Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Renvars and simultaneous renaming of several variables


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Renvars and simultaneous renaming of several variables
Date   Sun, 25 Jan 2004 18:35:28 -0000

This example raises a point that Jeroen 
Weesie and I discussed when last talking 
about -renvars- at dinner in the Maastricht 
meeting: how far -renvars- has lost much of its original 
rationale now that we have -foreach-? Indeed, 
from one point of view it was half out-of-date 
even as it was published. 

Given this problem, 
I would probably just fire up -foreach-
and crunch through the cases: 

foreach v of var *y98 *y99 *y00 *y01 { 
	local when = substr("`v'",-2,2) 
	if "`when'" == "98" | "`when'" == "99" { 
		local new : subinstr local v "`when'" "19`when'" 	
	} 
	else local new : subinstr local v "`when'" "20`when'" 
	rename `v' `new' 
} 

but that depends on knowing the very general tools 
used above. Alternatively, revisiting the idiosyncratic 
syntax of -renvars- I find one solution to be 

renvars *y98, sub(y98 y1998) 
renvars *y99, sub(y99 y1999)
renvars *y00, sub(y00 y2000)
renvars *y01, sub(y01 y2001) 

which does look a bit more transparent from at 
least one point of view. 
 
Nick 
[email protected] 

Herve STOLOWY
 
> I found the renvars elements by downloading the STB-60.
> 
> I can now formulate my question.
> 
> I have 200 variables named in the following way:
> 
> vary98
> vary99
> vary00
> vary01
> 
> Could I rename all the variables with one instruction to obtain:
> 
> vary1998
> vary1999
> vary2000
> vary2001.
> 
> If not, should I distinguish the 1990s and the 2000s?

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index