| btrap {lfe} | R Documentation |
Bootstrap standard errors for the group fixed effects
Description
Bootstrap standard errors for the group fixed effects which were swept out
during an estimation with felm().
Usage
btrap(
alpha,
obj,
N = 100,
ef = NULL,
eps = getOption("lfe.eps"),
threads = getOption("lfe.threads"),
robust = FALSE,
cluster = NULL,
lhs = NULL
)
Arguments
alpha |
data frame returned from |
obj |
object of class |
N |
integer. The number of bootstrap iterations |
ef |
function. An estimable function such as in |
eps |
double. Tolerance for centering, as in getfe |
threads |
integer. The number of threads to use |
robust |
logical. Should heteroskedastic standard errors be estimated? |
cluster |
logical or factor. Estimate clustered standard errors. |
lhs |
character vector. Specify which left hand side if |
Details
The bootstrapping is done in parallel if threads > 1.
btrap() is run automatically from getfe() if
se=TRUE is specified. To save some overhead, the individual
iterations are grouped together, the memory available for this grouping is
fetched with getOption('lfe.bootmem'), which is initialized upon
loading of lfe to options(lfe.bootmem=500) (MB).
If robust=TRUE, heteroskedastic robust standard errors are estimated.
If robust=FALSE and cluster=TRUE, clustered standard errors
with the cluster specified to felm() are estimated. If cluster
is a factor, it is used for the cluster definition. cluster may also
be a list of factors.
Value
A data-frame of the same size as alpha is returned, with standard errors filled in.
Examples
oldopts <- options("lfe.threads")
options(lfe.threads = 2)
## create covariates
x <- rnorm(3000)
x2 <- rnorm(length(x))
## create individual and firm
id <- factor(sample(700, length(x), replace = TRUE))
firm <- factor(sample(300, length(x), replace = TRUE))
## effects
id.eff <- rlnorm(nlevels(id))
firm.eff <- rexp(nlevels(firm))
## left hand side
y <- x + 0.25 * x2 + id.eff[id] + firm.eff[firm] + rnorm(length(x))
## estimate and print result
est <- felm(y ~ x + x2 | id + firm)
summary(est)
## extract the group effects
alpha <- getfe(est)
head(alpha)
## bootstrap standard errors
head(btrap(alpha, est))
## bootstrap some differences
ef <- function(v, addnames) {
w <- c(v[2] - v[1], v[3] - v[2], v[3] - v[1])
if (addnames) {
names(w) <- c("id2-id1", "id3-id2", "id3-id1")
attr(w, "extra") <- list(note = c("line1", "line2", "line3"))
}
w
}
# check that it's estimable
is.estimable(ef, est$fe)
head(btrap(alpha, est, ef = ef))
options(oldopts)