๐ฆ 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
๐จ Visualization Gallery¶
๐ Coefficient Comparison โ All 5 estimators with 95% confidence intervals
๐ Estimated Common Factors โ Fฬโ time series with r = 1
๐ Factor Loadings โ Heterogeneous ฮปแตข across cross-sections
๐ CupFM Convergence โ ฮฒ estimates across iterations
๐ก๏ธ Long-Run Covariance ฮฉฬ โ Kernel-estimated covariance matrix
โญ Bai-Ng IC โ Automatic factor number selection (r* = optimal)
๐ 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.
| Estimator | Method | Iterates | Reference | Status |
|---|---|---|---|---|
| LSDV | Within / FE | โ | Biased baseline | โ ๏ธ Biased |
| Bai FM | FM correction (1-step) | โ | Bai & Kao (2005) | โ Consistent |
| CupFM โ | FM + continuous updating | โ | BKN (2009) Thm 3 | โญ Recommended |
| CupFM-bar | FM + Z-bar instrument | โ | BKN (2009) | โ Consistent |
| CupBC | BC + updating | โ | BKN (2009) Thm 2 | โ Consistent |