Search code examples
rpackagecluster-computinglinear-regressionrobust

Is R Sandwich package not generating the expected clustered robust standard errors?


Load data

utils::data("InstInnovation", package = "sandwich")

df <- InstInnovation

Create group variable combining 'company' and 'year'

df[['cluster_var']] <- factor(paste0(df$company,"-",df$year))

Linear regression model

model <- lm(sales ~ competition + log(capital/employment) + year, data = df)

Why this:

lmtest::coeftest(model, vcov = vcovCL(model, type="HC3", cluster=~company+year))

Produces Standard Errors DIFFERENT than this?

lmtest::coeftest(model, vcov = vcovCL(model, type="HC3", cluster=~cluster_var))

Shouldn't cluster=~company+year and cluster=~cluster_var be equivalent?

In addition, I cannot find a place (e.g. Github) to report issues on R sandwich package, I found this but is just a read-only mirror: https://github.com/cran/sandwich

Thank you very much in advance.


Solution

  • cluster=~company+year is indeed something different: 'multiway clustering'. I found the explanation here:

    http://fmwww.bc.edu/repec/bost10/BOS10.baum.pdf

    https://francish.netlify.app/post/note-on-robust-standard-errors/