https://github.com/cran/sandwich
Tip revision: 39824702dada9466719a12af5cd16b6577b2482d authored by Achim Zeileis on 02 October 2020, 09:40:02 UTC
version 3.0-0
version 3.0-0
Tip revision: 3982470
vcovPL.Rout.save
R version 3.5.1 (2018-07-02) -- "Feather Spray"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
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
> pm <- plm::plm(y ~ x, data = PetersenCL, model = "pooling", indexes = 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
0.753 0.049 0.789