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, statalist.org is already up and running.


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

Re: st: RE: SV: RE: rename with if


From   K C Wong <kcwong5@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: SV: RE: rename with if
Date   Mon, 24 Oct 2011 18:47:18 +0800

it's always great to know the alternatives. Thx~


On Sat, Oct 22, 2011 at 1:07 AM, Nick Cox <n.j.cox@durham.ac.uk> wrote:
> Indeed, that does work. I was just suggesting an alternative.
>
> Nick
> n.j.cox@durham.ac.uk
>
> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Tomas Lind
> Sent: 21 October 2011 16:31
> To: statalist@hsphsun2.harvard.edu
> Subject: st: SV: RE: rename with if
>
> For the moment it works when using K C Wongs suggestion but modified with "`var'" as you suggested.
>
> if "`var'" != "idnr" {
> rename  `var'    `k'_`var'
>
> /Tomas
>
>
> -----Ursprungligt meddelande-----
> Från: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] För Nick Cox
> Skickat: den 21 oktober 2011 17:24
> Till: 'statalist@hsphsun2.harvard.edu'
> Ämne: st: RE: rename with if
>
> Looking at the question again, the core is
>
> foreach var of varlist _all {
>        if "`var'" != "idnr" rename `var' `k'_`var'
> }
>
> Picking up an idea from Fernando Rios Avila [f.rios.a@gmail.com], and adding another, this might as well be
>
> rename (*) (`k'_*)
> rename `k'_idnr idnr
>
> bearing in mind that in Stata 12 -- which you are presumed to use unless you flag otherwise -- -rename- has a bunch of new features that allow renaming of multiple variables.
>
>
> *
> *   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/


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