Bookmark and Share

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   Wameq Raza <[email protected]>
To   [email protected]
Subject   Re: st: Batch renaming variables
Date   Thu, 18 Oct 2012 15:53:38 +0200

Hi David,
Thanks for the reply. I'll give this a shot now, though I'm not sure I
understand the syntax correctly. I'll let you know how it goes!
Best
Wameq

On Thu, Oct 18, 2012 at 3:50 PM, David Kantor <[email protected]> wrote:
> 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/



-- 
W A M E Q   R A Z A
*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index