Thanks Kit.
I had to make one additional small change to get it to run:
v2=invtokens(v[cols(v)..1])
I changed to:
v2=mm_invtokens(v[cols(v)..1])
I thank you very much for the lesson, it works nicely.
I appreciate the help, and more, the chance to learn a new trick, from both
you and Maarten.
Thanks again very much.
Buzz
Buzz Burhans, Ph.D.
Dairy-Tech Group
Twin Falls, ID
Phone: 208-320-0829
Fax: 208-735-1289
Email: [email protected]
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Kit Baum
Sent: Tuesday, July 17, 2007 5:58 AM
To: [email protected]
Subject: st: Re: reverse variable order
To somewhat simplfy Maarten's code (without the check for x following
a strict pattern, which in fact is not required in this approach),
see below
On Jul 17, 2007, at 2:33 AM, Maarten wrote:
> *---------- begin example --------------
> sysuse auto, clear
> forvalues i = 1/10 {
> gen x`i' = uniform()
> }
>
> unab vars : x*
// this places the list of x* variables in macro vars
. mata
: v=tokens(st_local("vars"))
: v2=invtokens(v[cols(v)..1])
: st_local("revvars",v2)
:
: v2
x10 x9 x8 x7 x6 x5 x4 x3 x2 x1
: end
------------------------------------------------------------------------
--------
. di "`revvars'"
x10 x9 x8 x7 x6 x5 x4 x3 x2 x1
// Back in Stata, the local macro revvars now contains the reversed
list of x variables. No need to loop. -order- can be applied to this
list (prepended with the list of non-x variables, extracted as
Maarten illustrates).
Kit
*
* 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/
*
* 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/