Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: RE: foreach to renumber vars
From
"B. Timothy Walsh" <[email protected]>
To
[email protected]
Subject
Re: st: RE: foreach to renumber vars
Date
Tue, 07 Sep 2010 12:56:07 -0400
Terrific. I much appreciate the prompt assistance!
--On Tuesday, September 07, 2010 5:43 PM +0100 Nick Cox
<[email protected]> wrote:
-forval- is better:
forval i = 2/100 {
local j = `i' - 2
rename x`i' y`j'
}
Or
forval i = 2/100 {
rename x`i' y`=`i'-2'
}
A -foreach- solution could be
foreach i of numlist 2/100 {
<same innards>
}
But it has no advantages over -forval-.
See also -renvars- from the SJ.
Nick
[email protected]
B. Timothy Walsh
I would like to rename/renumber variables of the format x2 - x100 to y0 -
y98. In other words, I'd like to subtract 2 from the "subscript".
I'm afraid I am still not skilled enough to figure out how to do this
with foreach and a macro.
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
=======================
B. Timothy Walsh, M.D.
NYSPI Unit 98
1051 Riverside Drive
New York, NY 10032
TEL: 212-543-5752
FAX: 212-543-6606
---------------------------------------------------------------------------
NOTE TO RECIPIENT: this e-mail is meant for only the intended recipient of
the transmission, and may be a communication privileged by law. If you
receive his e-mail in error, any review, use, dissemination, distribution,
or copying of this e-mail is strictly prohibited. Please notify us
immediately of the error by return e-mail and please delete this message
from your system. Thank you.
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/