Replication seed settings from Stata

I am trying to replicate the code someone wrote to Stata in R and hit the wall trying to predict the behavior of my p-RNG.

Their code has this snippet:

set seed 123456 

Unfortunately, this is a bit of a foggy algorithm used by Stata. This question suggests that this is a KISS algorithm, but in the end failed to replicate it (and some of them seem to be dead / outdated). And the Stata guide for set seed says nothing about algorithms. This question does not seem to be complete.

Is it a crazy errand to try and reproduce random Stata numbers?

I do not know which version of Stata was used to create this.

+7
random r code-translation stata
source share
1 answer

In short: yes, this is an insane assignment.

Stata, being proprietary software, has not released all the details of its core components, such as a random number generator. However, documentation is available (link for Stata 14), most appropriate:

runiform() is the basis for all other random number functions, since all other random numbers, numerical functions transform uniform (0, 1) random numbers into a given distribution.

runiform() implements the 64-bit version of Mersenne Twister (MT64) and "keeps it simple stupid" of 32-bit (KISS32) algorithms for creating uniform (0, 1) random numbers. runiform() uses the MT64 default algorithm .

runiform() uses the KISS32 algorithm only when the user version is less than 14 , or when the random number generator is set to kiss32 ...

Recall also from ?Random in R, which is for Mersenne twister:

"A seed is a 624-dimensional set of 32-bit integers plus the current position in that set.

Stata internally controls the 624-dimensional set, which is almost impossible to guess.

I suggest you export these random numbers from Stata and read them into a vector / matrix / etc. in R using

 library(haven) mydata <- read_dta("mydata.dta") 
+8
source share

All Articles