Skip to main content

Westerlund: Panel Cointegration Testing in Python

Westerlund is a Python package implementing a functional approximation of the four panel cointegration tests developed by Westerlund (2007). The Westerlund test evaluates the null hypothesis of no cointegration by testing whether the error-correction term in a conditional panel ECM is equal to zero. If the null is rejected, there is evidence of a long-run equilibrium relationship between the variables.

Key Features

The package replicates the logic of the Westerlund (2007) methodology, including:

  • Four Test Statistics: Computes $G_t$, $G_a$, $P_t$, and $P_a$.
  • Flexible Dynamics: Allows for unit-specific lag and lead lengths.
  • Automated Selection: Built-in AIC/BIC selection logic for optimal lag and lead lengths.
  • Bootstrap Procedure: Robust p-values to handle cross-sectional dependence.
  • Kernel Estimation: Bartlett kernel long-run variance estimation.
  • Gap Handling: Strict time-series continuity checks to ensure valid econometric results.

Usage Examples

import pandas as pd
from westerlund_test import WesterlundTest

# 1. Prepare your panel data (Long format)
# Required columns: ID, Time, Y, X1, X2...
df = pd.read_csv("your_data.csv")

# 2. Initialize the test
test = WesterlundTest(
    data=df, 
    y_var='log_gdp', 
    x_vars=['log_energy', 'log_capital'], 
    id_var='country_id', 
    time_var='year',
    lags=(0, 2),        # Auto-select lags between 0 and 2
    leads=(0, 1),       # Auto-select leads between 0 and 1
    constant=True,      # Include intercept
    trend=True,         # Include time trend
    bootstrap=100,      # Perform 100 bootstrap replications
    seed=42
)

# 3. Run the estimation
results = test.run()

# 4. Visualize the results
test.plot_bootstrap()

References

Westerlund, J. (2007). Testing for Error Correction in Panel Data. Oxford Bulletin of Economics and Statistics, 69(6), 709-748.

Persyn, D., & Westerlund, J. (2008). Error-Correction-Based Cointegration Tests for Panel Data. Stata Journal, 8(2), 232-241.

Release files for Westerlund 0.1.1

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

Source distribution (sdist)

Source distribution for Westerlund 0.1.1
File Size Uploaded
westerlund-0.1.1.tar.gz 27.5 kB Details

Built distribution (wheel)

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

Total release size: 54.2 kB

Release files / westerlund-0.1.1.tar.gz

Download URL westerlund-0.1.1.tar.gz
Size 27.5 kB
Tags Source
SHA-256 checksum
How to use checksums
9de7ec24b500e12a98a872ec6032fe36509ea347240758dfbd449abf0e4cb129
BLAKE2b-256 checksum
How to use checksums
743bb26813cee5822131cde783fde483ac105f122d6fa697c841f25905e31e1e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.20

Release files / westerlund-0.1.1-py3-none-any.whl

Download URL westerlund-0.1.1-py3-none-any.whl
Size 26.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a68e84832fb91de8f1f1e360e97ce0bd845d086585f6a01cbea8d2bc6bf202f3
BLAKE2b-256 checksum
How to use checksums
ac5940901fa4ca0345c6c69b605862c2e3483d13ff0c07df5eeefc19cc29cbbb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.20

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

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