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]
st: SV: RE: rename with if
From
Tomas Lind <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: SV: RE: rename with if
Date
Fri, 21 Oct 2011 15:31:21 +0000
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: [email protected] [mailto:[email protected]] För Nick Cox
Skickat: den 21 oktober 2011 17:24
Till: '[email protected]'
Ä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 [[email protected]], 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.
Nick
[email protected]
Tomas Lind
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/