| WesterlundBootstrap | R Documentation |
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.
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
)
data |
A |
touse |
Logical vector of length |
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 |
leads |
Integer or length-2 integer vector, or |
westerlund |
Logical. If |
aic |
Logical. If |
bootstrap |
Integer. Number of bootstrap replications. |
indiv.ecm |
Logical. If |
lrwindow |
Integer. Bartlett kernel window (maximum lag) forwarded to |
verbose |
Logical. If |
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:
Filters the original data using touse and removes missing yvar/xvars.
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.
Stores the estimated coefficients for lagged \Delta y_t and leads/lags/current \Delta x_t, and constructs residuals e.
Demeans residuals e within each unit and constructs within-unit centered differenced regressors on the residual-support rows.
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.
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.
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).
This section describes how WesterlundBootstrap() constructs bootstrap
samples and how it is typically used in the overall testing workflow.
westerlund_test()?When the user-facing westerlund_test is called with bootstrap > 0, it typically:
obtains a bootstrap distribution via WesterlundBootstrap(),
computes the observed statistics via WesterlundPlain,
derives bootstrap p-values by comparing observed raw statistics to the bootstrap distribution.
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.
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.
## 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)
Westerlund, J. (2007). Testing for error correction in panel data. Oxford Bulletin of Economics and Statistics, 69(6), 709–748.
westerlund_test,
WesterlundPlain
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.