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
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