All Projects → FixedEffects → Fixedeffectmodels.jl

FixedEffects / Fixedeffectmodels.jl

Licence: other
Fast Estimation of Linear Models with IV and High Dimensional Categorical Variables

Programming Languages

julia
2034 projects

Projects that are alternatives of or similar to Fixedeffectmodels.jl

R4Econ
R Code Examples Multi-dimensional/Panel Data
Stars: ✭ 16 (-87.88%)
Mutual labels:  regression, economics
Microeconometrics.jl
Microeconometric estimation in Julia
Stars: ✭ 30 (-77.27%)
Mutual labels:  regression, economics
Appelpy
Applied Econometrics Library for Python
Stars: ✭ 136 (+3.03%)
Mutual labels:  economics, regression
RegressionTables.jl
Journal-style regression tables
Stars: ✭ 82 (-37.88%)
Mutual labels:  regression, economics
Gpstuff
GPstuff - Gaussian process models for Bayesian analysis
Stars: ✭ 106 (-19.7%)
Mutual labels:  regression
Machine learning code
机器学习与深度学习算法示例
Stars: ✭ 88 (-33.33%)
Mutual labels:  regression
Guide2econra
Stars: ✭ 86 (-34.85%)
Mutual labels:  economics
Machinelearningalgorithm
一些常用的机器学习算法实现
Stars: ✭ 84 (-36.36%)
Mutual labels:  regression
Mozregression
Regression range finder for Mozilla nightly builds
Stars: ✭ 126 (-4.55%)
Mutual labels:  regression
Ycml
A Machine Learning and Optimization framework for Objective-C and Swift (MacOS and iOS)
Stars: ✭ 118 (-10.61%)
Mutual labels:  regression
Cgoes
Research by Carlos Góes
Stars: ✭ 105 (-20.45%)
Mutual labels:  economics
Olsrr
Tools for developing linear regression models
Stars: ✭ 88 (-33.33%)
Mutual labels:  regression
Rul Net
Deep learning approach for estimation of Remaining Useful Life (RUL) of an engine
Stars: ✭ 112 (-15.15%)
Mutual labels:  regression
Ml
A high-level machine learning and deep learning library for the PHP language.
Stars: ✭ 1,270 (+862.12%)
Mutual labels:  regression
Dharma
Diagnostics for HierArchical Regession Models
Stars: ✭ 124 (-6.06%)
Mutual labels:  regression
Texreg
Conversion of R Regression Output to LaTeX or HTML Tables
Stars: ✭ 85 (-35.61%)
Mutual labels:  regression
Gcam Core
GCAM -- The Global Change Analysis Model
Stars: ✭ 100 (-24.24%)
Mutual labels:  economics
Mlr
Machine Learning in R
Stars: ✭ 1,542 (+1068.18%)
Mutual labels:  regression
Machine Learning Algorithms
A curated list of almost all machine learning algorithms and deep learning algorithms grouped by category.
Stars: ✭ 92 (-30.3%)
Mutual labels:  regression
Lossfunctions.jl
Julia package of loss functions for machine learning.
Stars: ✭ 89 (-32.58%)
Mutual labels:  regression

Build Status

This package estimates linear models with high dimensional categorical variables and/or instrumental variables.

Its objective is similar to the Stata command reghdfe and the R function felm. The package tends to be much faster than these two options.

benchmark

Installation

The package is registered in the General registry and so can be installed at the REPL with ] add FixedEffectModels.

Syntax

using DataFrames, RDatasets, FixedEffectModels
df = dataset("plm", "Cigar")
reg(df, @formula(Sales ~ NDI + fe(State) + fe(Year)), Vcov.cluster(:State), weights = :Pop)
# =====================================================================
# Number of obs:               1380   Degrees of freedom:            32
# R2:                         0.803   R2 Adjusted:                0.798
# F Statistic:              13.3382   p-value:                    0.001
# R2 within:                  0.139   Iterations:                     6
# Converged:                   true
# =====================================================================
#         Estimate  Std.Error  t value Pr(>|t|)   Lower 95%   Upper 95%
# ---------------------------------------------------------------------
# NDI  -0.00526264 0.00144097 -3.65216    0.000 -0.00808942 -0.00243586
# =====================================================================
  • A typical formula is composed of one dependent variable, exogeneous variables, endogeneous variables, instrumental variables, and a set of high-dimensional fixed effects.

    dependent variable ~ exogenous variables + (endogenous variables ~ instrumental variables) + fe(fixedeffect variable)
    

    High-dimensional fixed effect variables are indicated with the function fe. You can add an arbitrary number of high dimensional fixed effects, separated with +. You can also interact fixed effects using & or *.

    For instance, to add state fixed effects use fe(State). To add both state and year fixed effects, use fe(State) + fe(Year). To add state-year fixed effects, use fe(State)&fe(Year). To add state specific slopes for year, use fe(State)&Year. To add both state fixed-effects and state specific slopes for year use fe(State)*Year.

    reg(df, @formula(Sales ~ Price + fe(State) + fe(Year)))
    reg(df, @formula(Sales ~ NDI + fe(State) + fe(State)&Year))
    reg(df, @formula(Sales ~ NDI + fe(State)&fe(Year)))              # for illustration only (this will not run here)
    reg(df, @formula(Sales ~ (Price ~ Pimin)))
    

    To construct formula programatically, use

    reg(df, term(:Sales) ~ term(:NDI) + fe(:State) + fe(:Year))
    
  • Standard errors are indicated with the prefix Vcov (with the package Vcov)

     Vcov.robust()
     Vcov.cluster(:State)
     Vcov.cluster(:State, :Year)
    
  • The option weights specifies a variable for weights

     weights = :Pop
    
  • The option save can be set to one of the following: none (default) to save nothing :residuals to save residuals, :fe to save fixed effects. You can access the result with residuals() and fe()

  • The option method can be set to one of the following: :cpu, :gpu (see Performances below).

  • The option contrasts specifies particular contrasts for categorical variables in the formula, e.g.

     df.YearC = categorical(df.Year)
     reg(df, @formula(Sales ~ YearC); contrasts = Dict(:YearC => DummyCoding(base = 80)))
    

Output

reg returns a light object. It is composed of

  • the vector of coefficients & the covariance matrix (use coef, coefnames, vcov on the output of reg)
  • a boolean vector reporting rows used in the estimation
  • a set of scalars (number of observations, the degree of freedoms, r2, etc)
  • with the option save = true, a dataframe aligned with the initial dataframe with residuals and, if the model contains high dimensional fixed effects, fixed effects estimates (use residuals or fe on the output of reg)

Methods such as predict, residuals are still defined but require to specify a dataframe as a second argument. The problematic size of lm and glm models in R or Julia is discussed here, here, here here (and for absurd consequences, here and there).

You may use RegressionTables.jl to get publication-quality regression tables.

GPU

The package has support for GPUs (Nvidia) (thanks to Paul Schrimpf). This can make the package an order of magnitude faster for complicated problems.

To use GPU, run using CUDA before using FixedEffectModels. Then, estimate a model with method = :gpu. For maximum speed, set the floating point precision to Float32 with double_precision = false.

using CUDA, FixedEffectModels
df = dataset("plm", "Cigar")
reg(df, @formula(Sales ~ NDI + fe(State) + fe(Year)), method = :gpu, double_precision = false)

Solution Method

Denote the model y = X β + D θ + e where X is a matrix with few columns and D is the design matrix from categorical variables. Estimates for β, along with their standard errors, are obtained in two steps:

  1. y, X are regressed on D using the package FixedEffects.jl
  2. Estimates for β, along with their standard errors, are obtained by regressing the projected y on the projected X (an application of the Frisch Waugh-Lovell Theorem)
  3. With the option save = true, estimates for the high dimensional fixed effects are obtained after regressing the residuals of the full model minus the residuals of the partialed out models on D using the package FixedEffects.jl

References

Baum, C. and Schaffer, M. (2013) AVAR: Stata module to perform asymptotic covariance estimation for iid and non-iid data robust to heteroskedasticity, autocorrelation, 1- and 2-way clustering, and common cross-panel autocorrelated disturbances. Statistical Software Components, Boston College Department of Economics.

Correia, S. (2014) REGHDFE: Stata module to perform linear or instrumental-variable regression absorbing any number of high-dimensional fixed effects. Statistical Software Components, Boston College Department of Economics.

Fong, DC. and Saunders, M. (2011) LSMR: An Iterative Algorithm for Sparse Least-Squares Problems. SIAM Journal on Scientific Computing

Gaure, S. (2013) OLS with Multiple High Dimensional Category Variables. Computational Statistics and Data Analysis

Kleibergen, F, and Paap, R. (2006) Generalized reduced rank tests using the singular value decomposition. Journal of econometrics

Kleibergen, F. and Schaffer, M. (2007) RANKTEST: Stata module to test the rank of a matrix using the Kleibergen-Paap rk statistic. Statistical Software Components, Boston College Department of Economics.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].