*! version 1.0.1 08apr2026

Title

xtpqcs -- Panel Quantile Regression with Common Shocks

Syntax

xtpqcs depvar indepvars [if] [in],
id(varname)
time(varname)
[options]

Required
id(varname) cross-sectional unit identifier (numeric)

time(varname) time period identifier (numeric)

Estimation
quantile(#) quantile index tau in (0,1); default 0.5

bandwidth(#) kernel bandwidth h > 0; default Silverman with floor 0.05

kernel(string) gaussian (default), epanechnikov, or uniform

compare report classical Kato et al. (2012) SEs instead of robust SEs

Reporting
level(#) confidence level for CI; default level(95)

noheader suppress the header table above the coefficient table

depvar and indepvars must be numeric variables.
The panel must contain at least 2 cross-sectional units
and at least 5 time periods.
Missing values are excluded via marksample.

Description

xtpqcs estimates the fixed-effects panel quantile regression (FEQR) model

Qtau(Yit | Xit, alphai) =
alphai(tau) + Xitbeta(tau)

using the unregularised Koenker (2004) concentration algorithm and reports
the robust covariance matrix of Chiang, Galvao and Wei (2026,
arXiv:2602.19201), which remains consistent in the presence (or absence) of
pervasive common time shocks Bt that induce arbitrary
cross-sectional dependence.

Why does this matter? In macro/finance panels the residuals of different
units are contemporaneously correlated because common factors (business cycles,
monetary policy, oil prices) affect everybody at the same time. Classical FEQR
theory ignores this correlation, leading to downward-biased standard errors
and over-rejection of the null. xtpqcs eliminates this problem.

Under the common-shock framework the asymptotic distribution is

sqrt(T) * (beta_hat - beta_0) --> N(0, V),

V = Gamma-1 Sigma Gamma-1 (Theorem 1)

and xtpqcs reports SE = sqrt(diag(V_hat)/T).

xtpqcs also computes the classical Kato et al. (2012) sandwich
covariance and stores it in e(V_classical). By default the robust
estimator is used; specify compare to report the classical one instead.
Both are always stored regardless.

By Theorem 2 of Chiang, Galvao and Wei (2026), the robust estimator is
consistent both in the presence and in the absence of common shocks.
The practitioner does not need to know ex ante whether shocks are present.

Options

Required

id(varname) specifies the variable that identifies
cross-sectional units. Must be numeric. This is required.

time(varname) specifies the variable that identifies
time periods. Must be numeric. This is required.

Estimation

quantile(#) specifies the quantile index tau.
Must lie strictly between 0 and 1. Default is 0.5
(conditional median regression).

bandwidth(#) specifies the kernel bandwidth h
used to estimate the conditional density fi(0|X). Default is
Silverman's rule:

h = max(0.05, 1.06 * sd(eps_hat) * N-1/5)

where N is the cross-sectional dimension. The floor of 0.05 follows the
simulation design in Section 5 of Chiang, Galvao and Wei (2026). The user
may override this with any positive value.

kernel(string) selects the kernel function.
Allowed values:

gaussian (default) -- standard normal density phi(u/h)/h

epanechnikov -- 0.75*(1-u2)*I(|u|<=1) / h

uniform -- 0.5*I(|u|<=1) / h

compare replaces the displayed covariance with the classical Kato
et al. (2012) sandwich estimator. This option is useful for demonstrating
the size distortion caused by ignoring common shocks. Both matrices are
always stored in e(), regardless of this option.

Reporting

level(#) sets the confidence level for the reported table;
default is 95.

noheader suppresses the summary header above the coefficient table.
Useful when estimating across many quantiles in a loop.

Requirements

Stata version: 14.0 or later.

Panel structure: The data must be a panel with at least
N >= 2 cross-sectional units and T >= 5 time periods. The panel
need not be balanced; unbalanced panels are handled automatically.

Variable types: All variables (depvar, indepvars, id, time) must
be numeric. String identifiers should be encoded first with
encode or egen group().

No constant: Do not include a constant in indepvars; the individual
fixed effects alphai(tau) absorb it.

Dependencies: qreg and egen must be available (they ship
with Stata). No external packages are required.

Technical notes

Estimation algorithm. xtpqcs uses the iterative concentration
algorithm of Koenker (2004), which avoids creating N dummy variables:

1. Initialise beta from pooled qreg.

2. Compute alphai(beta) = tau-quantile of
within each unit i (in Mata).

3. Update beta from qreg of (Y - alpha_i) on X (only p parameters,
always fast).

4. Repeat steps 2-3 until max|beta_new - beta_old| < 1e-6,
or at most 50 iterations.

This converges to the exact Koenker (2004) solution and scales well to
very large panels (N*T > 1,000,000) because the qreg step never
includes dummy variables.

Covariance estimation. Four matrices are estimated in Mata (see paper):

Gamma_hat = (1/n) sum K_h(eps_it) * X_it * (X_it - gamma_i)'

Sigma_hat = (1/T) sum_t (m_t - mbar)(m_t - mbar)'

V_robust = Gamma-1 Sigma Gamma-1 / T

V_classical = tau(1-tau) * Gamma-1 Omega Gamma-1 / (NT)

where gammai is the unit-level weighted-average regressor,
mt is the cross-sectional mean of psiit at time t,
and Omega is the classical quadratic-form matrix.

Asymptotic regime. The theory requires (log N)2/T 0.
Practically, T >= 10 is recommended. The estimator also works in
the "large T" classical regime.

Replay. After estimation, typing xtpqcs without arguments replays
the last results, optionally with a new level().

Warnings and cautions

WARNING: No constant in the model. Do not include _cons or a
variable equal to 1 in indepvars. The unit fixed effects
alphai(tau) already absorb the intercept. Including a constant
will cause collinearity and numerical failure.

WARNING: Extreme quantiles. At tau near 0 or 1
(e.g. 0.01 or 0.99), the kernel density estimates may be imprecise because
very few residuals fall near zero. Consider using tau in [0.05, 0.95] unless
T is very large (>= 100).

WARNING: Small T. When T < 10 the asymptotic approximation for
the robust covariance Sigma_hat (which averages T cross-sectional means) may
be poor. The command requires T >= 5 and will refuse to run if T < 5.

CAUTION: Bandwidth sensitivity. The kernel density estimates
Gamma_hat and fi(0|X) depend on the bandwidth h. The Silverman
default is a sensible choice but practitioners should check robustness by
running the estimation with 2-3 different bandwidth() values.

CAUTION: Dependent variable scale. The bandwidth is chosen
relative to the residual standard deviation. Rescaling Y by a large
constant will change the automatic bandwidth. This does not affect
coefficients but can affect SEs.

CAUTION: Interpreting compare. When common shocks are present,
the classical SEs (compare) are typically too small, leading to
over-rejection of the null. The user should prefer the default robust SEs
unless they have strong reasons to believe that cross-sectional independence
holds exactly.

CAUTION: Unbalanced panels. Unbalanced panels are supported but
the theory technically assumes a balanced panel. Moderate imbalance is fine;
severely unbalanced panels (e.g. some units observed for only 2 periods)
may yield imprecise unit-level quantile estimates.

Examples

Setup: Generate panel data from the paper's DGP

. clear

. set seed 2026

. set obs 200

. gen id = _n

. gen alpha = runiform()

. expand 30

. bys id: gen t = _n

. gen X = rchi2(3) + 0.3*alpha

. sort t

. by t: gen eta = rnormal() if _n==1

. by t: replace eta = eta[1]

. gen eps = rnormal()

. gen U = (eps + eta)/sqrt(2)

. gen y = alpha + 1*X + (1 + 0.2*X)*U

. xtset id t

Example 1: Median regression with robust SEs (default)

. xtpqcs y X, id(id) time(t)

Example 2: Lower tail (tau=0.10)

. xtpqcs y X, id(id) time(t) quantile(0.10)

Example 3: Compare robust vs. classical SEs

. xtpqcs y X, id(id) time(t) quantile(0.50)

. xtpqcs y X, id(id) time(t) quantile(0.50) compare

Note: the classical SEs are noticeably smaller, illustrating the size
distortion documented in Petersen (2008) and analysed in Theorem 1.

Example 4: Multiple regressors

. gen X2 = rnormal()

. replace y = y + 0.5*X2

. xtpqcs y X X2, id(id) time(t) quantile(0.50)

Example 5: Estimate across several quantiles

. foreach q in 0.10 0.25 0.50 0.75 0.90 {

. xtpqcs y X, id(id) time(t) quantile(`q') noheader

. }

Example 6: Epanechnikov kernel with custom bandwidth

. xtpqcs y X, id(id) time(t) quantile(0.50) kernel(epanechnikov) bandwidth(0.3)

Example 7: Inspect stored matrices

. xtpqcs y X, id(id) time(t) quantile(0.50)

. matrix list e(V_robust)

. matrix list e(V_classical)

. matrix list e(Gamma_hat)

. matrix list e(Sigma_hat)

Example 8: Quantile process plot

. xtpqcsplot y X, id(id) time(t) quantiles(0.05(0.05)0.95)

Example 9: Monte Carlo replication of paper Section 5

. xtpqcsmc, n(500) tperiods(30) reps(200) quantile(0.50)

Stored results

xtpqcs stores the following in e():

Scalars

e(N) total number of observations used

e(N_g) number of cross-sectional units (groups)

e(T) number of time periods

e(quantile) quantile index tau

e(bandwidth) kernel bandwidth h actually used

e(df_r) residual degrees of freedom (T - p)

Macros

e(cmd) xtpqcs

e(cmdline) full command as typed

e(depvar) name of dependent variable

e(ivar) panel id variable

e(tvar) time variable

e(kernel) kernel function used

e(vce) robust_cgw

e(vcetype) description of the SE method displayed

Matrices

e(b) 1 x p coefficient vector beta_hat(tau)

e(V) p x p displayed variance-covariance (robust or classical)

e(V_robust) p x p robust CGW covariance: Gamma-1 Sigma Gamma-1 / T

e(V_classical) p x p classical Kato et al. (2012) sandwich

e(Gamma_hat) p x p Jacobian estimate Gamma_hat

e(Sigma_hat) p x p common-shock long-run variance Sigma_hat

e(Omega_hat) p x p classical Omega_hat

Functions

e(sample) marks estimation sample

References

Chiang, H. D., A. F. Galvao, and C.-M. Wei. 2026.
Panel Quantile Regression with Common Shocks.
arXiv:2602.19201.

Kato, K., A. F. Galvao, and G. V. Montes-Rojas. 2012. Asymptotics for panel
quantile regression models with individual effects.
Journal of Econometrics 170: 76-91.

Koenker, R. 2004. Quantile regression for longitudinal data.
Journal of Multivariate Analysis 91: 74-89.

Galvao, A. F., J. Gu, and S. Volgushev. 2020. On the unbiased asymptotic
normality of quantile regression with fixed effects.
Journal of Econometrics 218: 178-215.

Petersen, M. A. 2009. Estimating standard errors in finance panel data sets:
Comparing approaches.
Review of Financial Studies 22: 435-480.

Also see

Help: xtpqcsplot, xtpqcsmc, qreg,
xtset

Author

Dr. Merwan Roudane

Email: merwanroudane920@gmail.com

Stata implementation of Chiang, Galvao and Wei (2026).