学习笔记FE&RE(其一)

> 天鹰(中南财大——博士研究生)

E-mail: yanbinglh@163.com

对于固定效应以及随机效应模型的选择一直是学习面板的难点,stata的操作是很简单的,但是对于理论模型的选择问题还是有必要弄清楚背后的理论基础的,这篇文章也仅仅是对于相应操作的一个简单总结,理论部分还是需要仔细阅读课本的。(数据来源:陈强高级计量经济学)


use traffic.dta,clear

xtset state year  ///设定个体变量和时间变量

panel variable:  state (strongly balanced)

time variable:  year, 1982 to 1988

delta:  1 unit

xtdes  ///显示数据集结构


xtsum   ///显示变量特征的命令

xtsum fatal beertax spircons unrate perinck state year///显示数据集的变量特征


xtline fatal  ///查看变量的时间趋势图


混合回归

reg y x1 x2 x3,vce(cluster id ) ///id用来确定每个个体的变量

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


estimates store OLS    ///回归结果的储存

reg fatal beertax spircons unrate perinck  ///这个回归结果是使用普通标准误


固定效应

xtreg fatal beertax spircons unrate perinck ,fe r  ///使用固定效应模型


estimates store FE_robust

xtreg fatal beertax spircons unrate perinck ,fe  ///不加r时输出的结果包含一个F检验


estimates store FE

进一步通过LSDV(最小二乘虚拟变量)来考察

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


estimates store FD

也可以在固定效应中考虑时间效应,即双向固定效用

tab year ,gen(year)  ///定义年度虚拟变量


xtreg fatal beertax spircons unrate perinck year2-year7,fe r

estimates store FE_TW


xtreg fatal beertax spircons unrate perinck i.year,fe r  ///这个命令可以直接估计双向固定效应


随机效应

xtreg y x1 x2 x3,re r theta ///随机效应FGLS

xtreg y x1 x2 x3,mle        ///随机效应MLE

xtreg fatal beertax spircons unrate perinck ,re r theta


estimates store RE

xttest0  ///LM检验的命令在执行完xtreg,re后才可以执行


xtreg fatal beertax spircons unrate perinck ,mle nolog  ///对随机效应模型进行MLE估计


estimates store MLE

组间估计量(BE)

xtreg fatal beertax spircons unrate perinck ,be  ///组间估计


estimates store BE

固定效应还是随机效应的判断:豪斯曼检验

hausman FE RE,constant sigmamore

hausman cannot be used with vce(robust), vce(cluster cvar), or p-weighted data

r(198);  ///豪斯曼检验时,如果使用聚类稳健标准误,命令无法执行

xtreg fatal beertax spircons unrate perinck ,fe

estimates store FE

xtreg fatal beertax spircons unrate perinck ,re

estimates store RE

hausman FE RE,constant sigmamore


检验结果显示强烈拒绝原假设H0:ui与xit,zi不相关,应该使用固定效应模型

如果聚类标准误与普通的标准误误差较大,那么传统的豪斯曼检验将不再适用

解决的办法是使用自助法或者进行辅助回归

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{

  2. by state:egen mean`x'=mean(`x')

  3. gen md`x'=`x'-mean`x'

  4. gen red`x'=`x'-theta*mean`x'

  5. }

quietly reg redfatal redbeertax redspircons redunrate redperinck mdbeertax mdspircons mdunrate mdperinck ,vce(cluster state)

test mdbeertax mdspircons mdunrate mdperinck


拒绝随机效应,选择固定效应

也可使用下列外部命令进行辅助回归

ssc install xtoverid

 quietly  xtreg fatal beertax spircons unrate perinck ,re  r

xtoverid


汇总以上各种方法的估计系数以及标准误列表

estimates table OLS FE_robust FE_TW RE BE ,b se  ///要学会这个命令


不同的系数估计方法估计系数差别较大

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 静态面板数据的主要问题 横截面异方差 序列自相关 横截面同期相关 基础工作 屡次失败的经验表明,洗数据和看数据是非...
    CHEN_DIANDIAN阅读 26,596评论 0 16
  • > 天鹰(中南财大——博士研究生) E-mail: yanbinglh@163.com 双重差分模型的平行趋势假定...
    天鹰_2019阅读 12,446评论 0 4
  • 夜莺2517阅读 127,781评论 1 9
  • 我是黑夜里大雨纷飞的人啊 1 “又到一年六月,有人笑有人哭,有人欢乐有人忧愁,有人惊喜有人失落,有的觉得收获满满有...
    陌忘宇阅读 12,717评论 28 53
  • 信任包括信任自己和信任他人 很多时候,很多事情,失败、遗憾、错过,源于不自信,不信任他人 觉得自己做不成,别人做不...
    吴氵晃阅读 11,339评论 4 8