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]

st: RE: Renames add-on to rename multiple variables


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: Renames add-on to rename multiple variables
Date   Thu, 14 Jun 2012 13:31:30 +0100

-renames- (SSC) was written in 2000 for Stata 6 and was almost instantly superseded by -renvars- (SJ) in 2001. As always, you are asked to explain where user-written programs you refer to come from. 

If you have Stata 12.1 -- and Statalist protocol is that is assumed to be the case unless you specify otherwise -- -rename- is in any case the command of choice for renaming. 

All that said, there remains the question of why -renames- does not work. You don't tell us what variables you have, so my only guess is that the error message means what it says, that you have no variables that are -h5*-. 

-capture- here as a strategy is dubious: you might end up with a mess in which some names were changed and some weren't, which could be the worst of both worlds. 

I would have thought the better strategy would be to -append- the files, although you will need to do a lot of renaming. 

Nick 
[email protected] 

Katy Keenan

I have panel study data with 13 rounds, with many files at each round. The
variables are named inconsistently - some by numbers, some by letters. So I
am trying to rename multiple variables to have a consistent structure of
var name + round number.

This is the syntax I am using :

/* get round number from file name*/
local round=substr("`file'",7,.)

/* remove last 4 characters .dta*/

local round1=substr("`round'",1,length("`round'") -4)

/* get var name and rename all variables */

capture foreach var of varlist *  {
local varname=substr("`var'",3,.)

capture noisily renames h5* h6* h7* h8* \ "`var' `varname'`round1'"

}

************************************************************************************

When I run this I get an error saying that variable h5* not found. Can
anyone suggest how I can do this?


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