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: Renames add-on to rename multiple variables
From
Katy Keenan <[email protected]>
To
[email protected]
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/