Differences between revisions 5 and 7 (spanning 2 versions)
Revision 5 as of 2023-06-08 00:21:40
Size: 1426
Comment:
Revision 7 as of 2023-06-13 21:08:03
Size: 1823
Comment:
Deletions are marked like this. Additions are marked like this.
Line 6: Line 6:

----



== Dhms ==

See also `Cdhms`.

----



== Dmy ==

----



== Hms ==

See also `Chms`.

----



== Mdy ==

----



== Mdyhms ==

See also `Cmdyhms`.

----



== Y ==

----



== Yh ==

----



== Ym ==

----



== Yq ==

----



== Yw ==

----



== Real ==

----



== String ==

----



== StrOfReal ==

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


Real


String


StrOfReal


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)