*! version 1.0.0 12jun2026 Merwan Roudane

help xtheteroquantversion 1.0.0

Title

xtheteroquant -- Quantiles of heterogeneous individual-specific
coefficients in panel data, with SQB and CDQB bootstrap inference
(Galvao, Hounyo and Lin, 2026)

Syntax

xtheteroquant
[depvar [indepvars]]
[if] [in]
[, options]

If depvar is omitted, xtheteroquant runs as a postestimation
command after xtreg, regress, reghdfe, areg
or xtgls, reusing e(depvar), the regressors in e(b),
and e(sample). The data must be xtset.

Main
tau(numlist) quantile level(s) of the cross-sectional
coefficient distribution; default tau(.25 .5 .75)

reps(#) number of bootstrap replications; default
reps(200)

level(#) confidence level; default level(95)

seed(#) random-number seed for reproducible bootstrap
draws

noconstant suppress the unit-specific intercept in the
first-step regressions

minobs(#) minimum within-unit observations required;
default max(K+2, #)

Inference
design(string) both (default), sqb (alias
stochastic) or cdqb (alias deterministic); selects
which bootstrap tables/bands are displayed

citype(string) basic (default; centered, as in the
paper) or percentile bootstrap confidence intervals

null(#) null value for the symmetric-tail bootstrap
p-values; default null(0)

Reporting and graphs
plot quantile process plot: estimates and CI bands over a
grid of tau values (one panel per coefficient)

grid(#) number of grid points for plot; default
grid(19), i.e. tau = .05, .10, ..., .95

plotvars(namelist) subset of coefficients to plot
(use _cons for the intercept)

dist kernel-density plot of the first-step coefficient
estimates with the tau-quantiles marked

detail table of the cross-sectional distribution of the
first-step estimates (mean, sd, min, median, max, skewness)

gen1(stub) save the first-step unit-specific coefficients
as new variables stub_varname (constant for all
observations of a unit)

name(name) name for the (combined) graph

nodots suppress bootstrap replication dots

The panel must be declared with xtset before running
xtheteroquant.

Description

xtheteroquant implements the two-step estimator of Galvao, Hounyo
and Lin (2026) for the tau-quantile of the cross-sectional
distribution of heterogeneous individual-specific coefficients in the
linear panel-data model

y_it = a_i + x_it'b_i + e_it, i = 1,...,N, t = 1,...,T,

where every unit i has its own intercept a_i and its own slope
vector b_i. The procedure is:

Step 1 (individual estimation). For each unit i, estimate
the coefficient vector by OLS using only that unit's time series.

Step 2 (quantile aggregation). For each coefficient, take
the empirical tau-quantile of the N first-step estimates,
theta_hat(tau) = argmin_theta (1/N) sum_i rho_tau(theta_hat_i - theta),
where rho_tau is the quantile-regression check function.

Unlike conventional fixed-effects quantile regression (qreg /
panel QR), where tau indexes the conditional distribution of the
outcome, here tau indexes the distribution of the
structural coefficients across units: tau = .9 answers "what is
the slope for the 90th-percentile most-responsive unit?", not "what is
the effect at the 90th percentile of y?". Typical uses: heterogeneous
treatment or policy sensitivities, the distribution of mutual-fund
timing skill, firm-specific pass-through, country-specific elasticities.

With depvar alone (no regressors), the command estimates the
tau-quantile of unit long-run means (Example 2 in the paper).

The two designs and the two bootstraps

The same point estimator targets two different parameters, depending on
how the heterogeneous coefficients are viewed. xtheteroquant
always computes both bootstrap procedures and reports those requested
in design():

Stochastic design (SQB). The b_i are random draws from a
larger population, and the target is the population tau-quantile.
Convergence rate sqrt(N); valid under sqrt(N)/T = O(1). Inference uses
the Stochastic-design Quantile Bootstrap: resample time periods
within each unit, then resample units with replacement. Use this when
your N units are a sample (e.g., a sample of workers, funds, firms).

Deterministic design (CDQB). The observed N units are
the population of interest, and the target is the empirical (limiting)
tau-quantile of the realized coefficients. Convergence rate
sqrt(N*sqrt(T)); requires roughly sqrt(T) << N << T^(3/2). Inference
uses the Centered Deterministic-design Quantile Bootstrap:
resample time periods only, and re-center each bootstrap quantile at
the average bootstrap rank of the original estimate (Remark 2 in the
paper). Use this when you observe everyone (e.g., all OECD countries,
all funds in the market).

Using SQB in a deterministic design is conservative (intervals too
wide); using CDQB in a stochastic design understates uncertainty. When
in doubt about whether the units are a sample, prefer SQB.

Options

Main

tau(numlist) sets the quantile level(s) reported in the tables,
each strictly between 0 and 1. Default tau(.25 .5 .75).

reps(#) sets the number of bootstrap replications B. Default 200.
For publication-quality intervals use 999 or more.

level(#) sets the confidence level; see level.

seed(#) sets the random-number seed before drawing bootstrap
samples, making results exactly reproducible.

noconstant omits the unit-specific intercept a_i from the
first-step regressions.

minobs(#) drops units with fewer than max(K+2, #) time
periods, where K is the number of estimated coefficients. Units whose
within-unit X'X is singular are also dropped. The number of dropped
units is reported and stored in r(N_drop).

Inference

design(string) chooses which design's results to display:
both (default), sqb/stochastic, or
cdqb/deterministic. Both sets of results are always
computed and stored in r() regardless of this option.

citype(string) chooses the bootstrap confidence-interval
construction. basic (default) is the centered interval implied
by approximating the distribution of (theta_hat - theta) by the
bootstrap distribution of (theta* - theta_hat), as in the paper.
percentile reports the raw percentile interval of the bootstrap
draws.

null(#) sets the hypothesized value theta_0 used in the
symmetric-tail bootstrap p-value
p = (1/B) sum_b 1{ |theta*_b - theta_hat| >= |theta_hat - theta_0| }.
Default 0.

Reporting and graphs

plot draws the quantile process plot: for each coefficient, the
estimated tau-quantile (solid navy line) over a grid of tau values
with SQB (maroon, dashed) and/or CDQB (green, short-dashed) confidence
bands, replicating Figures 1-2 of the paper. Multiple coefficients are
arranged with graph combine.

grid(#) sets the number of equally spaced grid points used by
plot: tau_g = g/(#+1), g = 1,...,#. Default 19.

plotvars(namelist) restricts the plot to the listed coefficients;
use _cons for the intercept. At most 12 panels are drawn.

dist draws kernel densities of the first-step unit-specific
estimates, one panel per coefficient, with dashed vertical lines at the
estimated tau-quantiles from tau(). A direct visual check
of the shape, skewness, bunching or gaps of the coefficient
distribution (relevant for Assumption 7 of the paper).

detail prints a summary table (mean, sd, min, median, max,
skewness) of the first-step coefficient distribution; also stored in
r(firststats).

gen1(stub) saves the first-step unit-specific coefficient
estimates as new double variables stub_varname
(stub_cons for the intercept), repeated over each unit's
observations. Handy for second-stage cross-sectional regressions of
coefficients on unit characteristics (conditional quantile model (2.4)
in the paper).

name(name) names the process-plot graph (name) and the
density graph (name_dist). Defaults: xthq_process
and xthq_dist.

nodots suppresses the bootstrap progress dots.

Postestimation use

After fitting a pooled or fixed-effects model, calling
xtheteroquant without a varlist reuses the dependent variable,
the regressors and the estimation sample of the previous fit:

. xtreg y x1 x2, fe

. xtheteroquant, tau(.25 .5 .75) reps(200)

Note that xtheteroquant always re-estimates the model unit by
unit (heterogeneous slopes); it does not reuse the homogeneous-slope
coefficient estimates, only the variable list and the sample.
Factor-variable and time-series operators in e(b) are not
supported in this mode; supply an explicit varlist instead.
The user's e() results are left untouched.

Examples

Simulate a heterogeneous-coefficient panel

. clear all

. set seed 12345

. set obs 150

. gen long id = _n

. gen double a_i = rnormal()

. gen double b1_i = rchi2(2)/2

. gen double b2_i = rnormal(1, .5)

. expand 60

. bysort id: gen int t = _n

. xtset id t

. gen double x1 = rnormal()

. gen double x2 = rnormal()

. gen double y = a_i + b1_i*x1 + b2_i*x2 + rnormal()

Quartiles of the heterogeneous slopes, both bootstraps

. xtheteroquant y x1 x2, tau(.25 .5 .75) reps(200) seed(1)

More quantiles, percentile CIs, distribution detail

. xtheteroquant y x1 x2, tau(.1 .25 .5 .75 .9) reps(500) citype(percentile) detail

Quantile process plot and first-step densities

. xtheteroquant y x1 x2, tau(.5) reps(200) plot grid(19) dist name(demo)

Only the stochastic design, slope on x1 only in the plot

. xtheteroquant y x1 x2, tau(.5) reps(200) design(sqb) plot plotvars(x1)

As postestimation after xtreg

. xtreg y x1 x2, fe

. xtheteroquant, tau(.25 .5 .75) reps(200)

Quantile of unit long-run means (intercept-only model)

. xtheteroquant y, tau(.25 .5 .75) reps(200)

Save first-step coefficients for a second-stage cross-section

. xtheteroquant y x1 x2, reps(200) gen1(bhat)

. egen tag = tag(id)

. summarize bhat_x1 if tag

Access the full results matrix

. matrix list r(table)

Stored results

xtheteroquant stores the following in r():

Scalars

r(N) number of units used

r(N_drop) units dropped (too few obs or singular X'X)

r(T_avg) average within-unit observations

r(T_min) minimum within-unit observations

r(T_max) maximum within-unit observations

r(reps) bootstrap replications

r(level) confidence level

r(K) number of coefficients

r(null) null value used for p-values

Macros

r(cmd) xtheteroquant

r(depvar) dependent variable

r(indepvars) regressors

r(coefnames) coefficient names (regressors + _cons)

r(ivar) panel variable

r(tvar) time variable

r(citype) CI construction used

r(design) design(s) displayed

r(taulist) quantile levels reported

Matrices

r(table) long results table, one row per
(tau, coefficient): tau, estimate, SQB se/lb/ub/p, CDQB se/lb/ub/p

r(b) point estimates, K x #tau

r(se_sqb), r(lb_sqb), r(ub_sqb), r(p_sqb) SQB
standard errors, CI bounds and p-values, each K x #tau

r(se_cdqb), r(lb_cdqb), r(ub_cdqb), r(p_cdqb) CDQB
analogues

r(taus) quantile levels, 1 x #tau

r(firststats) first-step coefficient distribution summary,
K x 6

r(first) first-step unit-specific estimates, N x K
(omitted if N exceeds the maximum matrix size)

Methods and formulas

Point estimation. For each usable unit i, theta_hat_i is the OLS
coefficient vector from the regression of depvar on
indepvars (and a constant) over that unit's time series. For each
coefficient and each tau, the point estimate is the empirical
tau-quantile of the N first-step estimates,
inf (1/N) sum_i 1 >= tau, which is the
check-function minimizer of Algorithm 1 in the paper.

SQB (Algorithm 2). For b = 1,...,B: (i) within each unit, draw T_i
(y,x) pairs with replacement and recompute theta*_i; (ii) draw N units
with replacement and take the empirical tau-quantile of the selected
theta*_i, giving theta**_b. The CI is constructed from the
distribution of (theta**_b - theta_hat).

CDQB (Algorithm 3). Step (i) is identical. No unit resampling is
performed. The centering probability is
p*_tau = (1/B) sum_b (1/N) sum_i 1, and
each centered bootstrap quantile theta*_b,c is the empirical
p*_tau-quantile of i = 1,...,N. The CI is constructed
from the distribution of (theta*_b,c - theta_hat).

CIs and p-values. With citype(basic) the (1-alpha) interval
is [2*theta_hat - Q_{1-alpha/2}, 2*theta_hat - Q_], where Q_p
denotes the p-quantile of the bootstrap draws; with
citype(percentile) it is [Q_, Q_{1-alpha/2}]. Bootstrap
standard errors are the standard deviations of the draws. P-values are
symmetric-tail: p = (1/B) sum_b 1{ |draw_b - theta_hat| >=
|theta_hat - theta_0| }.

References

Galvao, A. F., U. Hounyo, and J. Lin. 2026. Estimation and inference
for the tau-quantile of heterogeneous individual-specific coefficients.
Working paper, arXiv:2605.01923.

Koenker, R., and G. Bassett. 1978. Regression quantiles.
Econometrica 46(1): 33-50.

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

Galvao, A. F., and K. Kato. 2016. Smoothed quantile regression for
panel data. Journal of Econometrics 193(1): 92-112.

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

Author

Merwan Roudane

Email: merwanroudane920@gmail.com

GitHub: github.com/merwanroudane

Please cite both the original paper (Galvao, Hounyo and Lin, 2026) and
this implementation when using xtheteroquant in published work.