*! version 1.0.0 23dec2025

Title

adtest -- Two-sample Anderson-Darling equality-of-distributions test

Syntax

adtest
varname [if] [in] , "by(varlist:groupvar)"
[,
reps(#)
seed(#)
power(#)]

groupvar must take on
two distinct values. The distribution of varname for the first value of
groupvar is compared with that of the second value.

* "by(varlist:groupvar)" specify a binary variable that identifies the two groups

reps(#) perform # Monte Carlo permutations; default is reps(1000)

seed(#) set random-number seed to #

power(#) specify the exponent for the AD statistic; default is power(2)

* Required

Description

adtest performs a two-sample Anderson-Darling (AD) permutation test
to assess whether two samples come from the same distribution. The AD statistic
weights discrepancies between empirical cumulative distribution functions
(ECDFs) by the inverse of their variance, making it more sensitive to differences
in the distribution tails compared to other EDF-based tests. The permutation
test provides an exact p-value by comparing the observed statistic to its distribution
under random reassignment of group labels.

Options

"by(varlist:groupvar)" is required. It specifies a binary variable
that identifies the two groups.

reps(#) specifies the number of random permutations for the test;
the default is reps(1000).

seed(#) sets the random-number seed for reproducible results.

power(#) specifies the exponent for the AD statistic calculation;
the default is power(2), which gives the standard AD statistic with quadratic weighting.
Other values modify sensitivity:
power(1) linear weighting (less sensitive to large differences),
power(3+) increased sensitivity to tail differences.

Examples

Set-up

. clear

. set obs 20

. gen group = cond(_n < 11,1,2)

. gen x = runiform() in 1/10

. replace x = runiform() * 1.30 if group==2

adtest using defaults

. adtest x, by(group)

adtest with specific seed and more permutations

. adtest x, by(group) reps(2000) seed(12345)

change power to linear weighting

. adtest x, by(group) reps(2000) seed(12345) power(1)

Stored results

adtest stores the following in r():

Scalars

r(stat) observed AD statistic

r(p) permutation p-value

r(reps) number of permutations performed

r(power) power parameter specified

Macros

r(group1) name of group 1

r(group2) name of group 2

References

Anderson, T. W., and D. A. Darling. 1952.
Asymptotic theory of certain "goodness-of-fit" criteria based on stochastic processes.
Annals of Mathematical Statistics
23: 193-212.

Pettitt, A. N. 1976.
A two-sample Anderson-Darling rank statistic.
Biometrika
63: 161-168.

Scholz, F. W., and M. A. Stephens. 1987.
K-sample Anderson-Darling tests.
Journal of the American Statistical Association
82: 918-924.

Citation of adtest

adtest is not an official Stata command. It is a free contribution
to the research community, like a paper. Please cite it as such:

Linden A. (2025). ADTEST: Stata module to perform a two-sample Anderson-Darling equality-of-distributions test

Author

Ariel Linden

President, Linden Consulting Group, LLC

alinden@lindenconsulting.org

Also see

ksmirnov, ranksum, permute, cvmtest (if installed), escftest (if installed), distcomp (if installed)