1
我正在尝试计算非缺失值,并受易变的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
d。所以循环不起作用。我想知道是否有办法做到这一点,而不创建更多的变量。