r - R plm 与 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)
回复:
## 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
以上等于时间固定效果,在数值上类似于 Statasreghdfe
命令
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
推荐阅读
- python-3.x - 使用 jinja2 生成配置文件
- java - 您已经加载了库 /tmp/... 这可能禁用了堆栈保护
- python-3.x - python3中的余弦相似度
- java - 单击主页按钮时,Android应用程序未按预期最小化
- modal-dialog - 在显示模式(基础)中显示具有多个标记的地图
- javascript - 当我点击动态按钮时的动态模式
- blockchain - 用户如何签署多重签名交易?
- java - Android MVP - 分享偏好
- django-rest-framework - Django REST 框架 FileField PUT 测试用例
- postgresql - 无法访问 postgres PSQL