*! version 1.0.0 26jun2026 Dr Merwan Roudane

Title

xtlongestim -- Long-run and mean-coefficient estimators with small-T
bias correction for dynamic heterogeneous panels

Syntax

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

The data must be xtset. The fitted model is the dynamic heterogeneous panel

y(it) = a(i) + lambda(i) y(i,t-1) + beta(i)'x(it) + e(it)

and the long-run coefficient of interest is theta(i) = beta(i)/(1 - lambda(i)).
The lag of depvar is added automatically; indepvars are the contemporaneous regressors.

Model
lr(varlist) regressors for which to report the long-run coefficient; default is all indepvars

noconstant suppress the group-specific intercept

Methods
methods(list) estimators to compute; default mg dbc1 dbc2 bsbc

Bootstrap (bias terms, NBC, DBC, BSBC, bias-corrected MG)
reps(#) bootstrap replications; default 400

seed(#) random-number seed; default 12345

parametric parametric (Gaussian) bootstrap; default is residual resampling

Hierarchical Bayes (Gibbs sampler)
burnin(#) burn-in iterations; default 1000

draws(#) retained posterior draws; default 2000

rho(#) Wishart prior degrees-of-freedom scaling; default 2

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

nodots suppress the bootstrap / Gibbs progress dots

Visualisation
graph produce publication-quality forest plots and a cross-panel heterogeneity caterpillar

gname(stub) name stem for the stored graphs (default xtle)

export(name) write a journal-style results table to name.tex (LaTeX booktabs) and/or name.csv

Description

xtlongestim unifies, in a single command, the estimators of the long-run and
mean short-run coefficients of dynamic heterogeneous panels developed in
Pesaran and Zhao (1999) and
Hsiao, Pesaran and Tahmiscioglu (1999).

The mean group (MG) estimator of the long-run coefficient is consistent but, as both
papers show, can carry substantial bias when the time dimension T is small,
because of (a) the small-T bias of the short-run least-squares estimates of
lambda(i) and beta(i), and (b) the nonlinearity of beta/(1-lambda).
xtlongestim implements the bias-reduction and Bayes shrinkage procedures
proposed to deal with this, several of which had not previously been available in Stata.

Estimators

The estimators fall into two groups according to what they target and which output
table they fill. Choose them in methods().

LONG-RUN estimators target theta=beta/(1-lambda); fill the long-run table/forest only

mg nbc dbc1 dbc2 bsbc

SHORT-RUN estimators target the mean lambda and beta; fill the mean short-run table/forest (and report an implied long-run)

pols mg bcmg ebayes hbayes

So, to see short-run results (the speed-of-adjustment lambda and the impact beta) you
must request a short-run estimator - e.g. methods(mg bcmg). The pure
long-run bias-corrections (nbc, dbc1, dbc2, bsbc) have no
short-run component by construction, so on their own they print only the long-run table.
The mean group (mg) belongs to both groups: it is the only estimator that
fills the long-run and the short-run tables at once. The shortcut methods(all)
runs everything; methods(longrun) and methods(shortrun) pick one group.

Long-run coefficient theta = beta/(1-lambda):

mg Mean group: average of the per-group ratios
beta(i)/(1-lambda(i)). Variance by the Pesaran-Smith formula.

nbc Naive bias-corrected: plug bias-corrected short-run coefficients
into the ratio, then average (Pesaran & Zhao, Section 3.1). Included as a benchmark;
the paper shows it generally over-corrects.

dbc1 Direct bias-corrected, formula (10) - retains the higher-order
O(T^-3/2) term in the denominator. Best overall performer in the paper.

dbc2 Direct bias-corrected, formula (15).

bsbc Bootstrap bias-corrected mean group, formula (20):
2*MG - mean bootstrap MG.

Mean short-run coefficients (lambda, beta):

pols Pooled OLS (homogeneous-slope benchmark; biased under heterogeneity).

mg Mean group average of the per-group OLS coefficients.

bcmg Bias-corrected mean group: average of the bootstrap bias-corrected
per-group coefficients.

ebayes Empirical Bayes / Swamy estimator, formula (7), with the
heterogeneity covariance estimated by the method of moments, formula (8).

hbayes Hierarchical Bayes via Gibbs sampling, using the full conditional
distributions of Hsiao, Pesaran and Tahmiscioglu (1999, p.275) with a diffuse prior on
the mean coefficient and a Wishart prior on the precision matrix.

Implied long-run coefficients are also reported for bcmg, ebayes,
hbayes and pols. The short-run-only methods (pols mg bcmg ebayes hbayes)
populate the mean short-run table; the long-run-only methods (nbc dbc1 dbc2 bsbc)
populate the long-run table.

The short-run bias terms B(lambda) and B(beta) that feed nbc, dbc1,
dbc2 and bcmg are estimated by a per-group bootstrap rather than the
closed-form Kiviet-Phillips (1993) approximation used in the original papers. The
bootstrap is exact to simulation error and applies to any number of regressors; the
analytical O(T^-1) approximation is a special case.

Options

Model

lr(varlist) lists the regressors for which the long-run coefficient is
reported. They must be a subset of indepvars. The default reports them all.

noconstant fits the model without a group-specific intercept.

Methods

methods(list) chooses which estimators to compute, as a space-separated
list of the keywords above. Three shortcuts are recognized: all (every method),
longrun (mg nbc dbc1 dbc2 bsbc) and shortrun
(pols mg bcmg ebayes hbayes). The default is mg dbc1 dbc2 bsbc (long-run
focus). Remember that a mean short-run table is shown only if a short-run estimator
(pols, mg, bcmg, ebayes, hbayes) is included; the pure
long-run bias-corrections (nbc, dbc1, dbc2, bsbc) print only the
long-run results. The first listed method that has a long-run row is posted in
e(b)/e(V).

Bootstrap

reps(#) sets the number of bootstrap replications used for the bias terms
and for bsbc (minimum 20).

seed(#) sets the seed for reproducibility.

parametric draws errors from N(0, sigma2(i)) instead of resampling the
(centered) within-group residuals.

Hierarchical Bayes

burnin(#), draws(#) and rho(#) control the Gibbs sampler:
the number of discarded initial iterations, the number of retained draws, and the
Wishart prior scaling (the prior scale matrix is set to the Swamy estimate of the
heterogeneity covariance).

Reporting

level(#) and nodots control the confidence level and the progress
display.

Visualisation

graph draws, for every long-run variable, a forest plot comparing all
requested estimators (point estimate with confidence interval; markers coloured and shaped
by estimator family: uncorrected, bias-corrected, Bayes, pooled), a matching forest plot of
the mean short-run coefficients, and a cross-panel heterogeneity caterpillar of the
per-group long-run estimates theta(i) sorted with their confidence intervals and the
mean-group line. One clean figure is produced per variable.

gname(stub) sets the name stem of the stored graphs. With stem s the graphs
are s_lr[#] (long-run forest), s_sr[#] (short-run forest) and
s_het[#] (heterogeneity), one per variable. Export any of them with
graph export myfig.png, name(s_lr) replace.

export(name) writes the long-run results as a ready-to-include table. If name
ends in .tex a LaTeX booktabs table is written (coefficients with significance
stars, standard errors in parentheses); if it ends in .csv a comma-separated table is
written; otherwise both name.tex and name.csv are produced.

Note on batch mode: when Stata runs headless (-b/-e) the graphs are built with
the graphics device off (so the run never aborts) and stored in memory; run interactively, or
graph export them afterwards, to view.

Stored results

xtlongestim stores the following in e():

Scalars

e(N) number of observations

e(N_g) number of groups

e(g_min) , e(g_avg), e(g_max)}obs per group

e(reps) bootstrap replications

e(level) confidence level

Macros

e(cmd) xtlongestim

e(primary) method posted in e(b)

e(methods) methods computed

e(lrvars) long-run regressors

e(depvar) , e(ivar), e(tvar)}variables

Matrices

e(b), e(V) long-run estimates of the primary method

e(LR_b), e(LR_se) all long-run point estimates / std. errors (rows = methods)

e(SR_b), e(SR_se) all mean short-run estimates / std. errors

e(theta_i), e(theta_i_se) per-group long-run estimates / std. errors (used by the heterogeneity plot)

e(coef_i), e(coef_i_se) per-group short-run coefficients / std. errors

e(panel_ids) panel identifiers, one per group

Examples

Long-run bias-correction suite (the Pesaran-Zhao methods):

. webuse grunfeld, clear

. xtset company year

. xtlongestim invest mvalue kstock

Everything, including the Bayes estimators, with the long-run reported only for mvalue:

. xtlongestim invest mvalue kstock, methods(all) lr(mvalue) reps(500)

Short-run comparison only, parametric bootstrap:

. xtlongestim invest mvalue kstock, methods(shortrun) parametric

References

Pesaran, M. H., and Z. Zhao. 1999. Bias reduction in estimating long-run relationships
from dynamic heterogeneous panels. In Analysis of Panels and Limited Dependent
Variable Models, ed. C. Hsiao, K. Lahiri, L.-F. Lee, and M. H. Pesaran, 297-322.
Cambridge: Cambridge University Press.

Hsiao, C., M. H. Pesaran, and A. K. Tahmiscioglu. 1999. Bayes estimation of short-run
coefficients in dynamic panel data models. In Analysis of Panels and Limited
Dependent Variable Models, ed. C. Hsiao, K. Lahiri, L.-F. Lee, and M. H. Pesaran,
268-296. Cambridge: Cambridge University Press.

Kiviet, J. F., and G. D. A. Phillips. 1993. Alternative bias approximations with a
lagged-dependent variable. Econometric Theory 9: 62-80.

Pesaran, M. H., and R. Smith. 1995. Estimating long-run relationships from dynamic
heterogeneous panels. Journal of Econometrics 68: 79-113.

Swamy, P. A. V. B. 1971. Statistical Inference in Random Coefficient Regression
Models. Berlin: Springer.

Author

Dr Merwan Roudane

merwanroudane920@gmail.com

github.com/merwanroudane