Skip to content

Instantly share code, notes, and snippets.

@tappek
tappek / plm_bootstrap.R
Last active April 16, 2023 12:28
fwildclusterboot and sandwich::vcovBS
library("plm")
data("Grunfeld", package = "plm")
## set some observations of the dependent variable to missing
Grunfeld$inv[Grunfeld$year<=1936] <- NA
fe <- plm(inv ~ value + capital, data = Grunfeld, model = "within")
library(sandwich)
sandwich::vcovBS(fe, cluster=~firm, R = 999) # errors
# Error in vcovBS.default(fe, cluster = ~firm, R = 999) :
@tappek
tappek / matrix_subsetting.R
Last active May 22, 2022 19:29
matrix subsetting by individual index (for plm::pcce and plm::pmg)
# speed test matrix splitting by individual subsetting, esp. in
# plm::pcce and plm::pmg
library("plm")
data(Produc)
pProduc <- pdata.frame(Produc)
X <- as.matrix(pProduc[ , -c(1:3)])
ind <- index(pProduc)[[1L]]