Size: 1738
Comment:
|
Size: 1823
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 77: | Line 77: |
== Real == ---- == String == ---- == StrOfReal == ---- |
Stata Numeric Functions
Stata supports these numeric functions in the global scope.
Contents
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.