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
egen
eq4=sd(e) if year>2004 &year<2008,by(loc2)
replace
eq4=0 if year!=2007
egen
eq5=sd(e) if year>2005 &year<2009,by(loc2)
replace
eq5=0 if year!=2008
egen
eq6=sd(e) if year>2006 &year<2010,by(loc2)
replace
eq6=0 if year!=2009
egen
eq7=sd(e) if year>2007 &year<2011,by(loc2)
replace
eq7=0 if year!=2010
egen
eq8=sd(e) if year>2008 &year<2012,by(loc2)
replace
eq8=0 if year!=2011
egen
eq9=sd(e) if year>2009&year<2013,by(loc2)
replace
eq9=0 if year!=2012
egen
eq10=sd(e) if year>2010&year<2014,by(loc2)
replace
eq10=0 if year!=2013
egen
eq11=sd(e) if year>2011&year<2015,by(loc2)
replace
eq11=0 if year!=2014
replace
eq=eq+eq1+eq2+eq2+eq4+eq5+eq6+eq7+eq8+eq9+eq1-+eq11
replace
eq=eq+eq1+eq2+eq2+eq4+eq5+eq6+eq7+eq8+eq9+eq10+eq11
replace
eq=. if year<2003
sum
eq
drop eq1
eq2 eq3 eq4 eq5 eq6 eq7 eq8 eq9 eq10 eq11
对EQ分年作表:
tabstat
eq,by(year) s(n mean p10 p25 p50 p75 p90)