Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Renames add-on to rename multiple variables

From   Katy Keenan <>
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

*   For searches and help try:

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