Differences between revisions 4 and 5
Revision 4 as of 2022-09-25 19:58:26
Size: 1357
Comment:
Revision 5 as of 2023-06-08 00:21:40
Size: 1426
Comment:
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:

Stata supports these '''numeric functions''' in the global scope.

Stata Numeric Functions

Stata supports these numeric functions in the global scope.


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...

  • mt64 (64-bit Mersenne Twister)

  • mt64s (stream algorithm based on the 64-bit Mersenne Twister)

  • kiss32 (32-bit keep it simple stupid)

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

Stata/NumericFunctions (last edited 2025-05-20 19:25:02 by DominicRicottone)