Skip to main content

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 with interactive fixed effects (ife).

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.

Metadata

Release files for pyInteractiveFixedEffects 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyInteractiveFixedEffects 0.0.2
File Size Uploaded
pyInteractiveFixedEffects-0.0.2.tar.gz 4.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyInteractiveFixedEffects 0.0.2
File Interpreter ABI Platform
pyInteractiveFixedEffects-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 10.6 kB

Release files / pyInteractiveFixedEffects-0.0.2.tar.gz

Download URL pyInteractiveFixedEffects-0.0.2.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e8e52c225cfe659ab1dff1e5dc117724515e33a907e6cd51752b55cbef2a247c
BLAKE2b-256 checksum
How to use checksums
e3ee50215f0eea0f3fac19b75a2b136c1f70959917a16398fc4008d16612d034
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / pyInteractiveFixedEffects-0.0.2-py3-none-any.whl

Download URL pyInteractiveFixedEffects-0.0.2-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
38abf2926fd5b9cc332ed35ff11ad571ca607abe7c250ad493579ea5f0df621f
BLAKE2b-256 checksum
How to use checksums
1969083231c68883dea49a53463642c3503170e7aaf2a2bdff5850d71713c4fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page