*! version 1.0.0 18jul2026

Title

xtlossf -- Distribution-free outlier detection via loss functions

Syntax

xtlossf basevar futurevar [if] [in] [, options]

xtlossf var [if] [in], lag [options]

Loss
q(#) loss exponent q; default q(-0.5)

mixedsign use the mixed-sign loss |F-B|(|F|+|B|)^q (Part II)

tinvariant(tvar) time-invariant loss, exponent t*q+t-1 (Part I)

signed also compute the signed loss and use two-sided bounds

lag base = L.var within panel (chronological time)

Critical value
c(#) fixed critical value C

quantile(#) C = the given quantile of the loss (0-1)

tukey(#) C = Q3 + (#)×IQR of the loss; default rule tukey(1.5)

cplus(#) upper bound for the signed loss

cminus(#) lower bound for the signed loss

Calibration / reporting
fit estimate q and C from a criteria table by regression

list(#) number of outliers to list; default list(20)

graph draw the criticality and loss figures

name(string) stub for graph names

nolabel show numeric panel codes instead of labels

Description

xtlossf detects outliers in panel data without any distributional
assumptions, following Coleman and Bryan (2025). It compares a base value
B and a future/comparison value F through a loss function and
flags observations whose loss exceeds a critical value C.

Two data types are supported. For nonnegative data (Part I) the loss is
L = |F-B|{&times}B^q; for mixed-sign data (Part II, option
mixedsign) it is L = |F-B|{&times}(|F|+|B|)^q, with the
continuity convention L(0,0)=0. The signed loss (option signed)
multiplies by the sign of F-B and uses separate upper/lower bounds so that
positive and negative outliers can be treated differently.

B and F can be two variables (two versions of an estimate, or an
estimate versus its true value - nominal time), or successive periods
of one variable (lag, chronological time). The command saves the loss
and the outlier flag as _xtlossf_L and _xtlossf_out (and
_xtlossf_S when signed).

Options

q(#) is the loss exponent. q=0 is the absolute difference;
q=-1 is the (average) absolute relative difference; intermediate values
trade the two off. The default q=-0.5 is the theoretically justified choice
when B and F are unbiased estimates whose variance is proportional to
the level (Part I).

tinvariant(tvar) incorporates elapsed time so losses at different
horizons are comparable. The time variable is rescaled so its last value is 1,
and the exponent becomes t*q+t-1 (nonnegative data only).

c(#), quantile(#), tukey(#) set the critical value C. If
none is given, the Tukey upper fence Q3 + 1.5{&times}IQR of the loss is
used. C is an empirical choice; there is no significance test, by design.

fit switches to calibration mode: supply a small table whose two
variables are the base-size midpoints and the {&epsilon} midpoints of a set
of preexisting outlier criteria; xtlossf regresses
log {&epsilon} = -q log B + K and reports the implied q and
C = exp(K) (source paper, Eq. I.19-I.20).

Method

The loss function is derived axiomatically (symmetry, monotone in the difference,
decreasing in the level); a Lie symmetry fixes the difference exponent to 1,
leaving q. An observation is an outlier whenever L > C. The boundary
L = C is a straight line in log-log space, which is what the
criticality graph plots. Full derivations:
xtoutliers methods.

Interpreting the output

o Critical value C - the loss threshold and the rule used to set
it.

o Outliers - count and share; the listing shows the largest-loss
units with their base, future, and loss values (and panel/time labels when
xtset).

o graph - (a) the criticality plot in logs with the L=C
line (points above are outliers); (b) the loss by observation with the cutoff.

Examples

Compare two census counts (nonnegative, q=-1/2):

. xtlossf pop2010 pop2020 , q(-0.5) graph

Successive periods of one series, chronological time:

. xtset id year

. xtlossf sales , lag q(-0.5) tukey(3)

Mixed-sign data with signed bounds:

. xtlossf forecast actual , mixedsign signed

Calibrate q and C from a criteria table:

. xtlossf Bmid epsmid , fit

Stored results

Scalars

r(N) number of observations used

r(nout) number of outliers

r(q) loss exponent

r(C) critical value

r(Cplus), r(Cminus) signed bounds (if signed)

r(K) intercept (in fit mode)

Macros

r(part) I (nonnegative) or II (mixed sign)

And the variables _xtlossf_L, _xtlossf_out (and
_xtlossf_S) are added to the data.

References

Coleman, C.D., and T. Bryan. 2025. Loss Functions for Detecting Outliers
in Panel Data. arXiv:2509.07014v2.

Coleman, C.D. 2025. Loss Functions for Measuring the Accuracy of
Nonnegative Cross-Sectional Predictions. arXiv:2505.18130.

Tukey, J.W. 1977. Exploratory Data Analysis. Addison-Wesley.

Author

Dr Merwan Roudane

merwanroudane920@gmail.com

github.com/merwanroudane