jungsee 发表于 2014-4-2 11:29 
在前面proc.基础上,补充这个code,从而使连续重复后面的数据行(不重复行),z value变成和y value, 但是在前一步处理过的 y 值出现过重复的数据行 保持不变。如果,你有其他要求,只要做相应调整即可。hope it helps!!!
use final_yz.dta,clear
sort y 
gen lagz=z[ _n-1]
gen temp=-y
sort temp
gen leadz=z[ _n-1]
drop temp
sort y
gen if_1=0
gen if_2=0
gen if_total=0
replace if_1=1 if z==lagz
replace if_2=1 if z==leadz
replace if_total=1 if if_1==1  | if_2!=0
replace z=y if if_total==0 & dup_database==1
save final_yz02.dta,replace