Learn R Programming

Westerlund: Panel Cointegration Testing in R

Westerlund is an R 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 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.

Installation

You can install the development version of Westerlund from GitHub using the devtools package:

# Install devtools if you haven't already
# install.packages("devtools")

# Install Westerlund
devtools::install_github("bosco-hung/Westerlund/R", build_vignettes = TRUE)

## Qucik Start
```r
library(Westerlund)

# Ensure data is sorted by ID and Time
results <- westerlund_test(
  data = my_data,
  yvar = "ln_gdp",
  xvars = c("ln_energy", "ln_capital"),
  idvar = "country",
  timevar = "year",
  constant = TRUE,
  trend = FALSE,
  lags = c(1, 3),      # AIC search between 1 and 3 lags
  leads = c(0, 2),     # AIC search between 0 and 2 leads
  bootstrap = 100,     # Run 100 bootstrap replications
  lrwindow = 3         # Bartlett kernel window size
)

# View the results table
print(results)

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.

Copy Link

Version

Install

install.packages('Westerlund')

Version

0.1.1

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Bosco Hung

Last Published

January 17th, 2026

Functions in Westerlund (0.1.1)

westerlund_test_mg

Print Mean-Group ECM Output and Long-Run Relationship Tables
westerlund_test_reg

Formatted Coefficient Table for Westerlund Test Reporting
WesterlundPlain

Compute Raw Westerlund ECM Panel Cointegration Statistics (Plain Routine)
get_lag

Time-Indexed Lag Extraction with Explicit Gaps
shiftNA

NA-Padded Lag and Lead Operator
calc_lrvar_bartlett

Long-Run Variance Estimation with Bartlett Kernel
westerlund_test

Westerlund ECM-Based Panel Cointegration Test
get_ts_val

Strict Time-Series Mapping with Explicit Gaps
get_diff

First Difference with Strict Time Indexing
plot_westerlund_bootstrap

Plot Bootstrap Distributions for Westerlund ECM Panel Cointegration Tests
DisplayWesterlund

Standardize and Display Westerlund ECM Panel Cointegration Test Results
WesterlundBootstrap

Bootstrap Routine for Westerlund ECM Panel Cointegration Tests