| Title: | Dynamic Common Correlated Effects Estimation for Panel Data |
|---|---|
| Description: | Estimates heterogeneous coefficient models for large panels with cross-sectional dependence. Implements the Mean Group (MG) estimator of Pesaran and Smith (1995) <doi:10.1016/0304-4076(94)01644-F>, the Common Correlated Effects (CCE) and Dynamic CCE (DCCE) estimators of Pesaran (2006) <doi:10.1111/j.1468-0262.2006.00692.x> and Chudik and Pesaran (2015) <doi:10.1016/j.jeconom.2015.03.007>, the regularized CCE of Juodis (2022), the Augmented Mean Group (AMG) of Eberhardt and Teal (2010), the Interactive Fixed Effects (IFE) estimator of Bai (2009) <doi:10.3982/ECTA6135>, and long-run estimators including Cross-Sectionally augmented Distributed Lag (CS-DL), Cross-Sectionally augmented Autoregressive Distributed Lag (CS-ARDL), and Pooled Mean Group (PMG) (Chudik et al. 2016; Shin et al. 1999). Also provides rolling-window estimation, high-dimensional fixed effect absorption, spatial CCE via user-supplied weight matrices, and structural break tests (Chow and sup-Wald) following Andrews (1993), Bai and Perron (1998), and Ditzen, Karavias and Westerlund (2024). Supplies a comprehensive cross-sectional dependence (CD) test suite including the Pesaran (2015) CD test <doi:10.1080/07474938.2014.956623>, the Juodis and Reese (2022) randomized weighted CD (CDw) test, the Baltagi et al. (2012) bias-adjusted weighted CD (CDw+) test, the Fan et al. (2015) Power Enhancement Approach (PEA) test, and the Pesaran and Xie (2021) bias-corrected CD (CD*) test. Further diagnostics include the Pesaran (2007) Cross-sectionally Augmented IPS (CIPS) panel unit root test <doi:10.1002/jae.951>, the Westerlund (2007) panel cointegration tests, the Dumitrescu and Hurlin (2012) panel Granger causality test, the Im-Pesaran-Shin (IPS) and Levin-Lin-Chu (LLC) panel unit root tests, the Pedroni (2004) and Kao (1999) residual cointegration tests, the Swamy (1970) and Pesaran and Yamagata (2008) slope homogeneity tests, a Hausman-type test for MG versus pooled, the exponent of cross-sectional dependence from Bailey et al. (2016) <doi:10.1002/jae.2490>, information criteria for Cross-Sectional Average (CSA) selection, the rank condition classifier, impulse response functions, cross-section and wild bootstrap inference, and 'broom'-compatible methods. |
| Authors: | Mustapha Wasseja [aut, cre] |
| Maintainer: | Mustapha Wasseja <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.4.2 |
| Built: | 2026-06-05 06:21:49 UTC |
| Source: | https://github.com/cran/dcce |
Computes bootstrap standard errors and confidence intervals for
dcce_fit objects using either cross-section or wild bootstrap.
bootstrap( object, type = c("crosssection", "wild"), reps = 500L, percentile = TRUE, cfresiduals = FALSE, seed = NULL )bootstrap( object, type = c("crosssection", "wild"), reps = 500L, percentile = TRUE, cfresiduals = FALSE, seed = NULL )
object |
A |
type |
Character: |
reps |
Integer: number of bootstrap repetitions. Default 500. |
percentile |
Logical: compute percentile CIs? Default |
cfresiduals |
Logical: for wild bootstrap, use common-factor
residuals instead of defactored residuals? Default |
seed |
Integer: random seed for reproducibility. Default |
An object of class dcce_boot with elements:
Bootstrap standard errors.
Percentile CI lower bound (if percentile=TRUE).
Percentile CI upper bound.
B x K matrix of bootstrap coefficient draws.
Number of repetitions.
Bootstrap type.
Naming conflict with broom::bootstrap. The broom package
also exports a function called bootstrap() (for resampling data
frames), with a completely different signature. If you load
broom after dcce, broom::bootstrap will mask dcce::bootstrap
on the search path and calls to bootstrap(fit, type = ..., reps = ...)
will fail with an "unused arguments" error. To avoid the conflict
you can either (a) use the namespace prefix
dcce::bootstrap(fit, ...), (b) load broom before dcce so
dcce ends up higher in the search path, or (c) use the
conflict-free alias dcce_bootstrap(fit, ...) which is exported by
dcce and has the same semantics.
set.seed(42) df <- data.frame( id = rep(1:10, each = 30), t = rep(1:30, 10), y = rnorm(300), x = rnorm(300) ) fit <- dcce(df, "id", "t", y ~ x, model = "mg", cross_section_vars = NULL) boot_res <- bootstrap(fit, reps = 50) print(boot_res)set.seed(42) df <- data.frame( id = rep(1:10, each = 30), t = rep(1:30, 10), y = rnorm(300), x = rnorm(300) ) fit <- dcce(df, "id", "t", y ~ x, model = "mg", cross_section_vars = NULL) boot_res <- bootstrap(fit, reps = 50) print(boot_res)
Implements the cross-sectionally augmented IPS (CIPS) panel unit root test of Pesaran (2007), which allows for cross-sectional dependence through a single unobserved common factor. For each unit, a cross-sectionally augmented Dickey-Fuller (CADF) regression is run:
cips_test(x, ...) ## S3 method for class 'matrix' cips_test(x, ..., lags = 0L, trend = FALSE) ## S3 method for class 'dcce_fit' cips_test(x, ..., lags = 0L, trend = FALSE) ## Default S3 method: cips_test( x, ..., data = NULL, unit_index = NULL, time_index = NULL, lags = 0L, trend = FALSE )cips_test(x, ...) ## S3 method for class 'matrix' cips_test(x, ..., lags = 0L, trend = FALSE) ## S3 method for class 'dcce_fit' cips_test(x, ..., lags = 0L, trend = FALSE) ## Default S3 method: cips_test( x, ..., data = NULL, unit_index = NULL, time_index = NULL, lags = 0L, trend = FALSE )
x |
A numeric vector, numeric matrix (N x T), data.frame, or
|
... |
Additional arguments passed to methods. |
lags |
Integer: number of lags of |
trend |
Logical: include a linear time trend? Default |
data |
A data.frame containing the panel structure (when |
unit_index |
Character: name of the unit variable in |
time_index |
Character: name of the time variable in |
The CIPS statistic is the cross-sectional average of the unit-level
t-statistics for (the CADF statistic). Critical values
come from Pesaran (2007, Table II(b), constant case) and Pesaran
(2007, Table II(c), constant + trend case). The null hypothesis is
that all series contain a unit root.
An object of class dcce_cips with elements:
The CIPS statistic (truncated cross-sectional average).
Approximate p-value from Pesaran (2007) critical values.
Per-unit truncated CADF t-statistics.
Number of units.
Time dimension.
Number of augmentation lags.
Whether a trend was included.
Pesaran, M. H. (2007). A simple panel unit root test in the presence of cross-section dependence. Journal of Applied Econometrics, 22(2), 265-312.
set.seed(1) N <- 20; T <- 30 f <- cumsum(rnorm(T)) X <- matrix(NA, N, T) for (i in seq_len(N)) X[i, ] <- cumsum(rnorm(T)) + 0.5 * f cips_test(X)set.seed(1) N <- 20; T <- 30 f <- cumsum(rnorm(T)) X <- matrix(NA, N, T) for (i in seq_len(N)) X[i, ] <- cumsum(rnorm(T)) + 0.5 * f cips_test(X)
Extract coefficients from a dcce_fit object
## S3 method for class 'dcce_fit' coef(object, type = c("mg", "unit"), ...)## S3 method for class 'dcce_fit' coef(object, type = c("mg", "unit"), ...)
object |
A |
type |
Character: |
... |
Ignored. |
A named numeric vector (for "mg") or a tibble (for "unit").
Implements the four error-correction-based panel cointegration tests of Westerlund (2007): two group-mean statistics (Ga, Gt) and two panel statistics (Pa, Pt). The null hypothesis is no cointegration between the dependent variable and the regressors.
cointegration_test( data, unit_index, time_index, formula, lags = 1L, leads = 1L, test = c("ga", "gt", "pa", "pt"), n_bootstrap = 0L, seed = NULL, show_progress = FALSE )cointegration_test( data, unit_index, time_index, formula, lags = 1L, leads = 1L, test = c("ga", "gt", "pa", "pt"), n_bootstrap = 0L, seed = NULL, show_progress = FALSE )
data |
A panel data.frame. |
unit_index |
Character scalar: unit identifier column. |
time_index |
Character scalar: time identifier column. |
formula |
Two-sided formula of the form |
lags |
Integer scalar: ADF lag order for |
leads |
Integer scalar: number of leads of |
test |
Character vector: which statistics to compute. Subset of
|
n_bootstrap |
Integer: number of bootstrap replications for
p-values. Default |
seed |
Integer: random seed for the bootstrap. |
show_progress |
Logical: print progress? Default |
For each unit , an error-correction regression is fitted
and the t-statistic for is used to construct the
four test statistics:
Gt: group-mean of the .
Ga: group-mean of
(unnormalised form).
Pt: pooled t-statistic.
Pa: pooled alpha-statistic.
A negative, large-magnitude statistic rejects the null of no
cointegration. Asymptotic p-values are obtained by linear interpolation
on the critical values in Westerlund (2007, Table 3). A bootstrap path
(n_bootstrap > 0) is also provided, resampling cross-sectional
units with replacement to account for cross-sectional dependence.
An object of class dcce_cointegration with elements
statistics (a tibble with columns test, statistic,
p_value, method), lags, leads, N,
T_bar, and call.
Westerlund, J. (2007). Testing for Error Correction in Panel Data. Oxford Bulletin of Economics and Statistics, 69(6), 709-748.
data(pwt8) result <- cointegration_test( data = pwt8, unit_index = "country", time_index = "year", formula = log_rgdpo ~ log_hc + log_ck, test = c("ga", "gt"), lags = 1L ) print(result)data(pwt8) result <- cointegration_test( data = pwt8, unit_index = "country", time_index = "year", formula = log_rgdpo ~ log_hc + log_ck, test = c("ga", "gt"), lags = 1L ) print(result)
Confidence intervals for a dcce_fit object
## S3 method for class 'dcce_fit' confint( object, parm = NULL, level = 0.95, type = c("mg", "lr", "adjustment"), ... )## S3 method for class 'dcce_fit' confint( object, parm = NULL, level = 0.95, type = c("mg", "lr", "adjustment"), ... )
object |
A |
parm |
Character vector of parameter names (default: all). |
level |
Confidence level. Default |
type |
Character: |
... |
Ignored. |
A matrix of confidence intervals with rows corresponding to parameters.
Estimates the exponent of cross-sectional dependence (alpha) using the methods of Bailey, Kapetanios & Pesaran (2016, 2019).
csd_exp( x, data = NULL, unit_index = NULL, time_index = NULL, use_residuals = FALSE, n_pca = 1L, test_size = 0.1, tuning = 0.5, n_bootstrap = 200L )csd_exp( x, data = NULL, unit_index = NULL, time_index = NULL, use_residuals = FALSE, n_pca = 1L, test_size = 0.1, tuning = 0.5, n_bootstrap = 200L )
x |
Either a numeric vector (variable stacked by unit), a numeric
matrix (N x T), or a |
data |
A data.frame containing the panel structure. Required if
|
unit_index |
Character: name of the unit variable in |
time_index |
Character: name of the time variable in |
use_residuals |
Logical: if |
n_pca |
Integer: number of principal components. Default 1. |
test_size |
Numeric: significance level for thresholding. Default 0.1. |
tuning |
Numeric: tuning parameter for residual method threshold. Default 0.5. |
n_bootstrap |
Integer: bootstrap repetitions for SE (residual method only). Default 200. |
An object of class dcce_csd with elements alpha (estimated
exponent), se (standard error), ci (confidence interval), method,
N, and T_val.
set.seed(42) # Matrix of cross-sectionally dependent data N <- 20; T_val <- 50 f <- rnorm(T_val) x <- matrix(NA, N, T_val) for (i in 1:N) x[i,] <- rnorm(1) * f + rnorm(T_val, sd = 0.5) result <- csd_exp(x, use_residuals = FALSE) print(result)set.seed(42) # Matrix of cross-sectionally dependent data N <- 20; T_val <- 50 f <- rnorm(T_val) x <- matrix(NA, N, T_val) for (i in 1:N) x[i,] <- rnorm(1) * f + rnorm(T_val, sd = 0.5) result <- csd_exp(x, use_residuals = FALSE) print(result)
Creates a differenced version of a variable for use inside dcce() formulas.
D(x, k = 1L)D(x, k = 1L)
x |
A numeric vector. |
k |
Integer difference order. Default 1. |
A numeric vector of the same length as x with leading NAs.
x <- c(10, 20, 30, 40, 50) D(x, 1) # NA 10 10 10 10 D(x, 2) # NA NA 20 20 20x <- c(10, 20, 30, 40, 50) D(x, 1) # NA 10 10 10 10 D(x, 2) # NA NA 20 20 20
Estimates heterogeneous coefficient panel data models with cross-sectional dependence using Mean Group (MG), Common Correlated Effects (CCE), Dynamic CCE (DCCE), and related estimators.
dcce( data, unit_index, time_index, formula, model = c("dcce", "cce", "ccep", "mg", "amg", "rcce", "ife", "pmg", "csdl", "csardl"), cross_section_vars = ~., cross_section_lags = 0L, pooled_vars = NULL, include_constant = TRUE, unit_trend = FALSE, bias_correction = c("none", "jackknife", "recursive", "half_panel_jackknife"), long_run_vars = NULL, long_run_model = NULL, csdl_xlags = 3L, absorb = NULL, spatial_weights = NULL, fast = TRUE, n_cores = 1L, run_cd_test = FALSE, full_sample = FALSE, verbose = FALSE, ... )dcce( data, unit_index, time_index, formula, model = c("dcce", "cce", "ccep", "mg", "amg", "rcce", "ife", "pmg", "csdl", "csardl"), cross_section_vars = ~., cross_section_lags = 0L, pooled_vars = NULL, include_constant = TRUE, unit_trend = FALSE, bias_correction = c("none", "jackknife", "recursive", "half_panel_jackknife"), long_run_vars = NULL, long_run_model = NULL, csdl_xlags = 3L, absorb = NULL, spatial_weights = NULL, fast = TRUE, n_cores = 1L, run_cd_test = FALSE, full_sample = FALSE, verbose = FALSE, ... )
data |
A data.frame containing the panel data. |
unit_index |
Character: name of the unit (cross-section) variable. |
time_index |
Character: name of the time variable. |
formula |
A formula of the form |
model |
Character: estimator to use. One of |
cross_section_vars |
A one-sided formula specifying variables for
cross-sectional averages, e.g. |
cross_section_lags |
Integer or named integer vector: number of lags of CSAs. Default 0. A single integer applies to all CSA variables. |
pooled_vars |
A one-sided formula specifying which coefficients to
constrain equal across units (pooled estimation). Default |
include_constant |
Logical: include unit-specific intercepts? Default
|
unit_trend |
Logical: include unit-specific linear trends? Default
|
bias_correction |
Character: bias correction method. One of |
long_run_vars |
A one-sided formula specifying long-run variables
(reserved for CSDL/CSARDL models). Default |
long_run_model |
Character: long-run model specification (reserved).
Default |
csdl_xlags |
Integer: number of lags of |
absorb |
Either |
spatial_weights |
Optional |
fast |
Logical: use the compiled C++ (RcppArmadillo) unit-OLS fast
path? Default |
n_cores |
Integer: number of cores for parallel unit estimation.
Only effective on Unix/macOS via |
run_cd_test |
Logical: run the Pesaran CD test on residuals? Default
|
full_sample |
Logical: use the full (unbalanced) sample? Default
|
verbose |
Logical: print progress messages? Default |
... |
Additional arguments passed to model-specific estimators. |
An object of class dcce_fit (and a model-specific subclass).
# Simple Mean Group estimation df <- data.frame( id = rep(1:10, each = 20), t = rep(1:20, 10), y = rnorm(200), x = rnorm(200) ) fit <- dcce(df, unit_index = "id", time_index = "t", formula = y ~ x, model = "mg", cross_section_vars = NULL) coef(fit)# Simple Mean Group estimation df <- data.frame( id = rep(1:10, each = 20), t = rep(1:20, 10), y = rnorm(200), x = rnorm(200) ) fit <- dcce(df, unit_index = "id", time_index = "t", formula = y ~ x, model = "mg", cross_section_vars = NULL) coef(fit)
Convenience alias for bootstrap with an unambiguous
name. broom::bootstrap is a data-frame resampling helper that
shares a name with dcce::bootstrap but has a completely
different signature. If you load broom after dcce the
broom function masks ours on the search path and calls to
bootstrap(fit, type = ..., reps = ...) will fail with an
"unused arguments" error. dcce_bootstrap() is identical to
dcce::bootstrap() but cannot be masked by any other package.
dcce_bootstrap( object, type = c("crosssection", "wild"), reps = 500L, percentile = TRUE, cfresiduals = FALSE, seed = NULL )dcce_bootstrap( object, type = c("crosssection", "wild"), reps = 500L, percentile = TRUE, cfresiduals = FALSE, seed = NULL )
object |
A |
type |
Character: |
reps |
Integer: number of bootstrap repetitions. Default 500. |
percentile |
Logical: compute percentile CIs? Default |
cfresiduals |
Logical: for wild bootstrap, use common-factor
residuals instead of defactored residuals? Default |
seed |
Integer: random seed for reproducibility. Default |
See bootstrap.
set.seed(42) df <- data.frame( id = rep(1:10, each = 30), t = rep(1:30, 10), y = rnorm(300), x = rnorm(300) ) fit <- dcce(df, "id", "t", y ~ x, model = "mg", cross_section_vars = NULL) dcce_bootstrap(fit, reps = 50)set.seed(42) df <- data.frame( id = rep(1:10, each = 30), t = rep(1:30, 10), y = rnorm(300), x = rnorm(300) ) fit <- dcce(df, "id", "t", y ~ x, model = "mg", cross_section_vars = NULL) dcce_bootstrap(fit, reps = 50)
Fits a sequence of dcce() models on overlapping time windows of
the panel, producing a time path of coefficient estimates. Useful for
detecting coefficient drift, parameter instability, or regime shifts
in long panels.
dcce_rolling( data, unit_index, time_index, formula, model = "cce", window = 20L, step = 1L, min_units = 5L, verbose = FALSE, ... )dcce_rolling( data, unit_index, time_index, formula, model = "cce", window = 20L, step = 1L, min_units = 5L, verbose = FALSE, ... )
data |
A panel data.frame. |
unit_index |
Character: unit identifier column. |
time_index |
Character: time identifier column. |
formula |
Two-sided model formula passed through to |
model |
Character: estimator to use (default |
window |
Integer: window length in time periods. |
step |
Integer: number of time periods to advance between windows.
Default |
min_units |
Integer: minimum number of cross-sectional units a
window must retain after NA handling to be kept. Default |
verbose |
Logical: print progress? Default |
... |
Additional arguments passed to |
At each window the function subsets the panel to observations whose
time index falls in , runs
dcce() with the user-supplied arguments, and collects the
Mean Group coefficient vector and its standard errors. The result is
returned as a dcce_rolling object containing the full list of
fits and a tidy tibble of coefficients indexed by window end-date.
An object of class dcce_rolling containing:
List of dcce_fit objects, one per window
(or NULL for windows that failed).
A tibble with one row per
(window end-date, term) combination, columns window_end,
window_start, term, estimate, std.error,
conf.low, conf.high.
The window length.
The step size.
Number of successful windows.
The original call.
data(pwt8) roll <- dcce_rolling( data = pwt8, unit_index = "country", time_index = "year", formula = d_log_rgdpo ~ log_hc + log_ck + log_ngd, model = "cce", cross_section_vars = ~ ., window = 20, step = 2 ) print(roll)data(pwt8) roll <- dcce_rolling( data = pwt8, unit_index = "country", time_index = "year", formula = d_log_rgdpo ~ log_hc + log_ck + log_ngd, model = "cce", cross_section_vars = ~ ., window = 20, step = 2 ) print(roll)
A synthetic panel dataset generated from the dynamic common correlated effects DGP of Chudik and Pesaran (2015), equation (1). Generated with N = 30 cross-sectional units and T = 50 time periods. The true mean group parameters are: autoregressive coefficient 0.50, slope on x 1.00. Factor structure uses a single AR(1) common factor with persistence 0.60.
dcce_simdcce_sim
A data frame with 1500 rows and 4 columns:
Cross-sectional unit identifier (integer, 1–30)
Time period (integer, 1–50)
Simulated dependent variable
Simulated regressor (cross-sectionally dependent via common factor)
The true parameter values are stored in the companion object
dcce_sim_truth and can be used in tests to verify estimator
consistency.
Chudik, A. and Pesaran, M. H. (2015). Common correlated effects estimation of heterogeneous dynamic panel data models with weakly exogenous regressors. Journal of Econometrics, 188(2), 393–420.
dcce_sim_truth for the true parameter values.
A named list containing the true mean group parameter values used to
generate dcce_sim. Use in tests to verify that dcce() recovers
parameters close to their true values.
dcce_sim_truthdcce_sim_truth
A named list with elements:
True mean group autoregressive coefficient (~0.50)
True mean group slope on x (~1.00)
Number of cross-sectional units (30)
Number of time periods (50)
Random seed used for generation (20240101)
Runs the recommended pre-estimation diagnostic sequence on a panel
regression specification and returns a structured report with a
suggested dcce() call. The workflow performs six steps:
dcce_workflow( data, unit_index, time_index, formula, max_cr_lags = NULL, significance = 0.05, verbose = TRUE, n_bootstrap = 0L )dcce_workflow( data, unit_index, time_index, formula, max_cr_lags = NULL, significance = 0.05, verbose = TRUE, n_bootstrap = 0L )
data |
A panel data.frame. |
unit_index |
Character: unit identifier column. |
time_index |
Character: time identifier column. |
formula |
Two-sided formula (levels, not differences). |
max_cr_lags |
Integer: maximum CSA lag order to evaluate.
Default |
significance |
Numeric: significance level used for decisions.
Default |
verbose |
Logical: print progress as each step runs. Default
|
n_bootstrap |
Integer: bootstrap replications for the Westerlund
p-values. Default |
Panel summary (N, T, balance).
Pesaran (2007) CIPS panel unit root test on each variable.
Pesaran CD test on raw residuals (pooled OLS) to check for cross-sectional dependence.
Westerlund (2007) cointegration test, if at least one variable is non-stationary.
Rank condition classifier (De Vos et al. 2024) for a baseline static CCE fit.
Information criterion selection of the optimal CSA lag order.
Based on the results, the function chooses a recommended estimator
from c("mg", "cce", "dcce", "pmg", "csardl") and returns a
printable suggested dcce() call.
An object of class dcce_workflow with elements
panel_summary, unit_root, csd_premodel,
cointegration, rank_condition, optimal_cr_lags,
recommendation, and call.
data(pwt8) wf <- dcce_workflow( data = pwt8, unit_index = "country", time_index = "year", formula = log_rgdpo ~ log_hc + log_ck + log_ngd, verbose = FALSE ) print(wf)data(pwt8) wf <- dcce_workflow( data = pwt8, unit_index = "country", time_index = "year", formula = log_rgdpo ~ log_hc + log_ck + log_ngd, verbose = FALSE ) print(wf)
Extract fitted values from a dcce_fit object
## S3 method for class 'dcce_fit' fitted(object, ...)## S3 method for class 'dcce_fit' fitted(object, ...)
object |
A |
... |
Ignored. |
A numeric vector of fitted values (y-hat), or NULL if not
available.
Returns a single-row tibble of model summary statistics, compatible with the broom package.
## S3 method for class 'dcce_fit' glance(x, ...)## S3 method for class 'dcce_fit' glance(x, ...)
x |
A |
... |
Ignored. |
A single-row tibble.
Tests whether Granger-causes in a heterogeneous panel,
following Dumitrescu & Hurlin (2012). For each unit a bivariate
VAR-type regression is fitted:
and the individual Wald statistic for
is computed.
granger_test(data, unit_index, time_index, y, x, lags = 1L)granger_test(data, unit_index, time_index, y, x, lags = 1L)
data |
A panel data.frame. |
unit_index |
Character: unit identifier column. |
time_index |
Character: time identifier column. |
y |
Character: name of the dependent variable. |
x |
Character: name of the potential Granger-causing variable. |
lags |
Integer: lag order |
The panel statistics are:
The cross-sectional average of the N unit-level Wald statistics.
Standardised version:
.
Small-sample adjusted version using
and from the
distribution.
An object of class dcce_granger with elements:
Mean Wald statistic across units.
Standardised statistic (large-T).
Small-sample adjusted statistic.
p-value for Z-bar.
p-value for Z-bar tilde.
Named vector of per-unit Wald statistics.
Number of units used.
Average time-series length.
Lag order.
Dumitrescu, E.-I., & Hurlin, C. (2012). Testing for Granger non-causality in heterogeneous panels. Economic Modelling, 29(4), 1450–1460.
data(pwt8) gc <- granger_test( data = pwt8, unit_index = "country", time_index = "year", y = "d_log_rgdpo", x = "log_ck", lags = 1 ) print(gc)data(pwt8) gc <- granger_test( data = pwt8, unit_index = "country", time_index = "year", y = "d_log_rgdpo", x = "log_ck", lags = 1 ) print(gc)
Tests the null that the pooled and MG estimators are both consistent (i.e. slopes are homogeneous and the pooled estimator is efficient) against the alternative that slopes are heterogeneous and only MG is consistent. The test statistic is
hausman_test(object)hausman_test(object)
object |
A |
An object of class dcce_hausman with the test statistic,
degrees of freedom, and p-value.
Computes impulse response functions (IRFs) from a fitted dynamic panel model (DCCE, CS-ARDL, or PMG). The IRF traces the response of the dependent variable to a one-unit shock in a specific regressor over a given number of horizons, using the Mean Group ARDL coefficient estimates and the autoregressive lag polynomial.
irf(object, impulse, horizon = 10L, boot_reps = 200L, seed = NULL)irf(object, impulse, horizon = 10L, boot_reps = 200L, seed = NULL)
object |
A |
impulse |
Character: the regressor that receives the shock. |
horizon |
Integer: number of periods to trace. Default 10. |
boot_reps |
Integer: bootstrap replications for confidence bands. 0 = no bands. Default 200. |
seed |
Integer: random seed. |
Confidence bands are computed via the cross-section bootstrap: units are resampled with replacement, the MG coefficients are recomputed, and the IRF is re-traced. The 2.5 and 97.5 percent quantiles of the bootstrap distribution form the 95 percent band.
An object of class dcce_irf containing the impulse
response path ($irf), optional bootstrap lower/upper bands,
and metadata (impulse variable name and horizon length).
data(dcce_sim) fit <- dcce( data = dcce_sim, unit_index = "unit", time_index = "time", formula = y ~ L(y, 1) + x, model = "dcce", cross_section_vars = ~ ., cross_section_lags = 3 ) ir <- irf(fit, impulse = "x", horizon = 10, boot_reps = 0) print(ir)data(dcce_sim) fit <- dcce( data = dcce_sim, unit_index = "unit", time_index = "time", formula = y ~ L(y, 1) + x, model = "dcce", cross_section_vars = ~ ., cross_section_lags = 3 ) ir <- irf(fit, impulse = "x", horizon = 10, boot_reps = 0) print(ir)
Creates a lagged version of a variable for use inside dcce() formulas.
This function is evaluated during formula processing by dcce() and should
not be called directly on raw vectors outside of a dcce formula context.
L(x, k = 1L)L(x, k = 1L)
x |
A numeric vector (column name evaluated within |
k |
Integer lag order. Default 1. Positive values lag, negative lead. |
A numeric vector of the same length as x with leading NAs.
x <- c(10, 20, 30, 40, 50) L(x, 1) # NA 10 20 30 40 L(x, 2) # NA NA 10 20 30x <- c(10, 20, 30, 40, 50) L(x, 1) # NA 10 20 30 40 L(x, 2) # NA NA 10 20 30
Creates multiple lagged versions of a variable from lag k0 to lag k1.
Useful for distributed lag specifications.
Lrange(x, k0, k1)Lrange(x, k0, k1)
x |
A numeric vector. |
k0 |
Integer start lag (inclusive). |
k1 |
Integer end lag (inclusive). |
A matrix with columns L[k0] through L[k1].
x <- c(10, 20, 30, 40, 50) Lrange(x, 0, 2) # 3 columns: lag 0, lag 1, lag 2x <- c(10, 20, 30, 40, 50) Lrange(x, 0, 2) # 3 columns: lag 0, lag 1, lag 2
Implements simplified versions of the Pedroni (1999, 2004) and Kao (1999) residual-based panel cointegration tests.
panel_coint_test( data, unit_index, time_index, formula, test = c("pedroni", "kao"), lags = 1L )panel_coint_test( data, unit_index, time_index, formula, test = c("pedroni", "kao"), lags = 1L )
data |
A panel data.frame. |
unit_index |
Character: unit identifier column. |
time_index |
Character: time identifier column. |
formula |
Two-sided formula in levels: |
test |
Character: |
lags |
Integer: ADF lag order for the residual regression. Default 1. |
Pedroni: Fits unit-level OLS regressions of on
, extracts the residuals, runs an ADF
regression on each unit's residual series, and averages the
t-statistics. Reports the group-mean t-statistic (group_t)
and the group-mean rho-statistic (group_rho).
Kao: Similar but pools the residuals rather than averaging unit-level statistics. Reports a single ADF t-statistic on the demeaned pooled residuals.
Both tests have null hypothesis no cointegration. A large negative statistic rejects the null.
An object of class dcce_cointegration_extra with
elements test, statistics (a tibble), N,
T_bar, lags.
Pedroni, P. (1999). Critical values for cointegration tests in heterogeneous panels with multiple regressors. Oxford Bulletin of Economics and Statistics, 61(S1), 653–670.
Pedroni, P. (2004). Panel cointegration: asymptotic and finite sample properties of pooled time series tests with an application to the PPP hypothesis. Econometric Theory, 20(3), 597–625.
Kao, C. (1999). Spurious regression and residual-based tests for cointegration in panel data. Journal of Econometrics, 90(1), 1–44.
data(pwt8) panel_coint_test( data = pwt8, unit_index = "country", time_index = "year", formula = log_rgdpo ~ log_hc + log_ck, test = "pedroni", lags = 1 )data(pwt8) panel_coint_test( data = pwt8, unit_index = "country", time_index = "year", formula = log_rgdpo ~ log_hc + log_ck, test = "pedroni", lags = 1 )
Implements the Im, Pesaran & Shin (2003) IPS t-bar test and the
Levin, Lin & Chu (2002) LLC common-root test for panel unit roots.
Neither test corrects for cross-sectional dependence — use
cips_test for CSD-robust testing.
panel_ur_test(x, ...) ## S3 method for class 'matrix' panel_ur_test(x, ..., test = c("ips", "llc"), lags = 0L, trend = FALSE) ## Default S3 method: panel_ur_test( x, ..., data = NULL, unit_index = NULL, time_index = NULL, test = c("ips", "llc"), lags = 0L, trend = FALSE )panel_ur_test(x, ...) ## S3 method for class 'matrix' panel_ur_test(x, ..., test = c("ips", "llc"), lags = 0L, trend = FALSE) ## Default S3 method: panel_ur_test( x, ..., data = NULL, unit_index = NULL, time_index = NULL, test = c("ips", "llc"), lags = 0L, trend = FALSE )
x |
A numeric matrix (N x T), data.frame, or vector. |
... |
Additional arguments. |
test |
Character: |
lags |
Integer: ADF lag order. Default 0. |
trend |
Logical: include a time trend. Default FALSE. |
data, unit_index, time_index
|
Panel structure (when |
IPS: fits unit-level ADF regressions, averages the t-statistics, and standardises using tabulated moments from Im et al. (2003, Table 2).
LLC: fits unit-level ADF regressions, extracts the
t-statistic from a pooled regression of adjusted
on adjusted , standardised to N(0,1).
An object of class dcce_unit_root with elements
test, statistic, p_value, N, T,
lags, trend.
Im, K. S., Pesaran, M. H., & Shin, Y. (2003). Testing for unit roots in heterogeneous panels. Journal of Econometrics, 115(1), 53–74.
Levin, A., Lin, C.-F., & Chu, C.-S. J. (2002). Unit root tests in panel data: asymptotic and finite-sample properties. Journal of Econometrics, 108(1), 1–24.
set.seed(1) X <- matrix(cumsum(rnorm(20 * 30)), 20, 30) panel_ur_test(X, test = "ips") panel_ur_test(X, test = "llc")set.seed(1) X <- matrix(cumsum(rnorm(20 * 30)), 20, 30) panel_ur_test(X, test = "ips") panel_ur_test(X, test = "llc")
Computes cross-sectional dependence test statistics for panel data residuals. Implements the Pesaran (2015) CD test, CDw (Juodis & Reese 2022), PEA (Fan et al. 2015), and CD* (Pesaran & Xie 2021).
pcd_test(x, ...) ## S3 method for class 'dcce_fit' pcd_test( x, ..., test = c("pesaran", "cdw", "cdwplus", "pea", "cdstar"), n_reps = 500L, n_pca = 1L ) ## S3 method for class 'data.frame' pcd_test( x, ..., unit_index = NULL, time_index = NULL, test = c("pesaran", "cdw", "pea", "cdstar"), n_reps = 500L, n_pca = 1L ) ## S3 method for class 'matrix' pcd_test( x, ..., test = c("pesaran", "cdw", "pea", "cdstar"), n_reps = 500L, n_pca = 1L ) ## Default S3 method: pcd_test( x, ..., data = NULL, unit_index = NULL, time_index = NULL, test = c("pesaran", "cdw", "cdwplus", "pea", "cdstar"), n_reps = 500L, n_pca = 1L )pcd_test(x, ...) ## S3 method for class 'dcce_fit' pcd_test( x, ..., test = c("pesaran", "cdw", "cdwplus", "pea", "cdstar"), n_reps = 500L, n_pca = 1L ) ## S3 method for class 'data.frame' pcd_test( x, ..., unit_index = NULL, time_index = NULL, test = c("pesaran", "cdw", "pea", "cdstar"), n_reps = 500L, n_pca = 1L ) ## S3 method for class 'matrix' pcd_test( x, ..., test = c("pesaran", "cdw", "pea", "cdstar"), n_reps = 500L, n_pca = 1L ) ## Default S3 method: pcd_test( x, ..., data = NULL, unit_index = NULL, time_index = NULL, test = c("pesaran", "cdw", "cdwplus", "pea", "cdstar"), n_reps = 500L, n_pca = 1L )
x |
Either a numeric vector of residuals (stacked by unit),
a |
... |
Arguments passed to methods. |
test |
Character vector specifying which tests to compute.
One or more of |
n_reps |
Integer: number of Rademacher draws for CDw. Default 500. |
n_pca |
Integer: number of principal components for CD* bias correction. Default 1. |
unit_index |
Character: name of the unit variable in |
time_index |
Character: name of the time variable in |
data |
A data.frame containing the panel structure. Required if
|
An object of class dcce_cd containing:
A data.frame with columns test, statistic, p_value.
Number of cross-sectional units.
Average time dimension.
Matrix of pairwise correlations (if retained).
set.seed(42) df <- data.frame( id = rep(1:10, each = 20), t = rep(1:20, 10), e = rnorm(200) ) cd <- pcd_test(df$e, data = df, unit_index = "id", time_index = "t", test = "pesaran") print(cd)set.seed(42) df <- data.frame( id = rep(1:10, each = 20), t = rep(1:20, 10), e = rnorm(200) ) cd <- pcd_test(df$e, data = df, unit_index = "id", time_index = "t", test = "pesaran") print(cd)
Produces coefficient distribution plots (one histogram per regressor) showing the unit-level estimates and the MG mean.
## S3 method for class 'dcce_fit' plot(x, which = c("coef", "resid"), ...)## S3 method for class 'dcce_fit' plot(x, which = c("coef", "resid"), ...)
x |
A |
which |
Character: |
... |
Passed to the underlying graphics call. |
Invisibly returns x.
Plot a dcce_irf object
## S3 method for class 'dcce_irf' plot(x, ...)## S3 method for class 'dcce_irf' plot(x, ...)
x |
A |
... |
Passed to |
Invisibly returns x.
Produces one line per regressor showing the rolling-window coefficient against the window end-date, with a 95% confidence ribbon built from the unit-loop standard errors.
## S3 method for class 'dcce_rolling' plot(x, terms = NULL, ...)## S3 method for class 'dcce_rolling' plot(x, terms = NULL, ...)
x |
A |
terms |
Character vector of terms to plot. Default |
... |
Passed to the underlying graphics call. |
Invisibly returns x.
Predict from a dcce_fit object
## S3 method for class 'dcce_fit' predict(object, newdata = NULL, type = c("response", "xb"), ...)## S3 method for class 'dcce_fit' predict(object, newdata = NULL, type = c("response", "xb"), ...)
object |
A |
newdata |
Optional data.frame with new observations. When supplied,
predictions are computed using the Mean Group coefficients on the
structural regressors (CSAs are not applied because they depend on the
full cross-section). When |
type |
Character: |
... |
Ignored. |
A numeric vector of predictions.
Print method for dcce_boot objects
## S3 method for class 'dcce_boot' print(x, ...)## S3 method for class 'dcce_boot' print(x, ...)
x |
A |
... |
Ignored. |
Invisibly returns x.
Print a dcce_break object
## S3 method for class 'dcce_break' print(x, ...)## S3 method for class 'dcce_break' print(x, ...)
x |
A |
... |
Ignored. |
Invisibly returns x.
Print method for dcce_cd objects
## S3 method for class 'dcce_cd' print(x, ...)## S3 method for class 'dcce_cd' print(x, ...)
x |
A |
... |
Ignored. |
Invisibly returns x.
Print a dcce_cips object
## S3 method for class 'dcce_cips' print(x, ...)## S3 method for class 'dcce_cips' print(x, ...)
x |
A |
... |
Ignored. |
Invisibly returns x.
Print method for dcce_cointegration
## S3 method for class 'dcce_cointegration' print(x, ...)## S3 method for class 'dcce_cointegration' print(x, ...)
x |
A |
... |
Ignored. |
Invisibly returns x.
Print a dcce_cointegration_extra object
## S3 method for class 'dcce_cointegration_extra' print(x, ...)## S3 method for class 'dcce_cointegration_extra' print(x, ...)
x |
A |
... |
Ignored. |
Invisibly returns x.
Print method for dcce_csd objects
## S3 method for class 'dcce_csd' print(x, ...)## S3 method for class 'dcce_csd' print(x, ...)
x |
A |
... |
Ignored. |
Invisibly returns x.
Print a dcce_fit object
## S3 method for class 'dcce_fit' print(x, ...)## S3 method for class 'dcce_fit' print(x, ...)
x |
A |
... |
Ignored. |
Invisibly returns x.
Print a dcce_granger object
## S3 method for class 'dcce_granger' print(x, ...)## S3 method for class 'dcce_granger' print(x, ...)
x |
A |
... |
Ignored. |
Invisibly returns x.
Print a dcce_hausman object
## S3 method for class 'dcce_hausman' print(x, ...)## S3 method for class 'dcce_hausman' print(x, ...)
x |
A |
... |
Ignored. |
Invisibly returns x.
Print a dcce_irf object
## S3 method for class 'dcce_irf' print(x, ...)## S3 method for class 'dcce_irf' print(x, ...)
x |
A |
... |
Ignored. |
Invisibly returns x.
Print a dcce_rolling object
## S3 method for class 'dcce_rolling' print(x, ...)## S3 method for class 'dcce_rolling' print(x, ...)
x |
A |
... |
Ignored. |
Invisibly returns x.
Print a dcce_swamy object
## S3 method for class 'dcce_swamy' print(x, ...)## S3 method for class 'dcce_swamy' print(x, ...)
x |
A |
... |
Ignored. |
Invisibly returns x.
Print a dcce_unit_root object
## S3 method for class 'dcce_unit_root' print(x, ...)## S3 method for class 'dcce_unit_root' print(x, ...)
x |
A |
... |
Ignored. |
Invisibly returns x.
Print a dcce_workflow object
## S3 method for class 'dcce_workflow' print(x, ...)## S3 method for class 'dcce_workflow' print(x, ...)
x |
A |
... |
Ignored. |
Invisibly returns x.
Panel dataset from Jan Ditzen's xtdcce2 Stata package, originally derived from the Penn World Tables 8. Used in Ditzen (2018, Stata Journal 18:3, 585–617) to illustrate MG, CCE, and DCCE estimation. Contains 93 countries observed from 1960 to 2007 (balanced).
pwt8pwt8
A data frame with 4464 rows and 8 columns:
Country numeric identifier
Year (1960–2007)
Log real GDP (output-side)
Log human capital index
Log physical capital stock
Log of population growth plus depreciation
Country identifier (character)
First difference of log_rgdpo (GDP growth)
Downloaded from https://github.com/JanDitzen/xtdcce2.
Ditzen, J. (2018). Estimating dynamic common-correlated effects in Stata. The Stata Journal, 18(3), 585–617.
Implements the De Vos et al. (2024) rank condition classifier for CCE estimators. Tests whether the rank condition holds (RC=1) which ensures CCE consistency.
rank_condition(object, criterion = c("er", "gr"))rank_condition(object, criterion = c("er", "gr"))
object |
A |
criterion |
Character: |
Note: Only valid for static panels. Emits a warning if called on dynamic or PMG models.
An object of class dcce_rank with elements m (number of
common factors), g (rank of average factor loadings), RC (1 if
rank condition holds, 0 otherwise).
Extract residuals from a dcce_fit object
## S3 method for class 'dcce_fit' residuals(object, ...)## S3 method for class 'dcce_fit' residuals(object, ...)
object |
A |
... |
Ignored. |
A numeric vector.
Tests for and estimates structural breaks in heterogeneous panel data models with cross-sectional dependence. Implements a Wald-type Chow test at a known break date, a sup-Wald test for an unknown break date (with trimmed candidate set), and a sequential procedure for multiple breaks following Bai & Perron (1998) adapted to panel CCE settings.
structural_break_test( data, unit_index, time_index, formula, model = "cce", type = c("unknown", "known"), break_date = NULL, trim = 0.15, n_breaks = 1L, test_terms = NULL, verbose = FALSE, ... )structural_break_test( data, unit_index, time_index, formula, model = "cce", type = c("unknown", "known"), break_date = NULL, trim = 0.15, n_breaks = 1L, test_terms = NULL, verbose = FALSE, ... )
data |
A panel data.frame. |
unit_index |
Character: unit identifier column. |
time_index |
Character: time identifier column. |
formula |
Two-sided formula passed through to |
model |
Character: base estimator (default |
type |
Character: |
break_date |
Required when |
trim |
Numeric: trimming fraction at each end of the sample for
the unknown-break-date search. Default |
n_breaks |
Integer: maximum number of breaks to search for using
the sequential Bai-Perron procedure. Default |
test_terms |
Character vector: which coefficients to include in
the Wald statistic. Default |
verbose |
Logical: print progress during the candidate search.
Default |
... |
Additional arguments passed to |
For each candidate break date the function computes
where and are the Mean Group
coefficients from running the base estimator on the pre-break and
post-break sub-samples respectively, and , are
the corresponding MG variances. Under the null of no break the
statistic is distributed where is the number
of tested coefficients.
The unknown-break-date sup-Wald test reports
, where
is the interior of the sample after applying
the trimming parameter. Approximate p-values use the Andrews (1993)
large-sample distribution.
An object of class dcce_break with elements:
"known" or "unknown".
The Wald (or sup-Wald) test statistic.
Approximate p-value.
Degrees of freedom of the Wald statistic.
Known or estimated break date.
For type = "unknown": a tibble with one
row per candidate date (date, wald).
Vector of break dates when n_breaks > 1L.
dcce_fit object from the pre-break sub-sample.
dcce_fit object from the post-break sub-sample.
The original call.
Andrews, D. W. K. (1993). Tests for parameter instability and structural change with unknown change point. Econometrica, 61(4), 821-856.
Bai, J., & Perron, P. (1998). Estimating and testing linear models with multiple structural changes. Econometrica, 66(1), 47-78.
Ditzen, J., Karavias, Y., & Westerlund, J. (2024). Multiple structural breaks in interactive effects panel data models. Journal of Applied Econometrics.
data(pwt8) brk <- structural_break_test( data = pwt8, unit_index = "country", time_index = "year", formula = d_log_rgdpo ~ log_hc + log_ck + log_ngd, model = "mg", cross_section_vars = NULL, type = "unknown", trim = 0.20 ) print(brk)data(pwt8) brk <- structural_break_test( data = pwt8, unit_index = "country", time_index = "year", formula = d_log_rgdpo ~ log_hc + log_ck + log_ngd, model = "mg", cross_section_vars = NULL, type = "unknown", trim = 0.20 ) print(brk)
Summary for a dcce_fit object
## S3 method for class 'dcce_fit' summary(object, ...)## S3 method for class 'dcce_fit' summary(object, ...)
object |
A |
... |
Ignored. |
Invisibly returns object.
Tests the null hypothesis that all slope coefficients are identical across cross-sectional units, against the alternative of heterogeneous slopes. Implements the Swamy (1970) chi-square test and the Pesaran & Yamagata (2008) standardised dispersion statistic.
swamy_test(object)swamy_test(object)
object |
A |
The Swamy statistic is
where is the unit-level OLS estimate,
is the weighted pooled estimate, and
projects off the
intercept. Under (homogeneous slopes),
is asymptotically .
Pesaran & Yamagata (2008) propose a standardised version that is asymptotically standard normal:
An object of class dcce_swamy with elements S_stat,
delta_stat, df, p_swamy, p_delta, N, k.
Swamy, P. A. V. B. (1970). Efficient inference in a random coefficient regression model. Econometrica, 38(2), 311-323.
Pesaran, M. H., & Yamagata, T. (2008). Testing slope homogeneity in large panels. Journal of Econometrics, 142(1), 50-93.
Returns a tibble of MG coefficients with standard errors, test statistics, p-values, and confidence intervals, compatible with the broom package. For long-run estimators (CS-ARDL, CS-DL, PMG) the tibble additionally includes rows for long-run coefficients and the adjustment speed.
## S3 method for class 'dcce_fit' tidy(x, include_lr = TRUE, ...)## S3 method for class 'dcce_fit' tidy(x, include_lr = TRUE, ...)
x |
A |
include_lr |
Logical: include long-run and adjustment rows when
available? Default |
... |
Ignored. |
A tibble with columns term, estimate, std.error,
statistic, p.value, conf.low, conf.high, type.
Update a dcce_fit object
## S3 method for class 'dcce_fit' update(object, formula. = NULL, ..., evaluate = TRUE)## S3 method for class 'dcce_fit' update(object, formula. = NULL, ..., evaluate = TRUE)
object |
A |
formula. |
Optional replacement formula (use |
... |
Additional arguments passed to |
evaluate |
Logical: evaluate the updated call? Default |
An updated dcce_fit object (if evaluate = TRUE) or
an unevaluated call.
Extract variance-covariance matrix from a dcce_fit object
## S3 method for class 'dcce_fit' vcov(object, ...)## S3 method for class 'dcce_fit' vcov(object, ...)
object |
A |
... |
Ignored. |
A variance-covariance matrix.