Stata Numeric Functions

Stata supports these numeric functions in the global scope.


Dhms

See also Cdhms.


Dmy


Hms

See also Chms.


Mdy


Mdyhms

See also Cmdyhms.


Y


Yh


Ym


Yq


Yw


Random Number Functions

Runiform

runiform(a,b) returns a random number between a and b. If no parameters are specified, the defaults of 0 and 1 are used.

Below is a demonstration for how an SRS sample can be drawn.

set seed 123456
generate double r_sampled = runiform()
sort r_sampled
generate byte sampled = _n <= 100 

The return value is a double; it will be within a + c(epsdouble) and b − c(epsdouble).

By default, runiform uses the 64-bit Mersenne Twister algorithm. Alternate algorithms are available; see set rng.

Set Rng

To use an alternate random number generation algorithm, set the rng value to something other than default.

set rng default

Possible values include...

In Stata 14, the default flipped from kiss32 to mt64.

Set Seed

To make random number generation reproducible, set a seed value.

set seed 42

A seed value must be an integer, non-negative, and no greater than 231 − 1.


CategoryRicottone