Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: append and post commands: code equivalence


From   "Sami Souabni" <S.A.SOUABNI.506831@swansea.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index