Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Random-Number Generator Version ##: set seed - different results

    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

  • #2
    in version 14, the default generator was changed; see
    Code:
    help whatsnew13to14
    there may have been other changes also - you can check by looking at various files under "previous updates" in "help whatsnew"

    Comment


    • #3
      As Rich points out, your problem arises from changes made to Stata's random number generator in Stata 14. This is described in the output of
      Code:
      help rng
      which suggests you can revert the random number generator to the previous version with
      Code:
      set rng kiss32
      prior to your
      Code:
      set seed
      Or, you can run your do-file under version control using
      Code:
      version 13
      unless of course you are running the do-file to test changes that include Stata features introduced in a later version.

      Comment

      Working...
      X