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
Independent variables based on same variableHi! When it comes to Stata, I am a complete rookie. I have a question on which type of method I sho…
Venn diagramHi I'm trying to do a Venn diagram with 4 variables but the code pvenn allows only 3 variables maxim…
Create graph with different colors when y<0Hello, I would like to know the code to create a graph (lines) with the y values (in this case "dif…
SubanalysisHello, I have a few questions regarding interaction terms. 1. If I have my final logistic regressi…
Randomization test and descriptive statisticsHi everyone! I am trying to replicate a balance test and descriptive statistics similar to the phot…
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