Statalist


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

st: AW: Fwd: Combining -forvalues- and -foreach-


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: AW: Fwd: Combining -forvalues- and -foreach-
Date   Fri, 31 Jul 2009 21:40:03 -0400

<>


Although you declared yourself satisfied with your own response, you may
want to note that -destring- happily takes a -varlist- which would allow you
to employ wildcards as seen in -help varlist-, and that pretty much renders
your loops redundant...

So try -destring p16_200?, replace-

HTH
Martin

-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Leonor Saravia
Gesendet: Freitag, 31. Juli 2009 16:08
An: statalist@hsphsun2.harvard.edu
Betreff: st: Fwd: Combining -forvalues- and -foreach-

I have found my error. Now it it works:

forvalues i = 1/6 {
foreach v of var p16_200`i' {
	destring `v', replace
 }
}

Thank you!

Leonor Saravia

---------- Forwarded message ----------
From: Leonor Saravia <lmisaravia@gmail.com>
Date: 2009/7/31
Subject: Combining -forvalues- and -foreach-
To: statalist@hsphsun2.harvard.edu


Dear Statalisters,

I have a list of string (with numeric meaningful numeric text)
variables: p1_2000 p1_ 2001 p1_2003 p1_2004 p1_2005 p1_2006

I was trying to -destring- them using the next code, but it is not working:

    forvalues i = 0/6 {
    foreach v of p1_200`i' {
    destring `v', replace
        }
     }
Please, could you tell me if it is posible to do this loop combining
the -forvalues- and the -foreach- commands, and if it is not posible,
would you give an idea of a "good" way to do it.
Thank you in advance,
Leonor

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



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