Learn R Programming

lfe (version 1.4-708)

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,fl,data)

Arguments

Value

felm return an object of class "felm". The content of this is currently not documented, but the generic summary-method will yield a summary which may be print'ed.

See Also

getfe

Examples

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

## individual and firm
id <- factor(sample(10,length(x),replace=TRUE))
firm <- factor(sample(3,length(x),replace=TRUE,prob=c(2,1,1)))

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

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

## 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)

Run the code above in your browser using DataLab