Skip to main content

Python implementation of the Interactive Fixed Effects estimator presented in Bai (2009).

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyInteractiveFixedEffects-0.0.2.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyInteractiveFixedEffects-0.0.2-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file pyInteractiveFixedEffects-0.0.2.tar.gz.

File metadata

File hashes

Hashes for pyInteractiveFixedEffects-0.0.2.tar.gz
Algorithm Hash digest
SHA256 e8e52c225cfe659ab1dff1e5dc117724515e33a907e6cd51752b55cbef2a247c
MD5 013522eb4075c7c44bd156a999603627
BLAKE2b-256 e3ee50215f0eea0f3fac19b75a2b136c1f70959917a16398fc4008d16612d034

See more details on using hashes here.

File details

Details for the file pyInteractiveFixedEffects-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pyInteractiveFixedEffects-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 38abf2926fd5b9cc332ed35ff11ad571ca607abe7c250ad493579ea5f0df621f
MD5 27402e3ba54bce8877b3683793d6edf4
BLAKE2b-256 1969083231c68883dea49a53463642c3503170e7aaf2a2bdff5850d71713c4fe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page