首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >R plm诉Stata reghdfe

R plm诉Stata reghdfe
EN

Stack Overflow用户
提问于 2018-12-06 15:41:38
回答 1查看 1.6K关注 0票数 1

在Stata (使用社区贡献的命令reghdfe)和R中估计面板数据模型时,我发现结果略有不同。

斯塔塔:

代码语言:javascript
复制
cls
webuse nlswork, clear
xtset idcode year
reghdfe ln_w grade age ttl_exp tenure not_smsa south, abs(year)  cluster(idcode)

R:

代码语言:javascript
复制
## 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

我会期望相同的系数(标准误差仍然需要自由度修正,我猜)。我遗漏了什么?

EN

回答 1

Stack Overflow用户

发布于 2018-12-09 13:00:16

经过一些调整后,我发现R的plm包可以使用多个固定效果(至少在两个索引级别上都是如此)

代码语言:javascript
复制
## 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命令。

代码语言:javascript
复制
 reghdfe ln_w grade age ttl_exp tenure not_smsa south, abs(year)  cluster(idcode)

同样,如果您希望在Stata中使用两个固定效果,则需要:

代码语言:javascript
复制
 reghdfe ln_w grade age ttl_exp tenure not_smsa south, abs(idcode year)  cluster(idcode) 

在R中,您可以使用:

代码语言:javascript
复制
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
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53654881

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档