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: rename


From   "Airey, David C" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   RE: st: rename
Date   Tue, 7 Aug 2012 23:17:39 -0500

.

Nick and David kindly helped with their replies.

Thanks!



> sysuse auto
> rename (*) (<new list>)
> 
> will work.
> 
> Nick

> > Maybe you could run it through a loop where the first word of the first
> > macro gets changed to the first word of the second macro, etc.? Like
> this:
> > 
> > * Make fake dataset
> > set more off
> > clear
> > set obs 1
> > forvalues i = 1/1000 {
> > 	gen oldvar`i' = .
> > 	}
> > 
> > * Make list of new variable names
> > forvalues i = 1/1000 {
> > 	local newnames `newnames' newvar`i'
> > 	}
> > 
> > * Change all variable names
> > local j = 1
> > unab original : oldvar*
> > forvalues j = 1/1000 {
> > 	local oldname : word `j' of `original'
> > 	local newname : word `j' of `newnames'
> > 	rename `oldname' `newname'
> > 	}


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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