foreach loop in reverse order

701 views
Skip to first unread message

J

unread,
Nov 24, 2010, 1:20:44 PM11/24/10
to Stata Users Forum
I would like to do a foreach loop in reverse order. I have my elements
to loop over in a local macro, but I can't find a way to reorder
elements of the macro or tell the for loop to start at the end and go
to the beginning. There is a sort function for macros, but it only
will reorder the elements in alphabetical order.

Joseph

Eric A. Booth

unread,
Nov 24, 2010, 5:45:06 PM11/24/10
to J, Stata Users Forum

Try doing it from within a loop:

**************!
sysuse auto, clear
ds
di "`r(varlist)'"

foreach v in `r(varlist)' {
local reverse `v' `reverse'
}

di "`r(varlist)'"
di "`reverse'"
**************!


- Eric
__
ebo...@ppri.tamu.edu
eric.a...@gmail.com

> --
> You received this message because you are subscribed to the Google Groups "Stata Users Forum" group.
> To post to this group, send email to stata-us...@googlegroups.com.
> To unsubscribe from this group, send email to stata-users-fo...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/stata-users-forum?hl=en.
>

Reply all
Reply to author
Forward
0 new messages