*! version 1.0.0 27feb2026

Title

xtqsh -- Quantile Regression Slope Homogeneity Test for Panel Data

Syntax

xtqsh
depvar
indepvars
[if] [in],
tau(numlist)
[options]

Required
tau(numlist) quantile(s) to test; values must be between 0 and 1

Variance estimation
bw(method) bandwidth rule for kernel density estimation;
method is bofinger or hallsheather (default)

hac(#) number of HAC (Bartlett kernel) lags for serially
dependent data; default is 0 (i.i.d.)

Test options
marginal perform additional marginal (per-variable) slope
homogeneity tests

level(#) confidence level for bandwidth calculation;
default is c(level)

Reporting
graph produce visualization suite (5 graphs)

notable suppress tabular output

A panel variable and a time variable must be specified; use xtset.

Description

xtqsh implements the Swamy-type and standardized Swamy-type slope
homogeneity tests proposed by Galvao, Juhl, Montes-Rojas, and Olmo (2017)
for quantile regression (QR) fixed-effects panel data models.

The tests assess whether the slope coefficients in a panel QR model are
homogeneous across all cross-sectional units:

H₀ : β₁(τ) = β₂(τ) = ··· = βₙ(τ) for a given quantile τ

H₁ : βᵢ(τ) ≠ βⱼ(τ) for some i ≠ j

Interpretation: If the test does not reject H₀, pooling is
appropriate and one may use the standard FE-QR estimator. If the test
rejects H₀, slopes are heterogeneous and individual time-series
estimation for each panel is more appropriate.

xtqsh also reports the classical Swamy (1970) test applied to the
OLS (mean) regression as a baseline comparison.

Note: At extreme quantiles (e.g., τ = 0.05 or 0.95) with small T,
Stata's built-in qreg may fail to estimate the sparsity function.
In such cases, xtqsh automatically falls back to a Mata-based IRLS
quantile regression solver to ensure valid estimates are produced.

Options

Required

tau(numlist) specifies one or more quantiles at which to perform the
slope homogeneity test. Multiple quantiles produce a table of results
across the distribution. Example: tau(0.10 0.25 0.50 0.75 0.90).

Variance estimation

bw(method) chooses the bandwidth rule for the Powell (1986) kernel
density estimator used in constructing the variance–covariance matrices.
bofinger uses the Bofinger (1975) rule; hallsheather (default)
uses the Hall–Sheather (1988) rule. These are the two rules studied in the
Monte Carlo experiments of Galvao et al. (2017).

hac(#) activates the HAC adjustment for serially dependent data
(Theorem 2 of Galvao et al. 2017). When # > 0, a Newey–West style
Bartlett kernel with # lags is used to estimate the long-run variance
matrices. Use this when your data exhibit serial correlation (β-mixing).
A common rule of thumb is # = floor(T^{1/3}).

Test options

marginal requests marginal (per-variable) slope homogeneity tests
in addition to the joint test. For each covariate individually, the
Swamy and standardized Swamy statistics are computed with k=1 and reported
in a separate table.

level(#) sets the significance level used in the Hall–Sheather
bandwidth formula. Default is c(level).

Reporting

graph produces a suite of five publication-quality graphs: a p-value
process plot, a marginal p-value heatmap (if marginal is specified),
a coefficient distribution fan chart (replicating Figure 1 of the paper),
an MD-QR coefficient process with 95% CI bands, and a summary dashboard.

notable suppresses all tabular output. Useful when only the stored
results or graphs are needed.

Methodology

Model. Consider the fixed-effects panel QR model:

Q_(τ | x_it, α_i) = α_i(τ) + x'_it β_i(τ)

where α_i(τ) are individual fixed effects and β_i(τ) are slope coefficients
that may differ across panels.

Step 1. For each panel i, estimate the individual QR by demeaning:

β̂_i = argmin (1/T) Σ ρ_τ(ỹ_it − x̃'_it β)

Step 2. Estimate the variance–covariance matrix of each β̂_i using the
Powell (1986) kernel density estimator for f_i(0|X):

V̂_i = τ(1−τ) Ĉ_i⁻¹ Ξ̂_i Ĉ_i⁻¹

Step 3. Compute the Minimum Distance estimator:

β̂_MD = (Σ V̂_i⁻¹)⁻¹ Σ V̂_i⁻¹ β̂_i

Step 4. The Swamy test statistic is:

Ŝ(τ) = Σ (β̂_i − β̂_MD)' (V̂_i/T)⁻¹ (β̂_i − β̂_MD)

Ŝ → χ²_{(n−1)k} as T → ∞, n fixed

Step 5. The standardized Swamy test statistic is:

D̂(τ) = √n × [(1/n)Ŝ − k] / √(2k)

D̂ → N(0,1) as (T,n) → ∞

Saved results

xtqsh saves the following in e():

Scalars

e(N) total number of observations

e(N_g) number of panels

e(k) number of covariates

e(ntau) number of quantiles

e(valid_panels) number of panels with valid estimates

e(S_ols) OLS (mean) Swamy statistic

e(D_ols) OLS (mean) standardized Swamy statistic

e(pval_S_ols) p-value of OLS Swamy test

e(pval_D_ols) p-value of OLS standardized Swamy test

Matrices

e(S) 1 × ntau vector of Ŝ(τ) statistics

e(D) 1 × ntau vector of D̂(τ) statistics

e(pval_S) 1 × ntau vector of p-values for Ŝ

e(pval_D) 1 × ntau vector of p-values for D̂

e(beta_md) ntau × k matrix of MD-QR coefficient estimates

e(beta_md_se) ntau × k matrix of SE for MD-QR estimates

e(beta_all) n × (k*ntau) matrix of individual β̂_i

e(beta_ols) n × k matrix of individual OLS β̂_i

If marginal is specified, additionally:

e(S_marginal) k × ntau matrix of marginal Ŝ statistics

e(D_marginal) k × ntau matrix of marginal D̂ statistics

e(pval_S_marginal) k × ntau matrix of marginal Ŝ p-values

e(pval_D_marginal) k × ntau matrix of marginal D̂ p-values

Macros

e(cmd) xtqsh

e(title) QR Slope Homogeneity Test (Galvao et al. 2017)

e(depvar) name of dependent variable

e(indepvars) names of independent variables

e(tau) quantile values used

e(bw) bandwidth method used

e(ivar) panel variable

e(tvar) time variable

e(cmdline) command as typed

Examples

Example 1: Simulated data under H₀ (homogeneous slopes)

. clear all

. set seed 12345

. set obs 10000

. gen id = ceil(_n/100)

. gen t = mod(_n-1, 100) + 1

. xtset id t

. gen alpha_i = id/100

. gen x1 = 0.3*alpha_i + rnormal()

. gen x2 = rnormal()

. bysort id (t): gen y = alpha_i + 1.0*x1 + 0.5*x2 + rnormal()

. xtqsh y x1 x2, tau(0.10 0.25 0.50 0.75 0.90) graph

Example 2: With marginal tests and HAC

. xtqsh y x1 x2, tau(0.05(0.05)0.95) marginal hac(3)

Example 3: Using Bofinger bandwidth

. xtqsh y x1 x2, tau(0.25 0.50 0.75) bw(bofinger) graph

Graphs

When graph is specified, xtqsh produces the following graphs:

1. xtqsh_pvalue — P-value process plot: p(Ŝ) and p(D̂) across
quantiles with horizontal significance lines at 1%, 5%, and 10%.

2. xtqsh_heatmap — Marginal p-value heatmap (if marginal
specified): color-coded matrix of D̂ p-values by variable × quantile.

3. xtqsh_fan_combined — Coefficient distribution fan chart:
percentiles (5th, 10th, 20th, 80th, 90th, 95th) of firm-specific β̂_i
across quantiles, overlaid with MD-QR and OLS estimates. This replicates
Figure 1 of Galvao et al. (2017).

4. xtqsh_mdqr_combined — MD-QR coefficient process: β̂_MD(τ) with
95% confidence interval bands.

5. xtqsh_dashboard — Summary dashboard combining key graphs.

References

Galvao, A. F., T. Juhl, G. Montes-Rojas, and J. Olmo. 2017.
Testing Slope Homogeneity in Quantile Regression Panel Data with an
Application to the Cross-Section of Stock Returns.
Journal of Financial Econometrics, 1–33.

Swamy, P. A. V. B. 1970. Efficient Inference in a Random Coefficient
Regression Model. Econometrica 38: 311–323.

Pesaran, M. H. and T. Yamagata. 2008. Testing Slope Homogeneity in Large
Panels. Journal of Econometrics 142: 50–93.

Koenker, R. and G. W. Bassett. 1978. Regression Quantiles.
Econometrica 46: 33–49.

Galvao, A. F. and L. Wang. 2015. Efficient Minimum Distance Estimator for
Quantile Regression Fixed Effects Panel Data.
Journal of Multivariate Analysis 133: 1–26.

Kato, K., A. F. Galvao, and G. Montes-Rojas. 2012. Asymptotics for Panel
Quantile Regression Models with Individual Effects.
Journal of Econometrics 170: 76–91.

Bofinger, E. 1975. Estimation of a Density Function Using Order Statistics.
Australian Journal of Statistics 17: 1–7.

Hall, P. and S. Sheather. 1988. On the Distribution of a Studentized
Quantile. Journal of the Royal Statistical Society, Series B 50: 381–391.

Author

Dr Merwan Roudane

Email: merwanroudane920@gmail.com

Please cite this package as:

Roudane, M. (2026). xtqsh: Quantile Regression Slope Homogeneity Test
for Panel Data. Stata package version 1.0.0.

When using xtqsh, please also cite the original theoretical paper:

Galvao, A. F., T. Juhl, G. Montes-Rojas, and J. Olmo (2017).
Testing Slope Homogeneity in Quantile Regression Panel Data with an
Application to the Cross-Section of Stock Returns.
Journal of Financial Econometrics, 1–33.