Skip to content

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

License

Notifications You must be signed in to change notification settings

jiboncom/pyInteractiveFixedEffects

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages