I am writing an ado program that one macro loop embedded in another one. I
have figured a way around it, but kind of awkward, not sure if there is an
easy way to do it.
I just extracted part of the Program that I am having problems with:
*******************************************************
capture program drop mycommand
program define mycommand
syntax [varlist] ,model(string) compare(string)
tokenize `compare', parse(" ; ")
local i=1
while "`1'"~=""{
...Do whatever I want for the macro's in `compare'
...
...
tokenize `varlist'
while "`1'"~=""{
...Do whatever I want for the macro's in `varlist'
}
tokenize `compare', parse (" ; ")
local i=`i'+2
macro shift `i'
}
end
****************************************************
What I am trying to do with `varlist' within the while loop is to capture
individual variable information and store it into a matrix. While the
`compare' macro list is to run through each pair within "compare (1 2; 4 2;
3 2)", in which "1 2" encodes two equations by a group variable like female
vs. male or white vs. black. 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?"
Jun Xu
Doctoral Student
Department of Sociology
Indiana University