stata陈强:第十五章 短面板

高级计量经济学及stata应用 陈强

第十五章 短面板

15.13短面板的stata命令及实例

clear all
 
cd "F:\stata经济数据分析"
dir

use traffic.dta, clear

* 1 面板数据的设定
* xtset panelvar timevar
* encode country, gen(cntry) //假如panelvar是字符串,转换为数字型
xtset state year

* 显示数据结构
* xtdes // 显示面板数据的结构,是否为平衡面板
* xtsum // 显示组内、组间与整体的统计指标
* xttab varname // 显示组内、组间与整体的分布频率,tab是指tabulate
* xtline varname // 对每位个体分别显示该变量的时间序列图,如果希望将所有个体的时间序列图叠加在一起,可以加上选择项 overlay

xtdes
xtsum
xtsum fatal beertax spircons unrate perinck state year
xtline fatal
xtline fatal, overlay

* 2 混合回归
* reg y x1 x2 x3,vce(cluster id)

reg fatal beertax spircons unrate perinck, vce(cluster state)
estimates store OLS

reg fatal beertax spircons unrate perinck

* 3 固定效应
* FE格式:xtreg y x1 x2 x3,fe r
* LSDV法:reg y x1 x2 x3 i.id ,r
xtreg fatal beertax spircons unrate perinck,fe r
estimates store FE_robust

xtreg fatal beertax spircons unrate perinck,fe 
estimates store FE

reg fatal beertax spircons unrate perinck i.state,vce(cluster state)
estimates store LSDV

* 附带一阶差分结果
xtserial fatal beertax spircons unrate perinck, output
estimates store FD


* 双向固定效应
tab year, gen(year)
xtreg fatal beertax spircons unrate perinck year2-year7, fe r
estimates store FE_TW

test year2 year3 year3 year4 year5 year6 year7

xtreg fatal beertax spircons unrate perinck i.year , fe r

* 4 随机效应
* xtreg y x1 x2 x3, re r theta  // 随机效应FGLS
* xtreg y x1 x2 x3, mle  // 随机效应MLE

* 随机效应FGLS
xtreg fatal beertax spircons unrate perinck, re r theta
estimates store RE

xttest0

* 随机效应MLE
xtreg fatal beertax spircons unrate perinck, mle nolog
estimates store MLE

* 5 组间估计量
* 组间估计BE :xreg y x1 x2 x3, be
xtreg fatal beertax spircons unrate perinck, be
estimates store MLE

* 6 固定效应还是随机效应:豪斯曼检验
* stata code for  hausman
* xreg y x1 x2 x3, fe
* estimates store FE
* xreg y x1 x2 x3, re
* estimates store RE
* hausman FE RE, constant sigmamore

hausman FE RE, constant sigmamore  
* 注:vce(cluster id) 无法执行该命令



quietly xtreg fatal beertax spircons unrate perinck, re
scalar theta = e(theta)
global yandxforhausman fatal beertax spircons unrate perinck
sort state
foreach x of varlist $yandxforhausman{
by state : egen mean`x'=mean(`x')
gen md`x' = `x' - mean`x'
gen red`x'= `x' - theta*mean`x' 
}
quietly reg redfatal redbeertax redspircons redunrate redperinck mdbeertax mdspircons mdunrate mdperinck, vce(cluster state)
test mdbeertax mdspircons mdunrate mdperinck

quietly xtreg fatal beertax spircons unrate perinck, re r
xtoverid

estimates table OLS FE_robust FE_TW RE BE, b se


  • 6
    点赞
  • 74
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值