[英]R plm vs. Stata reghdfe
当评估Stata中的面板数据模型(使用社区贡献的命令reghdfe
)与R时,我发现稍微不同的结果。
塔塔:
cls
webuse nlswork, clear
xtset idcode year
reghdfe ln_w grade age ttl_exp tenure not_smsa south, abs(year) cluster(idcode)
R:
## import data
library(foreign)
df = read_dta("http://www.stata-press.com/data/r14/nlswork.dta")
## estimate the model
model5 = plm( ln_wage ~ grade + age + ttl_exp + tenure+ not_smsa + south + as.factor(year), data=df, index=c('idcode', 'year'), model="random")
summary(model5)[1:7,1:4] # <- this gives unclustered errors
coeftest(model5, vcov=vcovHC(model5,type="HC0",cluster="group"))[1:7,1:4] # <- this gives clustered errors
我本来希望系数相同(我猜标准误差也仍然需要自由度校正)。 我想念什么?
稍作调整后,我发现R的plm
包可以使用多个固定效果(至少在两个索引级别上)
## estimate the model
model5 = plm( ln_wage ~ grade + age + ttl_exp + tenure+ not_smsa + south + as.factor(year), data=df, index=c('idcode', 'year'), model="with", effect="time")
summary(model5)[1:7,1:4] # <- this gives unclustered errors
coeftest(model5, vcov=vcovHC(model5,type="HC0",cluster="group")) [1:7,1:4] # <- this gives clustered errors
上面的内容等于时间固定效果,并且在数值上类似于Statas reghdfe
命令
reghdfe ln_w grade age ttl_exp tenure not_smsa south, abs(year) cluster(idcode)
同样,如果您想要两种固定效果,都可以在Stata中:
reghdfe ln_w grade age ttl_exp tenure not_smsa south, abs(idcode year) cluster(idcode)
在R中,您可以使用:
model5 = plm( ln_wage ~ grade + age + ttl_exp + tenure+ not_smsa + south + as.factor(year), data=df, index=c('idcode', 'year'), model="with", effect="twoways")
summary(model5) # <- this gives unclustered errors
coeftest(model5, vcov=vcovHC(model5,type="HC0",cluster="group")) # <- this gives clustered errors
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.