*! version 1.0.0 14feb2019

Title

sequences -- Generates versatile numerical sequences

Syntax

sequences
newvarname
,
[ from(#)
to(#)
by(#)
]

from(#) the starting (lowest) value of the sequence. from() accepts negative and fractional values

to() the ending (highest) value of the sequence. to() is required when the data contain no observations (_N == 0), and to() must be larger than from()

by(#) the increment by which the sequence increases. by() must be a positive value. by() cannot be specified when there are observations in the current data (_N > 0)

Description

sequences is a versatile alternative to official Stata's egen seq() for generating numerical sequences. In contrast to egen seq(),
sequences can generate sequences when there are currently no observations in the data (_N == 0), and sequences accepts non-integer values for
from(), to(), and by() options, thereby generating non-integer sequences. Like egen seq(), sequences can generate
sequences which are negative, or span from negative to positive values.

Options

from(#) specifies the starting (lowest) value of the sequence. Negative and fractional values may be specified.

to(#) specifies the ending (highest) value of the sequence. Negative and fractional values may be specified but to()
must be larger than from(). to() is required when the data contain no observations (_N == 0).

by(#) specifies the increment by which the sequence increases. by() must be a positive value but can take on fractional values. by()
cannot be specified when _N > 0.

Remarks

When _N == 0 (no observations):

and from() is not specified but by() is specified, from() is set to the modulus of to() and by();

or when both from() and by() are not specified, from() and by() are set to 1;

or when from() is specified but by() is not specified, by() is set to abs((to - from) / (to - 1)).

When _N > 0 (observations exist in the data):

and from() is not specified, from() is set to 1;

or when to() is not specified, to() is set to equal _N.

Examples

1) When _N == 0 (no observations in the data)

Clear the data

. clear

Generate a sequence named "test" that ranges from -30 to 30 in increments of 0.5. We then run summarize to see the results

. sequences test, from(-30) to(30) by(0.5)

. sum test

Same as above but we do not specify by()

. clear

. sequences test, from(-30) to(30)

. sum test

Same as above but we do not specify from()

. clear

. sequences test, to(30) by(0.5)

. sum test

Same as above but we specify only to()

. clear

. sequences test, to(30)

. sum test

2) When _N > 0 (i.e. observations in the data)

Use an existing dataset

. sysuse auto, clear

Generate a sequence named "test1" that ranges from -30 to 30. We then run summarize to see the results

. sequences test1, from(-30) to(30)

. sum test1

Generate a sequence named "test2", specifying only from()

. sequences test2, from(-30)

. sum test2

Generate a sequence named "test3", specifying only to()

. sequences test3, to(30)

. sum test3

Generate a sequence named "test4", with no options specified

. sequences test4

. sum test4

Citation of sequence

sequences 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. (2019). SEQUENCES: Stata module for generating versatile numeric sequences.

Author

Ariel Linden

President, Linden Consulting Group, LLC

alinden@lindenconsulting.org

Also see

Online: egen seq()