分组数据方差公式_[转载]用STATA计算面板分组的4年之间的标准差、方差

这篇博客介绍了如何在STATA中计算面板数据分组的方差。首先通过`egen id=group(stkcd)`将字符型变量数字化,然后使用`xtset id year`定义面板数据。接着,利用`tssmooth`命令计算4年滑动窗口内的标准差和方差,并通过`by id (year): g var=(s2-s^2)*5/4 if _n>4`计算方差。最后,利用`egen`命令按年份分组计算标准差,并进行汇总,得到不同年份的方差结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值