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


From   William Sankey <[email protected]>
To   [email protected]
Subject   st: Macro Producing Different Results Each Time Executed
Date   Thu, 22 Aug 2013 16:21:43 -0400

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/


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