xtreg y x year2-year7,fe //估计双向固定效应模型
ssc install xtcsd //安装命令
xtcsd,pes //检验截面相关问题
xtcsd,fri //检验截面相关问题
xtcsd,fre //检验截面相关问题
存在截面相关问题时
ssc install xtscc //安装命令
xi:xtscc y x year2-year7 i.state //处理了误差项截面相关问题的LSDV估计
testparm _Istate*
不存在截面相关问题时
xi:reg y x year2-year7 i.state, cluster(state) //使用聚类到州获得的标准误处理自相关和异方差问题
testparm _Istate* //对州虚拟变量做F检验
1.2随机效应和混合效应的选择
xtreg y x year2-year7,re //估计随机效应模型
xttest0 //LM检验,检验个体效应
xttest1 //LM检验,检验个体效应
1.3 固定效应和随机效应的选组(三种情形下的Hausman检验)
1.3.1第一种Hausman检验
xtreg y x,fe
est store fe
xtreg y x,re
est store re
hausman fe re,sigmamore/sigmaless
1.3.2第二种Hausman检验(适用于异方差情形)
xtreg y x i.year,fe r
est store fe
xtrg y x i.year,re r
est store re
hausman fe re,sigmamore/sigmaless
***此种情形hausman检验不能运算,hausman检验无效
quietly xtreg y x i.year, re
scalar theta=e(theta)
global yandxforhausman y x year2 year3 year4 year5 year6 year7
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 redy redx redy redx redyear2 redyear3 redyear4 redyear5 redyear6 redyear7 mdy mdx mdyear2 mdyear3 mdyear4 mdyear5 mdyear6 mdyear7, vce(cluster state)
test mdy mdx mdyear2 mdyear3 mdyear4 mdyear5 mdyear6 mdyear7
1.3.3第三种Hausman检验(适用于异方差和截面相关的情形)
xtreg y x year2-year7, fe //估计随机效应模型
xtcsd,pes //检验截面相关问题
xtcsd,fri //检验截面相关问题
xtcsd,fre //检验截面相关问题
xtscc redy redx redyear2 redyear3 redyear4 redyear5 redyear6 redyear7 mdy mdx mdyear2 mdyear3 mdyear4 mdyear5 mdyear6 mdyear7
test mdy mdx mdyear2 mdyear3 mdyear4 mdyear5 mdyear6 mdyear7