Skip to content

๐Ÿ”ฌ PyCupFM

Panel Cointegration with Common Factors
Python implementation of all 5 estimators from Bai, Kao & Ng (2009, Journal of Econometrics) and Bai & Kao (2005)

PyPI Python License Stata

๐Ÿ“ฆ Install in one line

pip install pycupfm


โœจ Features at a Glance

๐Ÿ“

5 Estimators

LSDV, Bai FM, CupFM โ˜…, CupFM-bar, CupBC โ€” faithfully translated from the original GAUSS source code

๐ŸŽจ

Beautiful Visualizations

9 publication-quality plot types with premium academic aesthetics using matplotlib

๐Ÿ”

Auto Factor Selection

Bai & Ng (2002) IC for automatic factor number selection + auto-bandwidth

๐Ÿ“ค

Export Everywhere

LaTeX, Excel, CSV, HTML tables โ€” ready for your next paper submission

๐Ÿงช

Monte Carlo Tools

Built-in DGP simulation replicating BKN (2009) Tables 1-4

๐Ÿผ

Pandas Native

DataFrame input/output with automatic variable name inference


๐Ÿš€ Quick Start โ€” 5 Lines of Code

from pycupfm import CupFM
from pycupfm.datasets import load_grunfeld

df = load_grunfeld()  # N=10 firms, T=20 years
model = CupFM(n_factors=1, bandwidth=3, max_iter=25)
results = model.fit(
    y=df['linvest'], X=df[['lmvalue', 'lkstock']],
    panel_id=df['firm'], time_id=df['year'],
    var_names=['lmvalue', 'lkstock'], dep_var='linvest'
)
results.summary()

๐Ÿ“Š Output โ€” Publication-Quality Summary Table

============================================================================== cupfm โ€” Panel Cointegration with Common Factors v1.0.0 Bai, Kao & Ng (2009, JoE 149:82-99) | Bai & Kao (2005, SSRN-1815227) ============================================================================== Panel Information -------------------------------------------------------------------------- Dependent variable : linvest Regressors : lmvalue, lkstock Cross-sections (N) : 10 Time periods (T) : 20 Observations (Nร—T) : 200 Panel type : Balanced Common factors (r) : 1 Bandwidth (M) : 3 (bartlett) Max iterations : 25 CupFM iterations : 25 -------------------------------------------------------------------------- Estimation Results -------------------------------------------------------------------------- Variable | LSDV Bai FM CupFM CupFM-bar CupBC --------------+---------------------------------------------------------- lmvalue | 0.5224*** 0.5840*** 0.7421*** 0.6952*** 0.5824*** | ( 6.81) ( 11.41) ( 10.43) ( 7.58) ( 11.38) --------------+---------------------------------------------------------- lkstock | 0.0827*** 0.0789*** 0.0664** 0.0716* 0.0791*** | ( 3.35) ( 2.92) ( 2.34) ( 1.87) ( 2.93) -------------------------------------------------------------------------- t-statistics in parentheses | *** p<0.01 ** p<0.05 * p<0.10 CupFM = recommended (BKN 2009, Theorem 3) | CupFM-bar = Z-bar variant


๐Ÿ“ The Model

Panel cointegrating regression with common factor structure:

\[y_{it} = \alpha_i + \beta' x_{it} + \lambda_i' F_t + u_{it}\]

where \(F_t\) are \(r\) common I(1) stochastic trends and \(\lambda_i\) are heterogeneous loadings.

EstimatorMethodIteratesReferenceStatus
LSDVWithin / FEโœ—Biased baselineโš ๏ธ Biased
Bai FMFM correction (1-step)โœ—Bai & Kao (2005)โœ… Consistent
CupFM โ˜…FM + continuous updatingโœ“BKN (2009) Thm 3โญ Recommended
CupFM-barFM + Z-bar instrumentโœ“BKN (2009)โœ… Consistent
CupBCBC + updatingโœ“BKN (2009) Thm 2โœ… Consistent

๐Ÿ”— Also Available for Stata

ssc install cupfm
cupfm y x1 x2, nfactors(2) bandwidth(5) plot

๐Ÿ‘ค Dr. Merwan Roudane

๐Ÿ“ง merwanroudane920@gmail.com

๐Ÿ”— GitHub ยท PyPI ยท Stata SSC