Statalist


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

Re: st: RE : RE: Foreach and rename


From   "Eva Poen" <[email protected]>
To   [email protected]
Subject   Re: st: RE : RE: Foreach and rename
Date   Mon, 25 Aug 2008 14:02:46 +0100

Alvine,

I don't get an invalid syntax error.

clear
set obs 1
foreach i of numlist 1 2 3 5 6 9 {
gen moi0`i'008=.
}
descr
foreach i of numlist 1 2 3 5 6 9 {
rename moi0`i'008 date_modif_`i'
}
descr

If you have problems, copy the exact code and output from the result
window. It might be a typo, or a "wrong" single quote.
Eva


2008/8/25  <[email protected]>:
> Thak you for your answer , but it doesn't help me for the invalide syntax of
>
>  forvalues i=1/9 {
>  rename moi0`i'008 date_modif_`i'
>  }
>
> -----Message d'origine-----
> De : [email protected]
> [mailto:[email protected]] De la part de Martin Weiss
> Envoy� : 25 August 2008 14:40
> � : [email protected]
> Objet : st: RE: Foreach and rename
>
>
> -h foreach- shows you that you can specify a -numlist- where you spell out
> the members explicitly.
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of
> [email protected]
> Sent: Monday, August 25, 2008 2:28 PM
> To: [email protected]
> Subject: st: Foreach and rename
>
> Dear all,
>
> 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.
>
> How can I do ?
>
> Thanks
>
> Alvine
>
> *****************************************************
> Alvine BISSERY
> Ing�nieur statisticien
> Service de Biostatistique des Hospices Civils de Lyon
> 162 Avenue Lacassagne
> 69424 Lyon Cedex 03 - France
> t�l: +33 4 72 11 57 55
> fax: +33 4 72 11 51 41
>

*
*   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/



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