我正在将包'estimatr'的lm_robust用于包含HC3鲁棒标准误差的固定效应模型。我不得不从vcovHC()切换,因为我的数据样本太大了,无法处理。
使用以下行进行回归:
lm_robust(log(SPREAD) ~ PERIOD, data = dat, fixed_effects = ~ STOCKS + TIME, se_type = "HC3")
该代码运行良好,并且系数与使用程序包plm中的固定效果相同。由于由于数据样本太大,我无法使用coeftest来估计plm输出的HC3标准误差,因此我将lm_robust
的HC3估算器与coeftest(model, vcov= vcovHC(model, type = HC1))
的HC1进行了比较结果,lm_robust的HC3标准误差比coeftest中的HC1小得多。
有人解释,因为HC3比HC1更具限制性。我感谢任何建议和解决方案。
<< [EDIT用于coeftest的模型:
plm(log(SPREAD) ~ PERIOD, data = dat, index = c("STOCKS", "TIME"), effect = "twoway", method = "within")
vcovHC()
的plm
方法似乎自动估计了群集稳健的标准误差,而lm_robust()
则没有。因此,与HC1
的标准误差相比,plm
的标准误差的lm_robust
估计显得虚高。使用一些玩具数据:
lm
在两个软件包中似乎没有等效的群集鲁棒标准错误类型。但是,当在library(sandwich) library(tidyverse) library(plm) library(estimatr) library(lmtest) set.seed(1981) x <- sin(1:1000) y <- 1 + x + rnorm(1000) f <- as.character(sort(rep(sample(1:100), 10))) t <- as.character(rep(sort(sample(1:10)), 100)) dat <- tibble(y = y, x = x, f = f, t = t) lm_fit <- lm(y ~ x + f + t, data = dat) plm_fit <- plm(y ~ x, index = c("f", "t"), model = "within", effect = "twoways", data = dat) rb_fit <- lm_robust(y ~ x, fixed_effects = ~ f + t, data = dat, se_type = "HC1", return_vcov = TRUE) sqrt(vcovHC(lm_fit, type = "HC1")[2, 2]) #> [1] 0.04752337 sqrt(vcovHC(plm_fit, type = "HC1")) #> x #> x 0.05036414 #> attr(,"cluster") #> [1] "group" sqrt(rb_fit$vcov) #> x #> x 0.04752337 rb_fit <- lm_robust(y ~ x, fixed_effects = ~ f + t, data = dat, se_type = "HC3", return_vcov = TRUE) sqrt(vcovHC(lm_fit, type = "HC3")[2, 2]) #> [1] 0.05041177 sqrt(vcovHC(plm_fit, type = "HC3")) #> x #> x 0.05042142 #> attr(,"cluster") #> [1] "group" sqrt(rb_fit$vcov) #> x #> x 0.05041177
中指定集群健壮的SE时,SE会更接近:
lm_robust()
由
rb_fit <- lm_robust(y ~ x, fixed_effects = ~ f + t, clusters = f, data = dat, se_type = "CR0") summary(rb_fit) #> #> Call: #> lm_robust(formula = y ~ x, data = dat, clusters = f, fixed_effects = ~f + #> t, se_type = "CR0") #> #> Standard error type: CR0 #> #> Coefficients: #> Estimate Std. Error t value Pr(>|t|) CI Lower CI Upper DF #> x 0.925 0.05034 18.38 1.133e-33 0.8251 1.025 99 #> #> Multiple R-squared: 0.3664 , Adjusted R-squared: 0.2888 #> Multiple R-squared (proj. model): 0.3101 , Adjusted R-squared (proj. model): 0.2256 #> F-statistic (proj. model): 337.7 on 1 and 99 DF, p-value: < 2.2e-16 coeftest(plm_fit, vcov. = vcovHC(plm_fit, type = "HC1")) #> #> t test of coefficients: #> #> Estimate Std. Error t value Pr(>|t|) #> x 0.925009 0.050364 18.366 < 2.2e-16 *** #> --- #> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(v0.3.0)在2020-04-16创建