R Under development (unstable) (2023-12-09 r85665 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library("sandwich") > data("PetersenCL", package = "sandwich") > m <- lm(y ~ x, data = PetersenCL) > > vcovPL(m, cluster = ~ firm + year, adjust = TRUE) (Intercept) x (Intercept) 5.935164e-04 2.222292e-05 x 2.222292e-05 7.934905e-04 > vcovPL(m, cluster = ~ firm + year, adjust = FALSE) (Intercept) x (Intercept) 5.932790e-04 2.221403e-05 x 2.221403e-05 7.931731e-04 > > > data("InstInnovation", package = "sandwich") > n <- glm(cites ~ institutions, family = poisson, data = InstInnovation) > > vcovPL(n, cluster = ~ industry, adjust = TRUE) (Intercept) institutions (Intercept) 0.095136753 -1.242281e-03 institutions -0.001242281 2.129094e-05 > vcovPL(n, cluster = ~ industry, adjust = FALSE) (Intercept) institutions (Intercept) 0.095106103 -1.241881e-03 institutions -0.001241881 2.128408e-05 > > > ## vcovPL covariance matrix compared with vcovSCC from plm package > if(!require("plm")) q() Loading required package: plm > pm <- plm::plm(y ~ x, data = PetersenCL, model = "pooling", index = c("firm", "year")) > > (pl1 <- vcovPL(m, cluster = ~ firm, adjust = FALSE)) (Intercept) x (Intercept) 5.932790e-04 2.221403e-05 x 2.221403e-05 7.931731e-04 > (pl2 <- plm::vcovSCC(pm)) (Intercept) x (Intercept) 5.932790e-04 2.221403e-05 x 2.221403e-05 7.931731e-04 attr(,"cluster") [1] "time" > attr(pl2, "cluster") <- NULL > > all.equal(pl1, pl2) [1] TRUE > > > ## vcovPL compared with Stata's xtscc (xtscc y x, lag(1) ase) standard errors > pl4 <- c(0.0243573, 0.0281633) > names(pl4) <- c("(Intercept)", "x") > pl4 (Intercept) x 0.0243573 0.0281633 > (pl3 <- sqrt(diag(pl1))) (Intercept) x 0.02435732 0.02816333 > > all.equal(pl3, pl4, tolerance = 1e-6) [1] TRUE > > proc.time() user system elapsed 1.21 0.17 1.37