[英]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.