【发布时间】:2014-10-30 14:31:34
【问题描述】:
我正在尝试根据不同的if 条件计算非缺失值。然后每个月使用max。
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 命令不能是replaced。所以循环不起作用。我想知道是否有一种方法可以在不创建更多变量的情况下做到这一点。
【问题讨论】:
标签: stata