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: rename with if


From   Matthew White <mwhite@poverty-action.org>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: rename with if
Date   Fri, 21 Oct 2011 11:11:36 -0400

I think:
if `var' != "idnr"    rename  `var'    `k'_`var'
should read:
if "`var'" != "idnr"    rename  `var'    `k'_`var'

On Fri, Oct 21, 2011 at 11:03 AM, Tomas Lind <Tomas.Lind@ki.se> wrote:
> Using this syntax for the rename:
>
> if `var' != "idnr"    rename  `var'    `k'_`var'
>
> gives me another error:    type mismatch
>
> /Tomas
>
>
>
> -----Ursprungligt meddelande-----
> Från: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] För Austin Nichols
> Skickat: den 21 oktober 2011 16:58
> Till: statalist@hsphsun2.harvard.edu
> Ämne: Re: st: rename with if
>
> Tomas Lind <Tomas.Lind@ki.se>:
> One way:
> if `var' != "idnr" rename  `var'    `k'_`var'
>
> On Fri, Oct 21, 2011 at 10:55 AM, Tomas Lind <Tomas.Lind@ki.se> wrote:
>> Hi Statalisters,
>>
>> I want to rename all my variables (in lots of datasets) except the first variable which is idnr. The problem with the syntax below is that "if is not allowed".
>>
>> Someone have a solution to this?
>>
>> /Tomas
>>
>>
>>
>> levelsof  atc  ,  local(cat)
>>    foreach  k  of local cat {
>>           preserve
>>           use "G:\ATC-dataset_`k'"  ,  clear
>>                 foreach  var  of varlist  _all {
>>              rename  `var'    `k'_`var'        if `var' != "idnr"
>>                          }
>>        save "G: \ATC-dataset_`k'" , replace
>>          restore
>>                 }
>>
>> *
>> *   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/
>
> *
> *   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/
>



-- 
Matthew White
Data Coordinator
Innovations for Poverty Action
101 Whitney Avenue, New Haven, CT 06510 USA
+1 434-305-9861
www.poverty-action.org

*
*   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