[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Foreach and rename

From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Foreach and rename
Date   Tue, 26 Aug 2008 13:05:32 +0100

This question generated several suggestions. 

Here is another: 

foreach v of var moi0?008 { 
	local i = substr("`v'", 5, 5) 
	rename `v' date_modif_`i' 

Or using -renvars- (-search- for location) 

renvars moi0?008, map("date_modif_" + substr("@",5,5)) 

I don't like it much but it's another way to do it. 

[email protected] 

[email protected]

I'd like to change the name of many variables in this way:

 rename moi01008 date_modif_1
 rename moi02008 date_modif_2
 rename moi03008 date_modif_3
 rename moi05008 date_modif_5
 rename moi06008 date_modif_6
 rename moi09008 date_modif_9

I'd like to use a loop, like 

  forvalues i=1/9 {
 rename moi0`i'008 date_modif_`i'

But it doesn't work : "invalid syntax"

Even if this loop works, I have a problem with the value i=4,7 and 8 for
which moi0`i' does not exist.

*   For searches and help try:

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