Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fwd: st: Looping to rename


From   Rebecca Pope <rebecca.a.pope@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Fwd: st: Looping to rename
Date   Tue, 6 Nov 2012 13:56:29 -0600

There might be better ways, but this should work:

local varlist p1 p3 p7 ...
local i 1
foreach var of local varlist {
   rename `var' p`i'
   local i = `i' + 1
}


Rebecca



---------- Forwarded message ----------
From: Zhangqunzi <zhangqunzi@googlemail.com>
Date: Tue, Nov 6, 2012 at 1:44 PM
Subject: st: Looping to rename
To: Stats <statalist@hsphsun2.harvard.edu>


Dear all,

I want to rename my var list: p1,p3,p7..,
Into new one :p1,p2,p3...

Currently I am running such loop:
Local i
For var of varlist
Rename var pi

But stata tells me error: can't find macro i ... How should I solve
this problem?

I can't use renvars due to memory problem.
Thanks in advance



*
*   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index