Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | daniel klein <klein.daniel.81@googlemail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: Setting same seed, getting different random numbers. |
Date | Thu, 1 Dec 2011 11:46:44 +0100 |
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 Best Daniel * * 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/