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: Macro Producing Different Results Each Time Executed


From   Joe Canner <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: RE: Macro Producing Different Results Each Time Executed
Date   Thu, 22 Aug 2013 20:54:07 +0000

William,

I'm not able to follow all of your code, but one place to start is to use -sort, stable- or else to sort on additional variables.  If you have multiple observations with the same PRVDR_NUM, each time you sort, the observations that have the same PRVDR_NUM can be in a different (random) order.  See -help sort- for a more detailed explanation.

Regards,
Joe Canner
Johns Hopkins University School of Medicine

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of William Sankey
Sent: Thursday, August 22, 2013 4:22 PM
To: [email protected]
Subject: st: Macro Producing Different Results Each Time Executed

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