MyNixOS website logo
Description

Linear Group Fixed Effects.

Transforms away factors with many levels prior to doing an OLS. Useful for estimating linear models with multiple group fixed effects, and for estimating linear models which uses factors with many levels as pure control variables. See Gaure (2013) <doi:10.1016/j.csda.2013.03.024> Includes support for instrumental variables, conditional F statistics for weak instruments, robust and multi-way clustered standard errors, as well as limited mobility bias correction (Gaure 2014 <doi:10.1002/sta4.68>). Since version 3.0, it provides dedicated functions to estimate Poisson models.

lfe

R-CMD-check

The goal of lfe is to speed up the estimation of linear models with large fixed effects. It includes support for instrumental variables, conditional F statistics for weak instruments, robust and multi-way clustered standard errors, as well as limited mobility bias correction. See Gaure (2013) doi:10.1016/j.csda.2013.03.024 and Gaure 2014 doi:10.1002/sta4.68.

Installation

You can install the released version of lfe from CRAN with:

install.packages("lfe")

You can install the development version of lfe like so:

remotes::install_github("MatthieuStigler/lfe")

Example

This is a basic example which shows you the speed improvement over base R for fixed effects estimation.

library(lfe) # fixed effects estimation
library(tradepolicy) # intl trade data
library(dplyr) # data cleaning/transforming

training_data <- agtpa_applications %>%
  mutate(
    log_trade = log(trade),
    log_dist = log(dist),
    exp_year = paste(exporter, year, sep = "_"),
    imp_year = paste(importer, year, sep = "_")
  ) %>%
  filter(trade > 0, exporter != importer, year %in% seq(1986, 2006, 4)) %>%
  select(year, log_trade, log_dist, cntg, lang, clny, rta, exp_year, imp_year)

# note the difference with the | operator to indicate the FEs
# this is just an example, here I am not estimating a PPML model or anything
# in the state of the art
fml1 <- 0 + log_trade ~
  log_dist + cntg + lang + clny + rta + exp_year + imp_year # base

fml2 <- log_trade ~
  log_dist + cntg + lang + clny + rta | exp_year + imp_year # lfe

lm(fml1, data = training_data)

felm(fml2, data = training_data)

Testing

For a complete test with devtools::check(), you need to run sudo apt-get install devtools or similar before. The package is written in C, in the future I shall try to rewrite it in C++ to ease long term maintenance.

The package also needs additional testing. At the present time,the tests it cover around 30% of the written lines.

Metadata

Version

3.0-0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows