[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Re: reverse variable order

From   "Buzz Burhans" <>
To   <>
Subject   st: RE: Re: reverse variable order
Date   Tue, 17 Jul 2007 16:50:08 -0600

Thanks Kit.  

I had to make one additional small change to get it to run:


I changed to:


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 Burhans, Ph.D.

Dairy-Tech Group
Twin Falls, ID
Phone: 208-320-0829
Fax: 208-735-1289 

-----Original Message-----
[] On Behalf Of Kit Baum
Sent: Tuesday, July 17, 2007 5:58 AM
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).

*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index