1、egen id=group(stkcd) /对字符型的变量数字化
xtset id year /定义面板
tssmooth ma s=roa,w(4 1)
tssmooth ma s2=roa^2,w(4 1)
by id (year): g var=(s2-s^2)*5/4 if _n>42、tssmooth ma
t=e,w(4 1)
tssmooth ma t1=e^2,w(4
1)
bys
loc2(year):g s=sqrt((t2-t^2)5/4) if _n>4
3、cap drop
eq*
egen
eq=sd(e) if year<2004,by(loc2)
replace
eq=0 if year!=2003
replace
eq=0 if year!=2003
egen
eq1=sd(e) if year>2001 &year<2005,by(loc2)
replace
eq1=0 if year!=2004
egen
eq2=sd(e) if year>2002 &year<2006,by(loc2)
replace
eq2=0 if year!=2005
egen
eq3=sd(e) if year>2003 &year<2007,by(loc2)
replace
eq3=0 if year!=2006