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: Batch renaming variables
From
David Kantor <[email protected]>
To
[email protected]
Subject
Re: st: Batch renaming variables
Date
Thu, 18 Oct 2012 09:50:07 -0400
At 09:36 AM 10/18/2012, Wameq Raza wrote:
Hi everyone,
I'm having some trouble trying to figure out how to do batch renames.
To elaborate, suppose I have 10 variables: v1, v2....v10 and I want to
rename every second var (ie v2, v4, v6, v8 and v10) to cost_a,
cost_b....cost_e. Can anyone please help me figure this out? I've
tried looking into renvars, but can't seem to figure it out.
If there are only five renames, I would just write them out.
But if you want a programmatic solution (as maybe there are really
many more renames)...
(untested)
local suffixes "a b c d e"
forvalues jj = 1/5 {
ren v`=`jj'*2' cost_`=word("`suffixes'", `jj')'
}
----
Another way of getting the suffixes (a, b, c,...) is to use
char(96+ `jj')
but you need to be careful not to exceed jj=26.
But that's true in any case.
HTH
--David
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/