Stargazer中的群集强健标准错误 [英] Cluster-Robust Standard Errors in Stargazer

查看:121
本文介绍了Stargazer中的群集强健标准错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何获取stargazer来显示lm模型的集群SE吗? (还有相应的F检验?)如果可能的话,我想采用一种类似于使用sandwich计算异方差鲁棒SE并将其弹出到stargazer的方法,如

Does anyone know how to get stargazer to display clustered SEs for lm models? (And the corresponding F-test?) If possible, I'd like to follow an approach similar to computing heteroskedasticity-robust SEs with sandwich and popping them into stargazer as in http://jakeruss.com/cheatsheets/stargazer.html#robust-standard-errors-replicating-statas-robust-option.

我正在使用lm来获取我的回归模型,并且我正在按公司聚类(我未包括在回归模型中的因子变量).我也有很多NA值,这让我认为multiwayvcov将是最好的软件包(请在此处查看landroni的答案的底部- https://sites.google.com/site/npgraham1/research/code )?请注意,我不想使用plm.

I'm using lm to get my regression models, and I'm clustering by firm (a factor variable that I'm not including in the regression models). I also have a bunch of NA values, which makes me think multiwayvcov is going to be the best package (see the bottom of landroni's answer here - Double clustered standard errors for panel data - and also https://sites.google.com/site/npgraham1/research/code)? Note that I do not want to use plm.

我想我找到了使用multiwayvcov软件包的解决方案...

I think I found a solution using the multiwayvcov package...

library(lmtest) # load packages
library(multiwayvcov)

data(petersen) # load data
petersen$z <- petersen$y + 0.35  # create new variable

ols1 <- lm(y ~ x, data = petersen) # create models
ols2 <- lm(y ~ x + z, data = petersen)

cl.cov1 <- cluster.vcov(ols1, data$firmid) # cluster-robust SEs for ols1
cl.robust.se.1 <- sqrt(diag(cl.cov1))
cl.wald1 <- waldtest(ols1, vcov = cl.cov1)

cl.cov2 <- cluster.vcov(ols2, data$ticker) # cluster-robust SEs for ols2
cl.robust.se.2 <- sqrt(diag(cl.cov2))
cl.wald2 <- waldtest(ols2, vcov = cl.cov2)

stargazer(ols1, ols2, se=list(cl.robust.se.1, cl.robust.se.2), type = "text") # create table in stargazer

此方法的唯一缺点是,您必须从每个模型的waldtest()输出中手动重新输入F统计信息.

Only downside of this approach is you have to manually re-enter the F-stats from the waldtest() output for each model.

推荐答案

使用lmtest和multiwayvcov软件包会导致很多不必要的开销.在R中计算聚类标准误差的最简单方法是修改后的summary()函数.此函数使您可以向常规的summary()函数添加一个称为cluster的附加参数.以下文章介绍了如何使用此函数来计算R中的群集标准错误:

Using the packages lmtest and multiwayvcov causes a lot of unnecessary overhead. The easiest way to compute clustered standard errors in R is the modified summary() function. This function allows you to add an additional parameter, called cluster, to the conventional summary() function. The following post describes how to use this function to compute clustered standard errors in R:

https://economictheoryblog.com/2016/12 /13/clustered-standard-errors-in-r/

您可以轻松地使用摘要功能来获得聚类的标准误差,并将其添加到寻星器输出中.根据您的示例,您可以简单地使用以下代码:

You can easily the summary function to obtain clustered standard errors and add them to the stargazer output. Based on your example you could simply use the following code:

# estimate models
ols1 <- lm(y ~ x) 

# summary with cluster-robust SEs
summary(ols1, cluster="cluster_id") 

# create table in stargazer
stargazer(ols1, se=list(coef(summary(ols1,cluster = c("cluster_id")))[, 2]), type = "text") 

这篇关于Stargazer中的群集强健标准错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆