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]

RE: st: rename


From   "Airey, David C" <david.airey@vanderbilt.edu>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index