使用stargazer()表示多个模型的lm()中的稳健标准误差

beq87vna  于 2023-10-13  发布在  其他
关注(0)|答案(1)|浏览(118)

我使用stargazer()显示OLS的结果,包括两个模型m3adjm4adj的稳健标准误差。这是我的代码:

model.lst <- list(m3adj, m4adj)

stargazer(model.lst,
          title = "Initial Results",
          type = "html",
          align = TRUE,
          no.space=TRUE,
          column.labels = c("Model 1 (Main effect)", "Model 2 (Main effect of sub dimensions)"), 
          omit.stat=c("LL","ser", "f"), 
          ord.intercepts = TRUE,
          notes.append=TRUE,
          se = c(list(NULL,robust_se3, NULL, robust_se4)), #include robust standard errors
          single.row = TRUE, 
          report = "vcs*", 
          notes="Heteroscedasticity-robust standard errors in parantheses.",
          add.lines=list(c('Year-quarter fixed effects', 'Yes','Yes')),
          star.cutoffs = c(0.05, 0.01, 0.001)
)

然而,我在robust_se3robust_se4中计算的稳健标准误差只显示了部分。对于模型1,我只得到了参数集中的SE,但是对于模型2,我得到了参数集中的随机数,并且只针对我的几个变量。有什么想法可以修改我的代码,这样我就可以为两个模型都包含健壮的SE了吗?

92vpleto

92vpleto1#

我自己找到了答案:首先使用代码计算每个模型m3m4的稳健标准误
robust_se2 <- sqrt(diag(vcovHC(m2, type = "HC0")))
然后调整stargazer如下:

model.lst <- list(m3, m4)

stargazer(model.lst,
          title = "Initial Results",
          type = "html",
          align = TRUE,
          no.space=TRUE,
          column.labels = c("Model 1 (Main effect)", "Model 2 (Main effect of sub dimensions)"), 
          omit.stat=c("LL","ser", "f"), 
          ord.intercepts = TRUE,
          notes.append=TRUE,
          se = list(robust_se3, NULL, robust_se4), #include robust standard errors
          single.row = TRUE, 
          report = "vcs*", 
          notes="Heteroscedasticity-robust standard errors in parantheses.",
          add.lines=list(c('Year-quarter fixed effects', 'Yes','Yes')),
          star.cutoffs = c(0.05, 0.01, 0.001)
)

相关问题