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]

st: Renames add-on to rename multiple variables


From   Katy Keenan <keenan.katy@googlemail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Renames add-on to rename multiple variables
Date   Thu, 14 Jun 2012 12:27:11 +0100

Dear Statalisters,

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?

Many thanks

Katherine Keenan
LSHTM

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