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
Out of sample prediction using a two way fixed effectDear members, When using a two way fixed effect model, "i.year" is added in the command which estim…
SAS to STATAI'm hoping someone can help me recreate the following SAS code in STATA. if first.studyid_adult the…
invalid numlist has missing values Error in forestplotHi, Recently, when I use metan or admetan on aggregated data, there is always an error with the fore…
Control number of bins in binscatterI generate a binscatter using Code: sysuse auto, clear binscatter price mpg, nq(100) rd(30) line(no…
Generating time series of (quarter) date variables for the period between two date variables: beginning and end of ownershipHi, I would much appreciate your assistance with the below question. Please, I have data set that …
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