getfe | R Documentation |
Compute the group fixed effects, i.e. the dummy parameters, which were swept
out during an estimation with felm()
.
getfe(
obj,
references = NULL,
se = FALSE,
method = "kaczmarz",
ef = "ref",
bN = 100,
robust = FALSE,
cluster = obj[["clustervar"]],
lhs = NULL
)
obj |
object of class |
references |
a vector of strings. If there are more than two factors
and you have prior knowledge of what the reference levels should be like
|
se |
logical. Set to TRUE if standard errors for the group effects are wanted. This is very time-consuming for large problems, so leave it as FALSE unless absolutely needed. |
method |
character string. Either 'cholesky', 'cg', or the default
'kaczmarz'. The latter is often very fast and consumes little memory, it
requires an estimable function to be specified, see |
ef |
function. A function of two variables, a vector of group fixed
effects and a logical, i.e. If a string is specified, it is fed to the Can be set to It can also be set to |
bN |
integer. The number of bootstrap runs when standard errors are requested. |
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 |
For the case with two factors (the terms in the second part of the formula
supplied to felm()
), one reference in each connected component
is adequate when interpreting the results.
For three or more factors, no such easy method is known; for the
"cholesky"
method- reference levels are found by analyzing the
pivoted Cholesky-decomposition of a slightly perturbed system. The
"kaczmarz"
method provides no rank-deficiency analysis, it is assumed
that the factors beyond the two first contribute nothing to the
rank-deficiency, so one reference in each is used.
If there are more than two factors, only the first two will be used to report connected components. In this case, it is not known which graph theoretic concept may be used to analyze the rank-deficiency.
The standard errors returned by the Kaczmarz-method are bootstrapped,
keeping the other coefficients (from felm()
) constant, i.e. they
are from the variance when resampling the residuals. 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.
The function getfe
computes and returns a data frame
containing the group fixed effects. It has the columns
c('effect','se','obs','comp','fe','idx')
effect
is the estimated effect.
se
is
the standard error.
obs
is the number of observations of this
level.
comp
is the graph-theoretic component number, useful
for interpreting the effects.
fe
is the name of factor.
idx
is the level of the factor.
With the Kaczmarz-method it's possible to specify a different estimable function.
oldopts <- options("lfe.threads")
options(lfe.threads = 2)
## create covariates
x <- rnorm(4000)
x2 <- rnorm(length(x))
## create individual and firm
id <- factor(sample(500, 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, se = TRUE)
## find some estimable functions, with standard errors, we don't get
## names so we must precompute some numerical indices in ef
idx <- match(c("id.5", "id.6", "firm.11", "firm.12"), rownames(alpha))
alpha[idx, ]
ef <- function(v, addnames) {
w <- c(
v[idx[[2]]] - v[idx[[1]]], v[idx[[4]]] + v[idx[[1]]],
v[idx[[4]]] - v[idx[[3]]]
)
if (addnames) names(w) <- c("id6-id5", "f12+id5", "f12-f11")
w
}
getfe(est, ef = ef, se = TRUE)
options(oldopts)
## Not run:
summary(lm(y ~ x + x2 + id + firm - 1))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.