This package implements a novel, fast and robust algorithm to estimate interactive fixed effect models.
The definition of interactive fixed effects follows Bai (2009).Formally, denote
I(i)) the two categorical dimensions associated with observation
i (typically time and id). This package estimates the set of coefficients
β, of factors
(f1, .., fr) and of loadings
(λ1, ..., λr) in the model
To estimate an interactive fixed effect model, one needs to specify a formula, a factor model with
ife, and, optionally, a set of fixed effects with
fe, a way to compute standard errors with
vcov, and a weight variable with
using DataFrames, RDatasets, InteractiveFixedEffectModels df = dataset("plm", "Cigar") df[:pState] = categorical(df[:State]) df[:pYear] = categorical(df[:Year]) regife(df, @model(Sales ~ Price, ife = (pState + pYear, 2), fe = pState, save = true)) # Linear Factor Model #================================================================ #Number of obs: 1380 Degree of freedom: 199 #R2: 0.976 R2 within: 0.435 #Iterations: 436 Converged: true #================================================================ # Estimate Std.Error t value Pr(>|t|) Lower 95% Upper 95% #---------------------------------------------------------------- #Price -0.425372 0.0141163 -30.1334 0.000 -0.453068 -0.397677 #================================================================
A typical formula is composed of one dependent variable and a set of regressors
using RDatasets, DataFrames, InteractiveFixedEffectModels df = dataset("plm", "Cigar")
When the only regressor is
fitfits a factor model
Sales ~ 0
fitfits a linear model with interactive fixed effects (Bai (2009))
Sales ~ Price + Year
Interactive fixed effects are indicated with the keyword argument
ife. Variables must be of type
PooledDataVector. The rank is the number of components to use. facFor instance, for a factor model with id variable
State, time variable
Year, and rank
requal to 2:
df[:pState] = categorical(df[:State]) df[:pYear] = categorical(df[:Year]) ife = (pState + pYear, 2)
Fixed effects are indicated with the keyword argument
fe. Use only the variables specified in the factor model. See FixedEffectModels.jl for more information
fe = pState fe = pYear fe = pState + pYear
Standard errors are indicated with the keyword argument
vcov = robust() vcov = cluster(StatePooled) vcov = cluster(StatePooled, YearPooled)
weights are indicated with the keyword argument
weights = Pop
methodallows to choose between two algorithms:
save = truesaves a new dataframe storing residuals, factors, loadings and the eventual fixed effects. Importantly, the returned dataframe is aligned with the initial dataframe (rows not used in the estimation are simply filled with NA).
Local minimum vs global minimum
The algorithm can estimate models with missing observations per id x time, multiple observations per id x time, and weights.
However, in these cases, the optimization problem may have local minima. The algorithm tries to catch these cases, and, if need be, restart the optimization until the global minimum is reached. However I am not sure that all the cases are caught.
Does the package estimate PCA / factor models?
Yes. Factor models are a particular case of interactive fixed effect models. Simply specify
0 as the lhs of the formula.
using DataFrames, RDatasets, InteractiveFixedEffectModels df = dataset("plm", "Cigar") df[:pState] = categorical(df[:State]) df[:pYear] = categorical(df[:Year]) regife(df, @model(Sales ~ 0, ife = (pState + pYear, 2), fe = pState, save = true))
Compared to the usual SVD method, the package estimates models with multiple (or missing) observations per id x time.
When should one use interactive fixed effects models?
Some litterature using this estimation procedure::
- Eberhardt, Helmers, Strauss (2013) Do spillovers matter when estimating private returns to R&D?
- Hagedorn, Karahan, Movskii (2015) Unemployment Benefits and Unemployment in the Great Recession: The Role of Macro Effects
- Hagedorn, Karahan, Movskii (2015) The impact of unemployment benefit extensions on employment: the 2014 employment miracle?
- Totty (2015) The Effect of Minimum Wages on Employment: A Factor Model Approach
How are standard errors computed?
Errors are obtained by regressing y on x and covariates of the form
i.year#c.id. This way of computing standard errors is hinted in section 6 of of Bai (2009).
Does this command implement the bias correction term in Bai (2009)?
In presence of cross or time correlation beyond the factor structure, the estimate for beta is consistent but biased (see Theorem 3 in Bai 2009, which derives the correction term in special cases). However, this package does not implement any correction. You may want to check that your residuals are approximately i.i.d.
- https://github.com/joidegn/FactorModels.jl : fits and predict factor models on matrices
- https://github.com/madeleineudell/LowRankModels.jl : fits general low rank approximations on matrices
- https://github.com/aaw/IncrementalSVD.jl: implementation of the backpropagation algorithm
using Pkg Pkg.add("InteractiveFixedEffectModels")