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
Phil Clayton <[email protected]>
To
[email protected]
Subject
Re: st: how to rename a set of variables using foreach
Date
Sun, 5 Feb 2012 23:09:15 +1100
One way is to use `=exp' to generate `n' - 2 on the fly:
drop inccatd1 inccatd2
foreach n of numlist 3/14 {
rename inccatd`n' inccatd`=`n'-2'
}
Phil
On 05/02/2012, at 11:04 PM, Ekaterina Hertog wrote:
> Dear all,
> 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.
> I would be grateful for advice.
> Ekaterina
>
> *
> * 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/