다양한 if
조건에 맞춰 누락되지 않은 값을 계산하려고합니다. 매달 max
번을 타십시오.Stata : 루프에서 egen 교체
gen xx1=.
gen xx2=.
forvalues i = 1/12{
bys state year month: replace xx1= 1 if month==`i' & no_monthsreport>=`i'
bys state year month: replace xx2= sum(!missing(xx1))
bys state year month: egen tot_xx3 =max(xx2)
}
나는 egen
명령 replace
라하지 않을 수 있습니다 것으로 나타났습니다. 그래서 루프가 작동하지 않습니다. 더 많은 변수를 만들지 않고이 작업을 수행 할 수있는 방법이 있는지 궁금합니다.