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: Renaming variables
From
Richard Moverare <[email protected]>
To
statalist <[email protected]>
Subject
Re: st: Renaming variables
Date
Mon, 13 Jan 2014 12:41:00 +0100
My mistake was with the double quotes, such a stupid mistake. Thank
you so much for your quick reply, Nick!
All the best, Rick
2014/1/13 Nick Cox <[email protected]>:
> <>
>
> From the pattern evident here
>
> foreach v of var VAR* {
> local insert : di %02.0f 14 + real(substr("`v'", 4, 2))
> local suffix = substr("`v'", 6, .)
> rename `v' VAR`insert'`suffix'
> }
>
> -renvars- (SJ) would allow a one-line solution, but it would look
> quite like the above and be no faster.
>
> Nick
> [email protected]
>
> On 13 January 2014 11:14, Richard Moverare <[email protected]>
>
>> I have a minor problem renaming some variables. I am sure there is
>> some simple solution, but at the moment I can't find it. I have a
>> dataset with variables named as follows:
>>
>> VAR02_1
>> VAR02_2
>> VAR02_3
>> VAR03
>> VAR04c
>> VAR05_1
>> VAR05_2
>> and so on
>>
>> The structure is VARXX and then sometimes a few more characters. I
>> would like to change these numbers, i.e. XX, by increasing their value
>> with, say 12. The characters following XX should not be changed. So
>> that, in my example, I get:
>>
>> VAR14_1
>> VAR14_2
>> VAR14_3
>> VAR15
>> VAR16c
>> VAR17_1
>> VAR17_2
>> and so on
> *
> * 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/
*
* 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/