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]

Re: st: how to rename a set of variables using foreach

From   Ekaterina Hertog <>
To   "" <>
Subject   Re: st: how to rename a set of variables using foreach
Date   Mon, 06 Feb 2012 22:32:59 +0000

Dear Nick and Phil, thank you very much for the advice.
I use Stata 12.1 and Nick's solution worked perfectly.
I also managed to tweak Phil's solution so it works by renaming inccat1 and inccat2 manually before doing the transformation.

On 05/02/2012 12:18, Nick Cox wrote:
By string commands I imagine you mean string functions (an important

Statalist protocol is that you are assumed to be using Stata 12.1
unless you specify otherwise.
That being so, -help rename- is in principle the place to start.

But the main problem here is that when you start renaming  -inccatd1-
is already a name in use and every renaming command known to me
(including -renvars-, SJ) will fail without an extra trick. This
should work

renpfix inccat fooinccat
renvars fooinccat1-fooinccat14 \ inccat3-inccat12

and there will be a -rename- alternative in Stata 12.1 except that at
this minute I can't test it.


Ekaterina Hertog<>  wrote:
I have a dataset with several dummy variables for income categories named:

inccatd1 inccatd2 inccatd3 inccatd4 inccatd5 etc till inccatd14

and I'd like to go 2 steps down in the numbers of income categories: i.e. I
want inccatd3 to become inccatd1 etc.
  and I cannot quite figure out whether I can do it with foreach or not and
all the advice I found so far is on using string commands.
*   For searches and help try:

*   For searches and help try:

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