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

st: Re: Problem with foreach


From   "Steichen" <[email protected]>
To   <[email protected]>
Subject   st: Re: Problem with foreach
Date   Thu, 29 Jul 2004 16:38:58 -0400

It fails because you are trying to -generate- variable -id- 3 times... and
you can only do that once.  -drop id-  before closing the -foreach- loop if
it needs to be different for each country.

Tom

----- Original Message ----- 
From: <[email protected]>
To: <[email protected]>
Sent: Thursday, July 29, 2004 4:30 PM
Subject: st: Problem with foreach


>
>
>
> Dear stata users,
>
> I have a problem.
>
> 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.
>
> local country "Benin Togo France"
> foreach i of local country {
>  use `i'.dta
>  di "I use `i'"
>  d
> }
>
> here it works for each country ( I have all the description).
>
> 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.
>
> . I use Benin
>  output omitted
> . I use Togo
> . I use France
>
> What is happening?
> Do I omit something?
>
> Best regards.
>
> Amadou.
>
> *
> *   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/
>

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