> -----Original Message-----
> From: Arthur Mu [mailto:[email protected]]
> Sent: Wednesday, July 10, 2002 12:06 PM
> To: [email protected]
> Subject: st: macro loop embedded in macro loop (Jun Xu)
>
> [snip]
>
> The problem here is: first I
> tokenize compare
> before the first while loop, and within the while loop I have another
> tokenize and the second while loop, which will overwrite the
> info stored by
> the first tokenize of `compare'. To restore the order of the
> tokenized
> `compare', I tokenize compare again and use local i=`i'+2 and
> macro shift
> `i' to get away with it. I am not sure if I correctly explained my
> question, which is "is there an easy way around it?
> Otherwise if I need to
> have several tokenize and while loop's, then I will have to
> restore them
> each time as I did?"
Tokenize is only one way to work your way through lists; you are
probably best off not using tokenize for both lists. The macro extended
functions -word count- and -word x of- let you step through a list of
words (such as a varlist) without tokenizing it:
tokenize `compare', parse(";")
while `"`1'"'!="" {
<do things with `compare'>
local n_var : word count `varlist'
forval i=1/`nvar' {
local cur_var : word `i' of `varlist'
<do things with `cur_var'>
}
macro shift
}
Nick Winter
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/