*! version 1.0.0 03jul2026

Title

xtfmg fe / mg / ccemg / surmg -- benchmark estimators of the
heterogeneous panel model

Syntax

xtfmg {fe|mg|ccemg|surmg}
depvar indepvars [if] [in] [, options]

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

heteroplot forest plot of unit-specific slopes (not fe)

focus(varname) regressor shown in the heterogeneity plot

notable suppress the coefficient table

saving(filename) export the table in journal format
(.tex, .rtf/.doc, .csv or .txt); see
xtfmg fccemg

title(string) caption for the exported table

replace overwrite the export file if it exists

Description

These are the comparison estimators of the framework in Guliyev (2026);
each answers a different combination of the two problems -- slope
heterogeneity and cross-sectional dependence (CSD):

xtfmg fe is the pooled within (fixed-effects) estimator with a common
slope. When the slopes genuinely differ across units it is inconsistent for
the mean slope: it converges to a weighted combination of the unit slopes in
which units with more variable regressors are over-represented (Pesaran and
Smith 1995). Reported as a cautionary benchmark.

xtfmg mg is the Mean Group estimator: a separate OLS time-series
regression for each unit, averaged across units, with the nonparametric
Pesaran-Smith variance. Consistent under slope heterogeneity but biased when
a common factor drives both the regressors and the errors, because every
unit estimate is then biased in the same direction and the bias does not
average away.

xtfmg ccemg is the Common Correlated Effects Mean Group estimator of
Pesaran (2006): each unit regression is augmented with the period-by-period
cross-sectional averages of (y, x), which asymptotically span the space of
the unobserved common factors, so the differential factor effect is filtered
out without estimating the factors. Idiosyncratic, heterogeneously-timed
breaks remain in the unit error; see xtfmg fccemg.

xtfmg surmg estimates the N unit equations jointly by feasible-GLS
seemingly unrelated regression, exploiting the contemporaneous cross-equation
error correlation for efficiency when N is small relative to T, then averages
the FGLS unit slopes. Requires a balanced panel with T > N. It does not
filter the factor; see xtfmg fsurmg for the
Fourier-augmented version.

Stored results

mg, ccemg and surmg store the same r() results as
xtfmg fccemg, without the sin/cos columns
and without r(kfreq). fe stores r(b), r(V),
r(N), r(Tbar), r(n), r(k) and the macros
r(estimator), r(depvar), r(indepvars).

Examples

. webuse grunfeld, clear

. xtset company year

. xtfmg mg invest mvalue kstock

. xtfmg ccemg invest mvalue kstock, heteroplot

. xtfmg surmg invest mvalue kstock

. xtfmg fe invest mvalue kstock

References

Pesaran, M. H. 2006. Estimation and inference in large heterogeneous
panels with a multifactor error structure. Econometrica 74: 967-1012.

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

Guliyev, H. 2026. Second-generation heterogeneous panel data model
with individual and common shocks. arXiv:2606.29063.

Author

Merwan Roudane

merwanroudane920@gmail.com

https://github.com/merwanroudane