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: append and post commands: code equivalence
From 
 
"Sami Souabni" <[email protected]> 
To 
 
<[email protected]> 
Subject 
 
st: append and post commands: code equivalence 
Date 
 
Tue, 3 Jul 2012 21:30:25 +0100 
Having come across the same error repeatedly while running the snippet below
                forval i = 1/`numq' {
                                local q = quan[1,`i']
                                local numpred = numdraw[1,`i'] 
                                use x`1'b`2'`q'.dta, clear
                                bsample `numpred', cluster(pid)
                                drop pid
                                if `i'==1 {
                                                quietly save x`1'b`2',
replace
                                }
                                else {
                                                append using x`1'b`2'
                                                quietly save x`1'b`2',
replace
                                }
                } 
which ends in "file x`1'b`2' could not be found", I created the code below
as a work-around. Using it in my application has resulted in different
results, implying that the code above and below are not equivalent.
Therefore, could anyone tell me if the code snippet above is equivalent to
this code snippet:
                tempname 3 
                postfile `3' x`1'b`2' using tmp/x`1'b`2', replace
                forval i = 1/`numq' {
                                local q = quan[1,`i'] 
                                local numpred = numdraw[1,`i']
                                use tmp/x`1'b`2'`q', clear
                                bsample `numpred', cluster(pid)
                                drop pid
                                local N=_N
                                forval o = 1/`N' {
                                                quietly {
                                                preserve
                                                keep if _n==`o'
                                                local x`1'b`2' = x`1'b`2'
                                                post `3' (`x`1'b`2'')
                                                restore
                                                }
                                di "`q'th percentile of x`1'b`2' sampled"
                                }
                } 
                postclose `3'
If it is not equivalent, how could the first snippet more accurately emulate
the second?
Thanks for any suggestions!
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/