Differences between revisions 1 and 6 (spanning 5 versions)
Revision 1 as of 2022-03-16 15:40:42
Size: 1202
Comment:
Revision 6 as of 2023-06-13 21:03:44
Size: 1738
Comment:
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
Stata supports these '''numeric functions''' in the global scope.
Line 4: Line 6:

----



== Dhms ==

See also `Cdhms`.

----



== Dmy ==

----



== Hms ==

See also `Chms`.

----



== Mdy ==

----



== Mdyhms ==

See also `Cmdyhms`.

----



== Y ==

----



== Yh ==

----



== Ym ==

----



== Yq ==

----



== Yw ==
Line 15: Line 83:
Below is a demonstration for how an [[SurveySamples#Sampling_Methods|SRS sample]] can be drawn.
Line 18: Line 88:
sort r_sampled
generate byte sampled = _n <= 100
Line 20: Line 92:
The return value is a [[Stata/Types|double]]; it will be within `a + c(epsdouble)` and `b − c(epsdouble)`. The return value is a [[Stata/DataTypes|double]]; it will be within `a + c(epsdouble)` and `b − c(epsdouble)`.

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

  • 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)