% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/xtcsdq.R
\name{xtcsdq}
\alias{xtcsdq}
\title{Tests of No Cross-Sectional Dependence in Panel Quantile Regressions}
\usage{
xtcsdq(
  formula = NULL,
  data = NULL,
  index = NULL,
  quantiles,
  mode = c("pooled", "individual", "residuals"),
  residuals = NULL,
  bandwidth = NULL,
  correction = TRUE
)
}
\arguments{
\item{formula}{A formula of the form \code{y ~ x1 + x2 + ...}. Required for
\code{mode = "pooled"} (default) and \code{mode = "individual"}.
Not used when \code{residuals} is provided.}

\item{data}{A data frame containing the panel data in long format. Required
unless \code{residuals} is provided.}

\item{index}{A character vector of length 2: \code{c("id_var", "time_var")}.
Required unless \code{residuals} is provided.}

\item{quantiles}{A numeric vector of quantile levels, each strictly between
0 and 1.}

\item{mode}{Estimation mode: \code{"pooled"} (default, pooled FE-QR),
\code{"individual"} (per-unit QR), or \code{"residuals"} (provide
pre-computed residuals via the \code{residuals} argument).}

\item{residuals}{A list (or named list) of numeric vectors or a matrix with
one column per quantile, containing pre-computed QR residuals. Only used
when \code{mode = "residuals"}.}

\item{bandwidth}{Numeric. KDE bandwidth for sparsity estimation. If
\code{NULL} (default), uses \eqn{0.35 (NT)^{-0.2}}.}

\item{correction}{Logical. If \code{TRUE} (default), reports the
bias-corrected T-tilde statistic in addition to T_tau.}
}
\value{
An object of class \code{"xtcsdq"} with components:
  \describe{
    \item{T_tau}{Numeric vector of T_tau statistics (one per quantile).}
    \item{Ttilde_tau}{Numeric vector of bias-corrected T-tilde_tau statistics.}
    \item{pval_T}{p-values for T_tau.}
    \item{pval_Ttilde}{p-values for T-tilde_tau.}
    \item{fhat}{KDE density estimates at zero (one per quantile).}
    \item{M_K}{Portmanteau statistic (average of T_tau over quantiles).}
    \item{Mtilde_K}{Bias-corrected portmanteau statistic.}
    \item{pval_M}{p-value for M_K.}
    \item{pval_Mc}{p-value for Mtilde_K.}
    \item{quantiles}{Quantile levels used.}
    \item{N}{Number of cross-sectional units.}
    \item{TT}{Number of time periods.}
    \item{bandwidth}{KDE bandwidth used.}
  }
}
\description{
Tests the null hypothesis of no cross-sectional error dependence (CSD) in
panel quantile regressions. Implements the T_tau and T-tilde_tau statistics
of Demetrescu, Hosseinkouchack and Rodrigues (2023).
}
\details{
The T_tau statistic (Equation 3 in Demetrescu et al., 2023) tests for CSD
by examining pairwise correlations of demeaned QR residuals across units.
Under the null of no CSD, T_tau is asymptotically standard normal.

The bias-corrected version T-tilde_tau (Equation 5) subtracts two correction
terms that account for the estimation uncertainty in the QR slope and the
sparsity at the quantile. Reject H0 for large positive values.

The portmanteau statistic \eqn{M_K = K^{-1} \sum_{q=1}^K T_\tau^{(q)}}
aggregates across K quantile levels.

The KDE bandwidth defaults to \eqn{h = 0.35 (NT)^{-0.2}} as in the
original paper.
}
\examples{
\donttest{
set.seed(42)
n <- 8; tt <- 20
dat <- data.frame(
  id   = rep(1:n, each = tt),
  time = rep(1:tt, times = n),
  y    = rnorm(n * tt),
  x1   = rnorm(n * tt)
)
res <- xtcsdq(y ~ x1, data = dat, index = c("id", "time"),
              quantiles = c(0.25, 0.5, 0.75))
print(res)
summary(res)
}

}
\references{
Demetrescu, M., Hosseinkouchack, M. and Rodrigues, P.M.M. (2023).
Testing for No Cross-Sectional Error Dependence in Panel Quantile
Regressions.
\emph{Ruhr Economic Papers}, No. 1041.
\doi{10.4419/96973002}
}
