首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >FE回归中的Driscoll和Kraay标准误差:在R中再现Stata xtscc输出

FE回归中的Driscoll和Kraay标准误差:在R中再现Stata xtscc输出
EN

Stack Overflow用户
提问于 2020-12-09 19:52:25
回答 1查看 709关注 0票数 0

我正在尝试用包xtscc在R中复制Stata命令plm提供的结果,但是我遇到了一些问题,因为为了复制目的,我使用来自Stata包plm的数据集的标准错误。

代码语言:javascript
运行
复制
# code to obtain dataset
library(lmtest)
library(car)
library(tidyverse)
data("Produc", package="plm")
write.dta(Produc,"test.dta")

我的目标是运行一个带有Driscoll和Kraay标准误差的双向固定效应面板模型估计。Stata中的例程如下

代码语言:javascript
运行
复制
use "test.dta", clear \\ to import data
** i declare the panel 
xtset state year
* create the dummies for the time fixed effects
quietly tab year, gen(yeardum)
* run a two way fixed effect regression model with Driscoll and Kraay standard errors
xi: xtscc gsp pcap emp unemp yeardum*,fe 
* results are the following
                    Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        pcap |  -.1769881    .265713    -0.67   0.515    -.7402745    .3862983
         emp |   40.61522   2.238392    18.14   0.000     35.87004     45.3604
       unemp |   23.59849   85.10647     0.28   0.785    -156.8192    204.0161

在R中,我使用以下例程:

代码语言:javascript
运行
复制
# I declare the panel
Produc <- pdata.frame(Produc, index = c("state","year"), drop.index = FALSE)
# run a two way fixed effect model
femodel <- plm(gsp~pcap+emp+unemp, data=Produc,effect = "twoway", 
               index = c("iso3c","year"), model="within")
# compute Driscoll and Kraay standard errors using vcovSCC
coeftest(femodel, vcovSCC(femodel))

pcap  -0.17699    0.25476 -0.6947   0.4874    
emp   40.61522    2.14610 18.9252   <2e-16 ***
unemp 23.59849   81.59730  0.2892   0.7725    

虽然点估计与Stata相同,但标准误差是不同的。

为了检查我是否对标准错误使用了“错误”的小样本调整,我还尝试使用所有可用的调整运行coeftest,但是没有一个得到与xtscc相同的值。

代码语言:javascript
运行
复制
library(purrr)
results <- map(c("HC0", "sss", "HC1", "HC2", "HC3", "HC4"),~coeftest(femodel, vcovSCC(femodel,type = .x)))
walk(results,print)
# none of the estimated standard errors is the same as xtscc

有人知道我怎样才能在R中复制Stata的结果吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-12 21:54:32

由于plm版本2.4,它的函数within_intercept(., return.model = TRUE)可以返回内部模型的完整模型,截取就像Stata中那样。这样,就可以准确地复制Stata的用户贡献命令xtscc的结果。

xtscc的工作方式是将双维有限元模型估计为单向有限元模型+时间维虚拟模型。所以让我们用plm来复制这个

代码语言:javascript
运行
复制
data("Produc", package="plm")
Produc <- pdata.frame(Produc, index = c("state","year"), drop.index = FALSE)

femodel <- plm(gsp ~ pcap + emp + unemp + factor(year), data = Produc, model="within")
femodelint  <- within_intercept(femodel,  return.model = TRUE)

lmtest::coeftest(femodelint, vcov. = function(x) vcovSCC(x, type = "sss"))
#                     Estimate  Std. Error t value              Pr(>|t|)    
# (Intercept)      -6547.68816  3427.47163 -1.9104             0.0564466 .  
# pcap                -0.17699     0.26571 -0.6661             0.5055481    
# emp                 40.61522     2.23839 18.1448 < 0.00000000000000022 ***
# unemp               23.59849    85.10647  0.2773             0.7816356    
# [...] 
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65223905

复制
相关文章

相似问题

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