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]

Re: st: Macro Producing Different Results Each Time Executed


From   Phil Schumm <[email protected]>
To   <[email protected]>
Subject   Re: st: Macro Producing Different Results Each Time Executed
Date   Thu, 22 Aug 2013 15:57:46 -0500

On Aug 22, 2013, at 3:21 PM, William Sankey <[email protected]> wrote:
> The following 'foreach' statement produces different results each time it executes. My suspicion is that the sort does not necessarily happen in the same order each time the program runs, hence what is dropped and what is kept in the merge becomes different each time.
> 
> Can the sort execute differently each time it is run, do you have other thoughts on why I might be obtaining different results each time this function is executed?


That's likely the best guess, looking at your code.  Remember, -sort- is (by default) not stable, and one of the reasons for this is exactly so that problems like this are discoverable.  In the future, whenever you are doing something that is dependent on the sort order of the data, use

    isid <varlist>, sort

instead of -sort- to ensure that the order of the dataset is uniquely determined.


-- Phil


*
*   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