Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: Re: Mata order() indeterminate


From   "Joseph Coveney" <[email protected]>
To   <[email protected]>
Subject   st: Re: Mata order() indeterminate
Date   Sun, 3 Nov 2013 13:08:21 +0900

Brendan Halpin wrote:

I'm checking a simulation in Mata, and find that setting the seed to the
same value does not yield the same results on repeated runs. I've
tracked it down to the use of -order()- to sort a matrix, where there
are many ties. It appears that -order()- brings in indeterminacy in
dealing with ties, but from somewher other thanq the random-number system.

This snippet illustrates the issue:

mata:
x = range(1,10,1)
y = runiform(10,1):>0.5

for (i=1; i<=20; i++) {
  rseed(12345)
  x, x[order(y,1),]
}
end

Though x is unchanged, and the seed is set to the same value at each
pass, x[order(y,1)] changes. 

While this is disturbing, I presume it is consistent with Stata policy
with regard to sorting indeterminacy. 

How do I get repeatable sorting in this context?

--------------------------------------------------------------------------------

This sounds analogous to wanting to set the seed for the pseudorandom number
generator used in -sort , stable- for a Stata dataset.  I don't know whether
that generator is also used--or even whether any such mechanism is used--in
Mata's -order()-.

Perhaps an alternative would be to explicitly create an auxiliary column or row
containing a random sequence from -runiform()- just for the purpose, and then
sorting the matrix on that.

But, based upon experience with data modeling for relational database design, I
find myself taking sides with StataCorp on this.  If it were me, I would suspect
that the indeterminacy I see is symptomatic of a conceptual bug in my simulation
code.  When you fix that bug, you will have fixed your problem with
irreproducibility on repeated runs from the same seed.

Joseph Coveney

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


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index