Interactive Fixed Effect Models — Bai (2009)
Clone or download
Latest commit 73740ce Dec 18, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
benchmark Switch to rss Aug 28, 2018
dataset first update Feb 1, 2018
img better model Jul 1, 2016
src require Dec 18, 2018
test Remove IterTools Jul 8, 2018
.gitignore add gitignoe Aug 23, 2018
.travis.yml only test on 1.0 Aug 19, 2018 last name change Aug 31, 2016 readme Nov 8, 2018
REQUIRE require Dec 18, 2018
paper.bib add info Apr 24, 2017 add info Apr 24, 2017

Build Status Coverage Status


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 T(i) and 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 weights.

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 0, fit fits a factor model

     Sales ~ 0

    Otherwise, fit fits 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 r equal 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

     vcov = robust()
     vcov = cluster(StatePooled)
     vcov = cluster(StatePooled, YearPooled)
  • weights are indicated with the keyword argument weights

     weights = Pop
  • method allows to choose between two algorithms:

    • levenberg_marquardt
    • dogleg
  • The option save = true saves 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 and 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.

Related Packages


using Pkg