Awesome
R interface for Fixed Effect Models
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
# =====================================================================
- For now the functions takes as inputs different strings for independent variable, regressors and fixed effects instead of a formula as in
felm
. FixedEffectModels.jl
accepts arbitrary number of fixed effects as well as interaction of categorical variables:
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
- Standard errors are either adjusted for heteroscedasticity,
robust
or clustered by categories:
vcov = "robust"
vcov = c("industry", "year")
- It is also possible to add weights:
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:
-
reg_res$results
should eventually become a regression class likelm
orfelm
and keeps in memory most of the julia output -
reg_res$summary
is most useful to create regression tables and keep regressors, standard errors, etc... -
reg_res$summary$coeftest
for a coeftest object, to be used directly in stargazer
Vignettes
- For standard estimation: FixedEffectModels.Rmd
- For IV and Interactive FE: OtherFEModels.Rmd
- A practical example of IFE: IFE_PCA_ex.md
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
.