Examples for 'sandwich::vcovPL'


Clustered Covariance Matrix Estimation for Panel Data

Aliases: vcovPL meatPL

Keywords: regression

### ** Examples

## Petersen's data
data("PetersenCL", package = "sandwich")
m <- lm(y ~ x, data = PetersenCL)

## Driscoll and Kraay standard errors
## lag length set to: T - 1 (maximum lag length)
## as proposed by Petersen (2009)
sqrt(diag(vcovPL(m, cluster = ~ firm + year, lag = "max", adjust = FALSE)))
(Intercept)           x 
 0.01618977  0.01426121 
## lag length set to: floor(4 * (T / 100)^(2/9))
## rule of thumb proposed by Hoechle (2007) based on Newey & West (1994)
sqrt(diag(vcovPL(m, cluster = ~ firm + year, lag = "NW1994")))
(Intercept)           x 
 0.02289115  0.02441980 
## lag length set to: floor(T^(1/4))
## rule of thumb based on Newey & West (1987)
sqrt(diag(vcovPL(m, cluster = ~ firm + year, lag = "NW1987")))
(Intercept)           x 
 0.02436219  0.02816896 
## the following specifications of cluster/order.by are equivalent
vcovPL(m, cluster = ~ firm + year)
             (Intercept)            x
(Intercept) 5.935164e-04 2.222292e-05
x           2.222292e-05 7.934905e-04
vcovPL(m, cluster = PetersenCL[, c("firm", "year")])
             (Intercept)            x
(Intercept) 5.935164e-04 2.222292e-05
x           2.222292e-05 7.934905e-04
vcovPL(m, cluster = ~ firm, order.by = ~ year)
             (Intercept)            x
(Intercept) 5.935164e-04 2.222292e-05
x           2.222292e-05 7.934905e-04
vcovPL(m, cluster = PetersenCL$firm, order.by = PetersenCL$year)
             (Intercept)            x
(Intercept) 5.935164e-04 2.222292e-05
x           2.222292e-05 7.934905e-04
## these are also the same when observations within each
## cluster are already ordered
vcovPL(m, cluster = ~ firm)
             (Intercept)            x
(Intercept) 5.935164e-04 2.222292e-05
x           2.222292e-05 7.934905e-04
vcovPL(m, cluster = PetersenCL$firm)
             (Intercept)            x
(Intercept) 5.935164e-04 2.222292e-05
x           2.222292e-05 7.934905e-04

[Package sandwich version 3.0-1 Index]