这是我之前写的一段命令,还有些小问题,供参考:
*== 生成退出公司虚拟变量 exit /*该变量还存在一些问题*/
sort code year
by code: gen count=_N
gen survivor = count==8 /*2000-2007,最长8年资料*/
gen has99 = 1 if year==2007 /*2007年还活着的公司*/
sort code has99
by code: replace has99=1 if has99[_n-1]==1 /*标示整个公司*/
replace has99=0 if has99==.
sort code year
* 标示年度不连续的样本
by code: gen has_gaps=1 if year[_n-1]!=year-1&_n!=1
sort code has_gaps
by code: replace has_gaps=1 if has_gaps[_n-1]==1
replace has_gaps=0 if has_gaps==.
sort code year
cap drop exit
by code: gen exit=(survivor==0 & has99==0 & has_gaps!=1 & _n==_N)
replace exit=0 if exit==1&year==2007
drop count survivor has99
|