Skip to content

Instantly share code, notes, and snippets.

@Nosferican
Created December 3, 2017 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nosferican/e183f0d270fce9ee7f34a12670a8d89d to your computer and use it in GitHub Desktop.
Save Nosferican/e183f0d270fce9ee7f34a12670a8d89d to your computer and use it in GitHub Desktop.
Multiway clustering in R
if (!any(grepl(pattern = 'pacman', x = installed.packages()[,1]))) {
install.packages('pacman')
}
pacman::p_load(dplyr, plm, multiwayvcov)
df = data(Grunfeld, package = 'plm')
model = lm(formula = value ~ inv + capital,
data = Grunfeld)
vcov_both = multiwayvcov::cluster.vcov(model, select(Grunfeld, firm, year))
diag(vcov_both)[2:3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment