Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

st: RE: SV: RE: rename with if

From   Nick Cox <>
To   "''" <>
Subject   st: RE: SV: RE: rename with if
Date   Fri, 21 Oct 2011 18:07:18 +0100

Indeed, that does work. I was just suggesting an alternative. 


-----Original Message-----
From: [] On Behalf Of Tomas Lind
Sent: 21 October 2011 16:31
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'


-----Ursprungligt meddelande-----
Från: [] För Nick Cox
Skickat: den 21 oktober 2011 17:24
Till: ''
Ä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 [], 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:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index