Skip to content

Latest commit

 

History

History
44 lines (37 loc) · 1.9 KB

README.md

File metadata and controls

44 lines (37 loc) · 1.9 KB

Panel Data Models with Interactive Fixed Effects

Python implementation of the Interactive Fixed Effects Estimator for panel data presented in Bai (2009).

Installation

pip install pyInteractiveFixedEffects

Usage

First, we need to import the module into our script.

import bai2009

Then we need the initiate the estimator by specifying the number of factors in the model.

# Load the  Interactive Fixed Effects estimator with r=3 factors
ife = bai2009.InteractiveFixedEffects(3)

Finally, there are two ways to estimate a model.

Estimation from a Patsy formula

The easiest way to get an estimate is using a Patsy formula to specify the model. The regression is specified as normal and we add an additional term ~ife(I,T)at the end to specify the columns of the data with the $N$ and $T$ index of each observation.

# Estimate the model using a Patsy formula
betas, F, Lambda = ife.fit_from_formula('Y~0+X1+X2~ife(I,T)', df)

Estimation from explicit definition of terms

If you prefer to specify each term explicitly in your code, you can use the code below.

# Alternatively, estimate the model specifying every term explicitly
betas, F, Lambda = ife.fit(
                        df['Y'].values[:,np.newaxis], # Outcome
                        df[['X1', 'X2']].values, # Observable regressors
                        df['I'].values[:,np.newaxis], # First level of the factor model (I)
                        df['T'].values[:,np.newaxis] # Second level of the factor model (T)
                    )

Estimation results

The estimator returns:

  • $\beta$ a $p\times 1$ vector of coefficients associated with the observables.
  • $F$ a $T\times r$ matrix of the factors on the $T$ dimension.
  • $\Lambda$ a $N\times r$ matrix of the loadings on the $N$ dimension.