Learn R Programming

lfe (version 1.5-1026)

felm: Fitting linear models with multiple group fixed effects

Description

'felm' is used to fit linear models with multiple group fixed effects, similarly to lm. It uses the Method of Alternating projections to sweep out multiple group effects from the normal equations before estimating the remaining coefficients with OLS.

This function is intended for use with large datasets with multiple group effects of large cardinality. If dummy-encoding the group effects results in a manageable number of coefficients, you are probably better off by using lm.

Usage

felm(formula, data, iv=NULL, clustervar=NULL, exactDOF=FALSE)

Arguments

formula
an object of class '"formula"' (or one that can be coerced to that class: a symbolic description of the model to be fitted. Similarly to 'lm'. Grouping factors are coded as G(f) (with a capital G).
data
a data frame containing the variables of the model
iv
a formula describing an instrumented variable. Estimated via two step OLS
clustervar
a string or factor. Either the name of a variable or a factor. Used for computing clustered standard errors.
exactDOF
logical. If more than two factors, the degrees of freedom used to scale the covariance matrix (and the standard errors) is normally estimated. Setting exactDOF=TRUE causes felm to compute it, but this may

Value

  • felm returns an object of class "felm". It is quite similar to en "lm" object, but not entirely compatible.

    The "felm" object is a list containing the following fields:

  • coefficientsa numerical vector. The estimated coefficients.
  • Nan integer. The number of observations
  • pan integer. The total number of coefficients, including those projected out.
  • responsea numerical vector. The response vector.
  • fitteda numerical vector. The fitted values.
  • residualsa numerical vector. The residuals of the full system, with dummies.
  • r.residualsa numerical vector. Reduced residuals, i.e. the residuals resulting from predicting without the dummies.
  • cfactorfactor of length N. The factor describing the connected components of the two first G() terms in the model.
  • vcva matrix. The variance-covariance matrix.
  • felist of factors. A list of the G() terms in the model.
  • The generic summary-method will yield a summary which may be print'ed. The object has some resemblance to the an lm object, and some postprocessing methods designed for lm may happen to work. It may however be necessary to coerce the object to succeed with this.

See Also

getfe

Examples

Run this code
## create covariates
x <- rnorm(1000)
x2 <- rnorm(length(x))

## individual and firm
id <- factor(sample(20,length(x),replace=TRUE))
firm <- factor(sample(13,length(x),replace=TRUE))

## effects for them
id.eff <- rnorm(nlevels(id))
firm.eff <- rnorm(nlevels(firm))

## left hand side
u <- rnorm(length(x))
y <- x + 0.5*x2 + id.eff[id] + firm.eff[firm] + u

## estimate and print result
est <- felm(y ~ x+x2+G(id)+G(firm))
summary(est)
## compare with lm
summary(lm(y ~ x + x2 + id + firm-1))
## alternatively
felm(y ~ x + x2,fl=list(id=id,firm=firm))
  getfe(est)

## make an iv-example, Q is instrumented by x3, report robust s.e.
x3 <- rnorm(length(x))
Q <- 0.3*x3 + x + 0.2*x2 + id.eff[id] + 0.7*u + rnorm(length(x),sd=0.3)
y <- y + Q
ivest <- felm(y ~ x + x2 + G(id)+G(firm) + Q, iv=Q ~ x3)
summary(ivest,robust=TRUE)

Run the code above in your browser using DataLab