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: rename with if
From
Nick Cox <[email protected]>
To
"'[email protected]'" <[email protected]>
Subject
RE: st: rename with if
Date
Fri, 21 Oct 2011 16:12:27 +0100
It should have been
if "`var'" != "idnr" rename `var' `k'_`var'
Nick
[email protected]
Tomas Lind
Using this syntax for the rename:
if `var' != "idnr" rename `var' `k'_`var'
gives me another error: type mismatch
Austin Nichols
Tomas Lind <[email protected]>:
One way:
if `var' != "idnr" rename `var' `k'_`var'
On Fri, Oct 21, 2011 at 10:55 AM, Tomas Lind <[email protected]> wrote:
> 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/