Shige Song wrote
> I'd like to know how to generate a macro out of a numerical
variable. For
> example, I have a variable A that includes 200 values, I want to
generate a
> macro X that contains all the values that variable A has so that I
can do
> something like:
> foreach x of local X {
> qreg ... , q(x)
> }
Check out -levels- from SSC.
Here is what the author wrote:
-levels- serves two different functions.
Occasionally, it serves to give a compact
display of the distinct values of varname.
More commonly, it may be useful when it is
desired to cycle through the distinct values of varname
with (say) foreach. -levels- leaves behind a list
in r(levels) which may be used in a subsequent command.
Note that -levels- won't work on a numeric
variable with fractional parts.
There is an older command, -vallist- (STB-60).
I recommend -levels- over -vallist-. -levels-
is considered by the author as -vallist-
done better.
Nick
[email protected]
*
* 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/