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   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Batch renaming variables
Date   Thu, 18 Oct 2012 15:39:11 +0100

Maarten and I really used the same method, just in part implemented it
differently.

Your problem is easy to understand, but awkward to solve without
knowing about loops and some macro manipulations.

On Thu, Oct 18, 2012 at 3:34 PM, Wameq Raza <[email protected]> wrote:
> Dear Maarten and Nick,
> Thank you very much and I'll certain discuss the problem from the
> outset! The method laid out
> by Maarten worked like a charm! I'll have to spend a little more time
> understanding the syntax
> better, but my problem for now is definitely solved.
> Many thanks once again,
> Best
> Wameq
>
> On Thu, Oct 18, 2012 at 4:28 PM, Maarten Buis <[email protected]> wrote:
>> On Thu, Oct 18, 2012 at 4:03 PM, Wameq Raza wrote:
>>> The variables I have start from v0915 and continue to v1005 and I need
>>> to rename every 5th variable in this list starting from v0917. The
>>> variables to be renamed to are: cost_a, cost_b....cost_n.
>>
>> *--------------------------- begin example --------------------------
>> // create some example data
>> clear
>> set obs 10
>> forvalues i = 915/1005 {
>>         gen v`:display %04.0f `i'' = runiform()
>> }
>>
>> // start renaming
>> local j = 0
>> forvalues i = 917(5)1005 {
>>         local j = `j' + 1
>>         mata: st_local("letter", strlower(numtobase26(strtoreal(st_local("j")))))
>>         rename v`:display %04.0f `i'' cost_`letter'
>> }
>> *---------------------------- end example ---------------------------
>>
*
*   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