## Stata 15 help for nlist

```
[P] numlist -- Parse numeric lists

Syntax

numlist "numlist" [, ascending descending integer missingokay min(#)
max(#) range(operator# [operator#]) sort]

where numlist consists of one or more numlist_elements

and where operator is < | <= | > | >=

There is no space between operator and #; for example,

range(>=0)
range(>=0 <=20)
range(>0 <=50)

Description

The numlist command expands the numeric list supplied as a string
argument and performs error checking based on the options specified.  Any
numeric sequence operators in the numlist string are evaluated, and the
expanded list of numbers is returned in r(numlist).  See numlist for a
discussion of numeric lists.  Also see [P] syntax for a more
comprehensive command that will also parse numeric lists.

Options

ascending indicates that the user must give the numeric list in ascending
order without repeated values.  This is different from the sort
option.

descending indicates that the numeric list must be given in descending
order without repeated values.

integer specifies that the user may only give integer values in the
numeric list.

missingokay indicates that missing values are allowed in the numeric
list.  By default, missing values are not allowed.

min(#) specifies the minimum number of elements allowed in the numeric
list.  The default is min(1).  If you want to allow empty numeric
lists, specify min(0).

max(#) specifies the maximum number of elements allowed in the numeric
list.  The default is max(1600), which is the largest allowed
maximum.

range(operator# [operator#]) specifies the acceptable range for the
values in the numeric list.  The operators are < (less than), <=
(less than or equal to), > (greater than), and >= (greater than or
equal to). No space is allowed between the operator and the #.

sort specifies that the returned numeric list be sorted.  This is
different from the ascending option, which places the responsibility
for providing a sorted list on the user who will not be allowed to
enter a nonsorted list.  sort, on the other hand, puts no restriction
on the user and takes care of sorting the list.  Repeated values are
also allowed with sort.

Examples

. numlist "5.3 1.0234 3 6:18 -2.0033 5.3/7.3"
. display "`r(numlist)'"

. numlist "5.3 1.0234 3 6:18 -2.0033 5.3/7.3", integer
(gives error message)

. numlist "1 5 8/12 15", integer descending
(gives error message)

. numlist "1 5 8/12 15", integer ascending
. display "`r(numlist)'"

. numlist "100 1 5 8/12 15", integer ascending
(gives error message)

. numlist "100 1 5 8/12 15", integer sort
. display "`r(numlist)'"

. numlist "3 5 . 28 -3(2)5"
(gives error message)

. numlist "3 5 . 28 -3(2)5", missingokay min(3) max(25)
. display "`r(numlist)'"

. numlist "28 36", min(3) max(6)
(gives error message)

. numlist "28 36 -3 5 2.8 7 32 -8", min(3) max(6)
(gives error message)

. numlist "3/6 -4 -1 to 5", range(>=1)
(gives error message)

. numlist "3/6", range(>=0 <30)
. display "`r(numlist)'"

Stored results

numlist stores the following in r():

Macros
r(numlist)    expanded numeric list

```