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   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Macro Producing Different Results Each Time Executed
Date   Thu, 22 Aug 2013 21:57:32 +0100

Yes. The results of -sort- can vary slightly. The point is that -sort
foo- with (say) values of -foo-

1
2
2
3
3
3
4

can have several different solutions, all correct so far as the
instruction is concerned, but different so far as other variables are
concerned.  -sort, stable- should ensure the same results. See also
e.g.

http://www.stata.com/support/faqs/programming/sorting-on-categorical-variables/index.html
Nick
[email protected]


On 22 August 2013 21:21, William Sankey <[email protected]> wrote:
> Dear Statalist,
>
> 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?
>
> Thanks in advance,
>
> foreach file in col1 col2  col4 col5   {
>
> use `file' , clear
>
> sort PRVDR_NUM
> by PRVDR_NUM: gen keeper = 1 if _n==1
> keep if keeper==1
> drop keeper
>
> sort PRVDR_NUM
> save myusing3, replace
>
> use mycostreports, clear
>
> by PRVDR_NUM: generate unique=1 if _N==1 | (_N==2 &  psych_type=="Hosp")
> keep if unique==1
> drop unique
>
> sort PRVDR_NUM
> merge PRVDR_NUM using myusing3
> tab _merge
> drop if _merge==1
> drop _merge
>
> *Tables:
>
> egen paytotal = total(ProviderPayments) if REG_G==9
> egen paytotal_b = total(ProviderPay_base) if REG_G==9
> gen change53 = (paytotal-paytotal_b)/paytotal_b if REG_G==9
> drop paytotal*
>
> *Executed for other changes*
>
> sum change1 - change53
> }
>
> --
> William J. Sankey
> Johns Hopkins University
> MA Public Policy '12
> *
> *   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/
*
*   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