## Stata 15 help for ksmirnov

```
[R] ksmirnov -- Kolmogorov-Smirnov equality-of-distributions test

Syntax

One-sample Kolmogorov-Smirnov test

ksmirnov varname = exp [if] [in]

Two-sample Kolmogorov-Smirnov test

ksmirnov varname [if] [in] , by(groupvar) [exact]

In the first syntax, varname is the variable whose distribution is being
tested, and exp must evaluate to the corresponding (theoretical)
cumulative.  In the second syntax, 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.

Statistics > Nonparametric analysis > Tests of hypotheses >
Kolmogorov-Smirnov test

Description

ksmirnov performs one- and two-sample Kolmogorov-Smirnov tests of the
equality of distributions.  A one-sample test compares the distribution
of the tested variable with the specified distribution.  A two-sample
test tests the equality of the distributions of two samples.

When testing for normality, please see [R] sktest and [R] swilk.

Options

+------+
----+ Main +-------------------------------------------------------------

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

exact specifies that the exact p-value be computed.

Examples

Setup
. webuse ksxmpl
. summarize x

One-sample test
. ksmirnov x = normal((x-r(mean))/r(sd))

Two-sample test
. ksmirnov x, by(group)

Two-sample test, exact value
. ksmirnov x, by(group) exact

Stored results

ksmirnov stores the following in r():

Scalars
r(D_1)         D from line 1
r(p_1)         p-value from line 1
r(D_2)         D from line 2
r(p_2)         p-value from line 2
r(D)           combined D
r(p)           combined p-value
r(p_exact)     exact combined p-value

Macros
r(group1)      name of group from line 1
r(group2)      name of group from line 2

```