Home

Awesome

R interface for Fixed Effect Models

Build Status codecov

This package uses the FixedEffectModels.jl julia package and the JuliaCall R library to estimate large fixed effects models in R.

It is a substitute to the felm R package. It is usually faster (see benchmarks. I find it also to be more robust to actually converge. I use the JuliaCall library to pass datasets into julia and process them using the FixedEffectModels.jl and InteractiveFixedEffectModels.jl libraries. The package is very preliminary, so please use it and let me know if you run into issues!

Thanks to Matthieu and Changcheng.

Usage

Install the package directly from github

devtools::install_github("eloualiche/FixedEffectjlr")

To actually use the package in R, first setup julia to work within R with JuliaCall (see more details about setting up on the package webpage)

library(FixedEffectjlr)
JULIA_HOME <- "/Applications/Julia-1.1.app/Contents/Resources/julia/bin/"
FixedEffect_setup(JULIA_HOME)

To run a regression with fixed effects

df <- Ecdat::Cigar
reg_res <- FixedEffect(df,
  lhs = "sales", rhs = "ndi",
  fe      = c("state", "year"),
  weights = "pop",
  vcov    = c("state"))
  
#                          Fixed Effect Model
# =====================================================================
# Number of obs:               1380   Degrees of freedom:            31
# R2:                         0.804   R2 within:                  0.139
# F-Statistic:              13.3481   p-value:                    0.000
# Iterations:                     6   Converged:                   true
# =====================================================================
#         Estimate  Std.Error  t value Pr(>|t|)   Lower 95%   Upper 95%
# ---------------------------------------------------------------------
# ndi  -0.00526264 0.00144043 -3.65351    0.000 -0.00808837 -0.00243691
# =====================================================================  
fe = c("year", "firm")
fe = c("industry:year")  # interaction without levels
fe = c("industry*year")  # interaction with levels
fe = c("industry:^year") # treat second variable as continuous 
fe = c("industry*^year") # treat second variable as continuous with first level
vcov = "robust"
vcov = c("industry", "year")
weights = "pop"

Output

The functions prints out a table that is generated directly from julia. Moreover it collects information about the regressions and output two lists:

Vignettes

Prerequisite:

The package requires a working installation of julia (last tested with julia 1.0.3)

<a name = "thanks">Thanks</a>

Thanks to Changcheng for developing JuliaCall.

Thanks to Matthieu for all his packages!

See other packages built on JuliaCall: convexjlr and ipoptjlr.