Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: Setting same seed, getting different random numbers.


From   "Impavido, Gregorio" <GImpavido@imf.org>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Setting same seed, getting different random numbers.
Date   Thu, 1 Dec 2011 09:33:41 -0500

INDEED. setting version control produces three identical set of obs. Here the results 
(with -version 10.1-) 


Variable	Obs	Mean	Std. Dev.	Min	Max
f101mp	1000000	-.0011306	1.000803	-5.054097	4.730645
f112mp	1000000	-.0011306	1.000803	-5.054097	4.730645
f12mp	1000000	-.0011306	1.000803	-5.054097	4.730645

Gregorio
-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
Sent: Thursday, December 01, 2011 9:24 AM
To: 'statalist@hsphsun2.harvard.edu'
Subject: RE: st: Setting same seed, getting different random numbers.

I've not been following this thread closely, but would underline what is said in -help whatsnew11- at 30mar2011

14.  rnormal(), the Gaussian random-number generation function in both
         Stata and Mata, now produces different, better values.  Prior results
         are reproduced under version control.

Who did and who did not use version control? 

Nick 
n.j.cox@durham.ac.uk 

Impavido, Gregorio

While I cannot comment on the mata code, I tested it under stata MP 10.1, 11.2 and 12 running on Windows server 2003.  These are the results:

Variable	Obs	        Mean	Std. Dev.	 Min	      Max
f101mp	1000000	-.0011306	1.000803	-5.054097	4.730645
f112mp	1000000	-.0004074	1.000851	-5.574099	4.953123
f12mp	      1000000	-.0004059	1.000854	-5.574099	4.953123

the same code appears to be producing three different sets of obs

daniel klein

Maarten,

setting the seed within Mata environment I still get -.5182349644 with
Stata 12 and .7005116833 with Stata 11.2 (both run under Windwos 7)
for f[1000000, 1].

There seems to be something going on here. I have created "f" with
Stata 11.2 and Stata 12, stored it as a variable (f11 and f12) and
merged the two datasets together. Here is the result of

. compare f11 f12

                                        ---------- difference ----------
                            count       minimum      average     maximum
------------------------------------------------------------------------
f11<f12                     69082     -6.550396     -1.13044   -4.61e-06
f11=f12                    861607
f11>f12                     69311      5.90e-07     1.126683    6.204143
                       ----------
jointly defined           1000000     -6.550396    -1.51e-06    6.204143
                       ----------
total                     1000000


I have taken a look at the differing values. The first observation
that differs is number 257982 (the dataset is not sorted). Looking at
the values it turns out that there is no pattern in the differences up
to observation 861626 (or at least I cannot spot it). Here are the ten
observations before a pattern begins

. l in 861616/861625 ,noo

  +-------------------------+
  |        f11          f12 |
  |-------------------------|
  | -.15638463   -.68684051 |
  | -.00384823    .93516482 |
  |  .33461912    1.9167679 |
  |  .35663551   -.90130858 |
  | -.01543446    -.8010808 |
  |-------------------------|
  |  1.0124802    .76208019 |
  |  .71259067    .17003043 |
  | -.25893844   -1.0935868 |
  |  -1.494143    .08098092 |
  |  1.2844026   -.38414395 |
  +-------------------------+

For the rest of the dataset it seems as if there is a clear pattern,
and it is very simple. Values in f11 appear in f12 in the following
observation. Here shown for the last ten observations.

. l in 999991/1000000 ,noo

  +-------------------------+
  |        f11          f12 |
  |-------------------------|
  |  1.0302782    .81991301 |
  | -1.7505349    1.0302782 |
  | -.36247988   -1.7505349 |
  | -.22582508   -.36247988 |
  | -.56251499   -.22582508 |
  |-------------------------|
  |  .59687397   -.56251499 |
  | -1.8742183    .59687397 |
  | -2.0173154   -1.8742183 |
  | -.51823496   -2.0173154 |
  |  .70837504   -.51823496 |
  +-------------------------+

You can inspect this pattern with

.l if (f11 == f12[_n + 1])

Here is the code I have used to create the dataset.

* run this in Stata 11.2
clear
set obs 1000000
mata :
    rseed(2)
    f = rnormal(1000000,1,0,1)
    st_store(., st_addvar("double", "f11"), f)
end
g long id = _n
save f11


* run the same code in Stata 12
clear
set obs 1000000
mata :
    rseed(2)
    f = rnormal(1000000,1,0,1)
    st_store(., st_addvar("double", "f12"), f)
end
g long id = _n
save f12

* merge the two
use f11 ,clear
merge 1:1 id using f12
drop _merge
drop id


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index