Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
^doc$
^Meta$
^\.github$
^CRAN-SUBMISSION$
^_pkgdown\.yml$
^docs$
^pkgdown$
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ inst/doc
.Rprofile
/doc/
/Meta/
docs
3 changes: 3 additions & 0 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Version: 1.0.0
Date: 2026-02-17 20:27:31 UTC
SHA: 9ff062df4af4e5572f66abfeca5e27fa2f7b3886
11 changes: 8 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
Package: csdm
Title: Cross-Sectional Dependence Models
Version: 1.0.0
Version: 1.0.1
Depends: R (>= 4.0.0)
Imports: MASS
Imports: MASS,
Rdpack
RdMacros: Rdpack
Suggests:
testthat (>= 3.0.0),
knitr,
Expand All @@ -14,7 +16,10 @@ Authors@R:
person(given = c("Joao", "Claudio"),
family = "Macosso",
email = "joaoclaudiomacosso@gmail.com",
role = c("aut", "cre"))
role = c("aut", "cre"),
comment = c(ORCID = "0009-0006-5051-9312"))
URL: https://github.com/Macosso/csdm
BugReports: https://github.com/Macosso/csdm/issues
Description: Provides estimators and utilities for large panel-data models with cross-sectional dependence, including mean group (MG), common correlated effects (CCE) and dynamic CCE (DCCE) estimators, and cross-sectionally augmented ARDL (CS-ARDL) specifications, plus related inference and diagnostics.
License: GPL-3
Encoding: UTF-8
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export(get_residuals)
export(pooled_vcov)
export(prepare_cd_input)
export(sandwich_vcov)
importFrom(Rdpack,reprompt)
importFrom(stats,aggregate)
importFrom(stats,cor)
importFrom(stats,model.matrix.lm)
Expand Down
13 changes: 13 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,16 @@
### Inference and diagnostics
- Cross-sectional dependence (CD) tests
- Summary and printing methods


# csdm 1.0.1

## Documentation and References enhancement

### References
- Added references for the implemented estimators and methods, including key papers and textbooks in the field

### Documentation
- Improved documentation for all functions, including detailed descriptions of the estimators, their assumptions, and
- Ensured consistency in the documentation style across different documents
- Added link for reporting bugs
168 changes: 115 additions & 53 deletions R/csdm.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# csdm.R

#' Panel Model Estimation with Cross Section Dependence
#' Panel Model Estimation with Cross-Sectional Dependence
#'
#' Estimate panel data models that allow for cross-sectional dependence and
#' heterogeneous slopes. The interface supports Mean Group (MG), Common
#' Correlated Effects (CCE), Dynamic CCE (DCCE), and Cross-Sectionally
#' Augmented ARDL (CS-ARDL) estimators with consistent handling of
#' cross-sectional averages, dynamic structure, and robust inference.
#' Estimate heterogeneous panel data models with optional cross-sectional
#' augmentation and dynamic structure. The interface supports Mean Group (MG),
#' Common Correlated Effects (CCE), Dynamic CCE (DCCE), and
#' Cross-Sectionally Augmented ARDL (CS-ARDL) estimators with a consistent
#' specification workflow for cross-sectional averages, lag structure, and
#' variance-covariance estimation.
#'
#' @param formula Model formula of the form \code{y ~ x1 + x2}.
#' @param data A \code{data.frame} (or \code{plm::pdata.frame}) containing the
Expand All @@ -29,59 +30,120 @@
#'
#' @return An object of class \code{csdm_fit} containing estimated coefficients,
#' residuals, variance-covariance estimates, model metadata, and diagnostics.
#' Use \code{summary()}, \code{coef()}, \code{residuals()}, \code{vcov()}, and
#' \code{cd_test()} to access standard outputs.
#' Use [summary()], [coef()], [residuals()], [vcov()], and
#' [cd_test()] to access standard outputs.
#'
#' @details
#' ## Model equations
#'
#' \describe{
#' \item{MG (Pesaran and Smith, 1995)}{
#' \deqn{y_{it} = x_{it}^\top \beta_i + u_{it}}
#' }
#' \item{CCE (Pesaran, 2006)}{
#' \deqn{y_{it} = x_{it}^\top \beta_i + \lambda_i^\top F_t + u_{it}}
#' }
#' \item{DCCE (Chudik and Pesaran, 2015)}{
#' \deqn{\Delta y_{it} = \Delta x_{it}^\top \beta_i + \lambda_i^\top \Delta F_t + u_{it}}
#' }
#' \item{CS-ARDL (Chudik and Pesaran, 2015)}{
#' \deqn{y_{it} = \phi_i y_{it-1} + x_{it}^\top \theta_i + \lambda_i^\top F_t + u_{it}}
#' }
#' }
#'
#' ## Estimation, identification, and assumptions
#'
#' \describe{
#' \item{MG}{Unit-by-unit estimation with heterogeneous slopes. The reported
#' coefficients are cross-sectional averages of unit estimates. Requires
#' sufficient time series per unit and weak serial dependence in errors.}
#' \item{CCE}{Augments regressions with cross-sectional averages (CSA) to proxy
#' unobserved common factors. Identification relies on large N and T, weak
#' dependence in idiosyncratic errors after CSA, and weak exogeneity of
#' regressors.}
#' \item{DCCE}{Extends CCE to dynamic settings with lagged dependent variables
#' and CSA lags. Identification relies on weak exogeneity, adequate time length
#' for dynamic lags, and a stable factor structure.}
#' \item{CS-ARDL}{Specifies dynamic distributed lags with CSA terms. Estimation
#' follows ARDL-style dynamics in each unit and aggregates to panel averages.
#' Assumes weak exogeneity and sufficient time length for lag structure.}
#' }
#' Let \eqn{i = 1, \ldots, N} index cross-sectional units and
#' \eqn{t = 1, \ldots, T} index time. A baseline heterogeneous panel model is
#'
#' @references
#' Pesaran, M.H. and Smith, R. (1995). "Estimating long-run relationships from
#' dynamic heterogeneous panels." Journal of Econometrics, 68(1), 79-113.
#' \deqn{y_{it} = \alpha_i + \beta_i^T x_{it} + u_{it}.}
#'
#' Here \eqn{\alpha_i} is a unit-specific intercept, \eqn{x_{it}} is a vector
#' of regressors, \eqn{\beta_i} is a vector of unit-specific slopes, and
#' \eqn{u_{it}} is an error term that may exhibit cross-sectional dependence.
#'
#' Cross-sectional averages are specified through [csdm_csa()] and dynamic or
#' long-run structure is specified through [csdm_lr()]. This keeps the model
#' interface consistent across estimators while allowing the degree of
#' cross-sectional augmentation and lag structure to vary by application.
#'
#' \strong{Implemented estimators}
#'
#' \strong{MG (Pesaran and Smith, 1995)}
#'
#' The Mean Group estimator fits separate regressions for each unit and averages
#' the resulting coefficients:
#'
#' \deqn{\hat{\beta}_{MG} = \frac{1}{N}\sum_{i=1}^N \hat{\beta}_i.}
#'
#' This estimator accommodates slope heterogeneity but does not explicitly model
#' cross-sectional dependence.
#'
#' \strong{CCE (Pesaran, 2006)}
#'
#' Regressions are augmented with cross-sectional averages to proxy unobserved
#' common factors:
#'
#' \deqn{y_{it} = \alpha_i + \beta_i^T x_{it} + \gamma_i^T \bar{z}_{t} + v_{it}.}
#'
#' A common choice is
#'
#' \deqn{\bar{z}_t = (\bar{y}_t, \bar{x}_t),}
#'
#' with
#'
#' \deqn{\bar{x}_t = \frac{1}{N}\sum_{i=1}^N x_{it}, \qquad
#' \bar{y}_t = \frac{1}{N}\sum_{i=1}^N y_{it}.}
#'
#' More generally, \eqn{\bar{z}_t} collects the cross-sectional averages
#' specified in \code{csa}.
#'
#' \strong{DCCE (Chudik and Pesaran, 2015)}
#'
#' Pesaran, M.H. (2006). "Estimation and inference in large heterogeneous panels
#' with multifactor error structure." Econometrica, 74(4), 967-1012.
#' Dynamic CCE extends CCE by allowing lagged dependent variables and lagged
#' cross-sectional averages:
#'
#' \deqn{y_{it} = \alpha_i + \sum_{p=1}^{P} \phi_{ip} y_{i,t-p}
#' + \beta_i^T x_{it}
#' + \sum_{q=0}^{Q} \delta_{iq}^T \bar{z}_{t-q}
#' + e_{it}.}
#'
#' In the package implementation, lagged dependent variables and distributed
#' lags of regressors are controlled through \code{lr}, while contemporaneous
#' and lagged cross-sectional averages are controlled through \code{csa}.
#'
#' \strong{CS-ARDL (Chudik and Pesaran, 2015)}
#'
#' In the package implementation, \code{model = "cs_ardl"} is obtained by first
#' estimating a cross-sectionally augmented ARDL-style regression in levels,
#' using the same dynamic specification as \code{model = "dcce"}, and then
#' transforming the unit-specific coefficients into adjustment and long-run
#' parameters.
#'
#' The underlying unit-level regression is of the form
#'
#' \deqn{y_{it} = \alpha_i + \sum_{p=1}^{P} \phi_{ip} y_{i,t-p}
#' + \sum_{q=0}^{Q} \beta_{iq}^T x_{i,t-q}
#' + \sum_{s=0}^{S} \omega_{is}^T \bar{z}_{t-s}
#' + e_{it}.}
#'
#' From this dynamic specification, the package recovers the implied
#' error-correction form
#'
#' \deqn{\Delta y_{it} =
#' \alpha_i +
#' \varphi_i \left(y_{i,t-1} - \theta_i^T x_{i,t-1}\right)
#' + \sum_{j=1}^{P-1} \lambda_{ij} \Delta y_{i,t-j}
#' + \sum_{j=0}^{Q-1} \psi_{ij}^T \Delta x_{i,t-j}
#' + \sum_{s=0}^{S} \tilde{\omega}_{is}^T \bar{z}_{t-s}
#' + e_{it},}
#'
#' where \eqn{\varphi_i} is the adjustment coefficient and \eqn{\theta_i} is
#' the implied long-run relationship. In the current implementation, these
#' quantities are computed from the estimated lag polynomials rather than from a
#' direct ECM regression.
#'
#' \strong{Identification and assumptions}
#'
#' MG requires sufficient time-series variation within each unit.
#'
#' CCE relies on cross-sectional averages acting as proxies for latent common
#' factors, together with adequate cross-sectional and time dimensions.
#'
#' DCCE additionally requires enough time periods to support lagged dependent
#' variables, distributed lags, and lagged cross-sectional averages.
#'
#' CS-ARDL requires sufficient time length for the distributed-lag structure and
#' is intended for applications where both short-run dynamics and long-run
#' relationships are of interest in the presence of common factors.
#'
#' @references
#' \insertRef{PesaranSmith1995}{csdm}
#'
#' 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.
#' \insertRef{Pesaran2006}{csdm}
#'
#' Chudik, A. and Pesaran, M.H. (2015). "Large panel data models with
#' cross-sectional dependence: A survey." Annals of Economics and Finance, 16(1),
#' 53-78.
#' \insertRef{ChudikPesaran2015a}{csdm}
#'
#' @examples
#' library(csdm)
Expand Down
6 changes: 3 additions & 3 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#' Penn World Tables panel (93 countries, 19602007)
#' Penn World Tables panel (93 countries, 1960-2007)
#'
#' A panel of 93 countries (unit id) observed annually over 19602007 (time/year),
#' A panel of 93 countries (unit id) observed annually over 1960-2007 (time/year),
#' with the log-transformed variables used in
#' xtdcce2-style examples.
#'
#' @format A data frame with 4464 rows and 6 variables:
#' \describe{
#' \item{id}{Unit identifier (country id).}
#' \item{year}{Time identifier (year, 19602007).}
#' \item{year}{Time identifier (year, 1960-2007).}
#' \item{log_rgdpo}{Log real GDP (output).}
#' \item{log_hc}{Log human capital index.}
#' \item{log_ck}{Log capital stock.}
Expand Down
16 changes: 5 additions & 11 deletions R/utils_cd.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,15 @@
#' }
#'
#' @references
#' Pesaran, M.H. (2015). "Testing weak cross-sectional dependence in large panels."
#' \emph{Econometric Reviews}, 34(6-10), 1089-1117.
#' \insertRef{Pesaran2015}{csdm}
#'
#' Pesaran, M.H. (2021). "General diagnostic tests for cross-sectional dependence
#' in panels." \emph{Empirical Economics}, 60, 13-50.
#' \insertRef{Pesaran2021}{csdm}
#'
#' Juodis, A., & Reese, S. (2021). "The incidental parameters problem in testing for
#' remaining cross-sectional correlation." \emph{Journal of Business and Economic Statistics},
#' 40(3), 1193-1203.
#' \insertRef{JuodisReese2021}{csdm}
#'
#' Fan, J., Liao, Y., & Yao, J. (2015). "Power Enhancement in High-Dimensional
#' Cross-Sectional Tests." \emph{Econometric Reviews}, 34(6-10), 742-779.
#' \insertRef{FanLiaoYao2015}{csdm}
#'
#' Pesaran, M.H., & Xie, Y. (2021). "A bias-corrected CD test for error cross-sectional
#' dependence in panel models." \emph{Econometric Reviews}, 41(6), 649-677.
#' \insertRef{PesaranXie2021}{csdm}
#'
#' @examples
#' # Simulate independent and dependent panels
Expand Down
1 change: 1 addition & 0 deletions R/zzz_imports.R
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#' @importFrom stats aggregate cor model.matrix.lm pt residuals sd setNames symnum terms
#' @importFrom Rdpack reprompt
NULL
Loading
Loading