In Stata 9, this is done by -levelsof-.
In Stata 8, this is done by -levels-.
In Stata 7, this is done by -vallist- from SSC.
See also the FAQ
FAQ . . . . . . . . . . Making foreach go through all values of a variable
4/03 Is there a way to tell Stata to try all values of a
particular variable in a foreach statement without
specifying them?
http://www.stata.com/support/faqs/data/foreach.html
Incidentally, if your values were contained
in a local called uniqlist, you use its name, as follows:
foreach uniqval of local uniqlist {
<execute code>
}
Nick
[email protected]
Stephen R. Hale, Ph.D.
> I'm new to the list. Can anyone direct me to an efficient,
> preferrably
> already existing way to get the unique values of a
> categorical variable into
> a macro. The goal is just like creating a "by", but I need
> to have the
> unique values list. Let's say I can get the unique values in
> the macro
> uniqlist.
>
> I then want to be able to loop over all unique values in the list
>
> Foreach uniqval of local `uniqlist' {
> execute code
> }
*
* 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/