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 on April 23, and its replacement, is already up and running.

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

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

From   Nick Cox <>
Subject   Re: st: how to rename a set of variables using foreach
Date   Sun, 5 Feb 2012 12:18:31 +0000

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:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index