I'd like to create an LM with HC3 corrected standard errors and a fixest model with cluster robust standard errors in the same table.
see my MRE below:
df <- mtcars
models <- list()
models[[1]] <- lm(cyl~disp, data = df)
models[[2]] <- feols(cyl~disp|as.factor(gear), data = df)
library(modelsummary)
# this works
modelsummary::modelsummary(models)
# but these do not
modelsummary::modelsummary(models, vcov = c("HC3", "cluster"))
modelsummary::modelsummary(models, vcov = c(HC3, cluster))
modelsummary::modelsummary(models, vcov = list(HC3, cluster))
modelsummary::modelsummary(models, vcov = list(vcovHC, cluster))
modelsummary::modelsummary(models, vcov = list(vcovHC, vcovHC))
modelsummary::modelsummary(models, vcov = c(vcovHC, vcovHC))
Okay--I figured out a hack, but still leaving question open in case someone finds out a more slick solution.
df <- mtcars
models <- list()
fit <- lm(cyl~disp, data = df)
models[[1]] <- coeftest(fit, vcovHC(fit, type = "HC3"))
models[[2]] <- summary(feols(cyl~disp|as.factor(gear), data = df), "cluster")
library(modelsummary)
# this works
modelsummary::modelsummary(models)
By default
fixest
automatically computes cluster-robust standard errors when you include fixed effects. If you setvcov=NULL
,modelsummary
will return the default standard errors, which will then be cluster-robust.Alternatively, you can set
vcov=~gear
to compute the standard errors using thesandwich::vcovCL
function under the hood.Using version 0.10.0 of
modelsummary
and 0.10.4 offixest
, we can do:Notice that the results are the same in the 2nd and 3rd column, and also equal to the plain
fixest
summary:In some past versions of
modelsummary
there were issues with labelling of the standard errors at the bottom of the table. I will soon be working on a more robust system to make sure the label matches the standard errors. In most cases,modelsummary
calculates the robust standard errors itself, so it has full control over labelling and computation. Packages likefixest
andestimatr
make things a bit more tricky because they sometimes hold several SEs, and because the default is not always “classical”.