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]
Re: st: how to rename a set of variables using foreach
From
Ekaterina Hertog <[email protected]>
To
"[email protected]" <[email protected]>
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.
Ekaterina
On 05/02/2012 12:18, Nick Cox wrote:
By string commands I imagine you mean string functions (an important
difference).
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.
Nick
Ekaterina Hertog<[email protected]> 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:
*http://www.stata.com/help.cgi?search
*http://www.stata.com/support/statalist/faq
*http://www.ats.ucla.edu/stat/stata/
*
* 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/