WesterlundBootstrap: Bootstrap Routine for Westerlund ECM Panel Cointegration...

View source: R/Westerlund.R

WesterlundBootstrapR Documentation

Bootstrap Routine for Westerlund ECM Panel Cointegration Tests

Description

Internal bootstrap routine for generating a bootstrap distribution of the Westerlund (2007) ECM-based panel cointegration statistics under the null hypothesis of no error correction. The routine estimates short-run dynamics for each unit, constructs residual-based bootstrap samples in a Stata-aligned manner, and re-computes G_t, G_a, P_t, and P_a by calling WesterlundPlain on each bootstrap sample.

Usage

WesterlundBootstrap(
  data,
  touse,
  idvar,
  timevar,
  yvar,
  xvars,
  constant = FALSE,
  trend = FALSE,
  lags,
  leads = NULL,
  westerlund = FALSE,
  aic = TRUE,
  bootstrap = 100,
  indiv.ecm = FALSE,
  lrwindow = 2,
  verbose = FALSE
)

Arguments

data

A data.frame containing the original panel data.

touse

Logical vector of length nrow(data) indicating rows eligible for estimation. The routine further removes rows with missing yvar or xvars.

idvar

String. Column identifying cross-sectional units.

timevar

String. Column identifying time. Within-unit time gaps are handled by Stata-style differencing in the bootstrap setup.

yvar

String. Name of the dependent variable (levels) in the original data.

xvars

Character vector. Names of regressors (levels) in the original data.

constant

Logical. Include a constant term in the short-run regression used to obtain bootstrap residuals and coefficients.

trend

Logical. Include a trend term in the short-run regression used to obtain bootstrap residuals and coefficients.

lags

Integer or length-2 integer vector. Fixed lag order or range c(min,max) used for selecting short-run dynamics in the bootstrap setup.

leads

Integer or length-2 integer vector, or NULL. Fixed lead order or range c(min,max) used for selecting short-run dynamics. If NULL, defaults to 0.

westerlund

Logical. If TRUE, uses a Westerlund-style information criterion and trimming logic in the bootstrap setup, matching the westerlund mode used elsewhere.

aic

Logical. If TRUE, uses AIC for lag/lead selection when ranges. If FALSE, uses BIC.

bootstrap

Integer. Number of bootstrap replications.

indiv.ecm

Logical. If TRUE, gets output of individual ECM regressions..

lrwindow

Integer. Bartlett kernel window (maximum lag) forwarded to WesterlundPlain during bootstrap re-estimation.

verbose

Logical. If TRUE, prints additional output.

Details

Purpose and status. WesterlundBootstrap() is an internal engine typically called by westerlund_test when bootstrap inference is requested. It returns a matrix of bootstrap test statistics that can be used to compute bootstrap p-values for the raw statistics.

High-level algorithm. For each bootstrap replication, the routine:

  1. Filters the original data using touse and removes missing yvar/xvars.

  2. For each unit, estimates a short-run model for \Delta y_t using Stata-style differencing that respects time gaps: if t is not consecutive, the corresponding difference is set to missing.

  3. Stores the estimated coefficients for lagged \Delta y_t and leads/lags/current \Delta x_t, and constructs residuals e.

  4. Demeans residuals e within each unit and constructs within-unit centered differenced regressors on the residual-support rows.

  5. Resamples residual-support clusters to form bootstrap innovations, recursively generates bootstrap \Delta y_t with an AR recursion implied by the estimated \Delta y coefficients, integrates to levels to obtain bootstrap booty and bootx series, and enforces Stata-style truncation rules.

  6. Calls WesterlundPlain on the constructed bootstrap panel to compute G_t, G_a, P_t, and P_a.

The resulting statistics are stored row-by-row in BOOTSTATS.

Time indexing in bootstrap setup. Unlike the main estimation routines (which use strict time-indexed helpers), this bootstrap routine uses a local differencing helper diff_ts() that mimics Stata's D. operator under gaps: differences are marked NA when diff(timevec) != 1.

Lag/lead selection in the bootstrap setup. If lags and/or leads are supplied as ranges, the routine performs an information-criterion search over candidate short-run specifications for each unit. In westerlund=TRUE mode, a Westerlund-style criterion is used; otherwise, a standard AIC-based criterion is applied.

Random number generation. The routine sets the RNG kind to Mersenne-Twister and uses a deterministic sequence given the current RNG state. Users should set set.seed() upstream if reproducibility is desired.

Value

A list containing:

  • BOOTSTATS: a numeric matrix with bootstrap rows and 4 columns, containing bootstrap replications of G_t, G_a, P_t, and P_a (in that order).

Vignette

This section describes how WesterlundBootstrap() constructs bootstrap samples and how it is typically used in the overall testing workflow.

How does this relate to westerlund_test()?

When the user-facing westerlund_test is called with bootstrap > 0, it typically:

  1. obtains a bootstrap distribution via WesterlundBootstrap(),

  2. computes the observed statistics via WesterlundPlain,

  3. derives bootstrap p-values by comparing observed raw statistics to the bootstrap distribution.

Residual-based bootstrap under the null

The routine first estimates a short-run model for \Delta y_t within each unit and extracts residuals. It then resamples these residuals (clustered on the residual-support rows) and uses the stored short-run coefficients to propagate bootstrap dynamics.

Handling time gaps

To mirror Stata semantics in differencing, the bootstrap setup uses a local difference rule: if two adjacent observations are not exactly one time unit apart, the difference is set to missing for that location.

Example

## Upstream: set a seed for reproducibility
set.seed(123)

boot_res <- WesterlundBootstrap(
  data       = df,
  touse      = touse,
  idvar      = "id",
  timevar    = "t",
  yvar       = "y",
  xvars      = c("x1","x2"),
  constant   = TRUE,
  trend      = FALSE,
  lags       = 1,
  leads      = 0,
  westerlund = FALSE,
  bootstrap  = 399,
  indiv.ecm  = TRUE,
  lrwindow   = 2,
  verbose    = FALSE
)

## Example left-tail p-value for Gt (assuming 'obs' exists)
# mean(boot_res$BOOTSTATS[,1] <= obs$Gt, na.rm = TRUE)

References

Westerlund, J. (2007). Testing for error correction in panel data. Oxford Bulletin of Economics and Statistics, 69(6), 709–748.

See Also

westerlund_test, WesterlundPlain


Westerlund documentation built on Feb. 7, 2026, 5:07 p.m.