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   William Buchanan <[email protected]>
To   [email protected]
Subject   Re: st: Macro Producing Different Results Each Time Executed
Date   Thu, 22 Aug 2013 15:37:33 -0500

One potential issue is the error in your merge command (which should produce an error).  If you're not using the most recent version of Stata you should also acknowledge that in your query.

HTH,
Billy


On Aug 22, 2013, at 3:21 PM, 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