| felm {capybara} | R Documentation |
LM fitting with high-dimensional k-way fixed effects
Description
feglm can be used to fit linear models with many high-dimensional fixed effects. The estimation
procedure is based on unconditional maximum likelihood and can be interpreted as a “weighted demeaning”
approach.
Usage
felm(formula = NULL, data = NULL, weights = NULL, vcov = NULL, control = NULL)
Arguments
formula |
an object of class "formula": a symbolic description of the model to be fitted. formula
must be of type response ~ slopes | fixed_effects | cluster.
|
data |
an object of class "data.frame" containing the variables in the model. The expected input is a
dataset with the variables specified in formula and a number of rows at least equal to the number of variables
in the model.
|
weights |
an optional string with the name of the prior weights variable in data.
|
vcov |
an optional character string specifying the type of variance-covariance estimator.
One of "iid" (default OLS, ignore cluster part of formula), "hetero" (heteroskedastic-robust
HC0, computed in C++ - no cluster variable needed), "cluster" (one-way sandwich using the cluster
variable in the formula), "m-estimator" (M-estimator one-way sandwich), or "dyadic"
(Cameron-Miller dyadic sandwich; requires two entity variables in the third part of the formula).
When NULL (default), the type is inferred from the formula: if a cluster variable is present the
standard sandwich is used, otherwise the inverse Hessian (IID) is returned.
|
control |
a named list of parameters for controlling the fitting process. See fit_control for details.
|
Value
A named list of class "felm". The list contains the following
eleven elements:
coefficients |
a named vector of the estimated coefficients
|
fitted_values |
a vector of the estimated dependent variable
|
weights |
a vector of the weights used in the estimation
|
hessian |
a matrix with the numerical second derivatives
|
null_deviance |
the null deviance of the model
|
nobs |
a named vector with the number of observations used in the estimation indicating the dropped and
perfectly predicted observations
|
fe_levels |
a named vector with the number of levels in each fixed effect
|
nms_fe |
a list with the names of the fixed effects variables
|
formula |
the formula used in the model
|
data |
the data used in the model after dropping non-contributing observations
|
control |
the control list used in the model
|
Examples
ross2004_subset <- ross2004[ross2004$year == 1999, ]
ross2004_subset <- ross2004_subset[ross2004_subset$ltrade >
quantile(ross2004_subset$ltrade, 0.75), ]
# Model with fixed effects
fit <- felm(ltrade ~ ldist | ctry1, ross2004_subset)
summary(fit)
ross2004_subset <- ross2004[ross2004$year %in% c(1994, 1999), ]
ross2004_subset <- ross2004_subset[ross2004_subset$ltrade >
quantile(ross2004_subset$ltrade, 0.75), ]
# Model without fixed effects but with clustered standard errors
# Note: Use 0 to indicate no fixed effects when specifying clusters
fit <- felm(ltrade ~ ldist | 0 | year, ross2004_subset)
summary(fit)