I found an issue with using the RNG and set seed with different versions of Stata. I had used version 12.1 to select a sample from a sample frame list and then tried to replicate the results after upgrading to version 15. I was getting different results and found that the problem was with how Stata uses version control with the RNG. It seems that Stata assumes that the most current version of the RNG is the best version. To understand the problem I tried a simple experiment to see how the version command might work with the set seed command.
Here is my example - NOTICE - that the results are different for Versions 11, 12, and 13 when running the foreach command versus the outside the loop.
Can someone explain the differences?
* Stata uses different pseudo-random number generators for different versions
*Version control for all random-number generators is specified at the time the set seed
clear all // Clear Stata's memory
set obs 200 // Create a dataset with 200 obs
* Set seed using version command
foreach version in 11 12 13 14 15 {
version `version': set seed `version'
generate rnva`version' = runiform()
}
* Outside of the foreach loop versions 11, 12, 13 work differently
local version 11
version `version': set seed `version'
generate rnvc`version' = runiform()
local version 12
version `version': set seed `version'
generate rnvc`version' = runiform()
local version 13
version `version': set seed `version'
generate rnvc`version' = runiform()
local version 14
version `version': set seed `version'
generate rnvc`version' = runiform()
local version 15
version `version': set seed `version'
generate rnvc`version' = runiform()
format rnv* %5.3fc
sum rnv*
list rnva* in 1/5
list rnvc* in 1/5
Related Posts with Random-Number Generator Version ##: set seed - different results
Is it possible that log mis-calculates it or create weird ".b" when the workload is too heavy?I use Stata 17 (24 cores). I am sorry that I cannot provide the reproducible example because this p…
Is it possible that log mis-calculates it or create weird ".b" when the workload is too heavy?I use Stata 17 (24 cores). I am sorry that I cannot provide the reproducible example because this p…
Determining level of significance between two median and between two catergorial variables, pre and post treatmentDear Stata community, I was wondering if anybody could help me with the following question. I am tr…
Assigning value from one variable to another if condition is metI have a data manipulation question: I have a dataset with the variables "id_1", "year", and "id_2."…
Extracting All Strings After a Word within a Variable NameI have a dataset representing a treated unit (GDP), a series of estimated counterfactuals, (cf) and …
Subscribe to:
Post Comments (Atom)
Thanks for taking the time to discuss this, I feel strongly about it as well as love understanding more about this topic. If possible, while you acquire expertise, would you mind upgrading your blog with more information? It is extremely ideal for me. see this page
ReplyDelete