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

st: Re: Problem with foreach


From   Friedrich Huebler <[email protected]>
To   [email protected]
Subject   st: Re: Problem with foreach
Date   Thu, 29 Jul 2004 14:02:25 -0700 (PDT)

Amadou,

Add the option -clear- to the -use- command. If you want to
understand how -foreach- works you can run the lines inside the {}
braces one at a time. Type -use Benin.dta, clear-, -di "I use Benin"-
and so on, when the command contains the macro `i'.

local country "Benin Togo France"
foreach i of local country {
 use `i'.dta, clear
 di "I use `i'"
 g id = _n
 codebook id
}

Friedrich Huebler

--- [email protected] wrote:
> I have a list of countries. I put them in a macro.
> When I run the loop, it works fine if I only ask for
> basic tasks such as describe or su.
> But when I try to do a bit more complicated tasks,
> nothing appeared. It proceeds only for the first country.
> And the remaining is blank.
>
> [...]
> 
> But when I code:
> local country "Benin Togo France"
> foreach i of local country {
>  use `i'.dta
>  di "I use `i'"
>  g id = _n
>  codebook id
> }
> 
> It works only for the first country: Benin.



		
__________________________________
Do you Yahoo!?
Take Yahoo! Mail with you! Get it on your mobile phone.
http://mobile.yahoo.com/maildemo 
*
*   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