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

RE : st: Re: Problem with foreach


From   <[email protected]>
To   <[email protected]>
Subject   RE : st: Re: Problem with foreach
Date   Thu, 29 Jul 2004 16:53:33 -0400

Amadou,

You need to add the clear option:

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

Beno�t

-----Message d'origine-----
De : [email protected] [mailto:[email protected]] De la part de [email protected]
Envoy� : 29 juillet, 2004 16:44
� : [email protected]
Objet : Re: st: Re: Problem with foreach





Thanks,
I put a "cap drop id" before issuing the generate command.
And I still got the same problem.
Besides, when stata exits the loop, doesn't it automatically
drop the id variable and leaves the dataset unchanged?
Maybe I have no clue on how foreach proceeds exactely.
Best regards.
Amadou.



                                                                                                                                           
                      "Steichen"                                                                                                           
                      <[email protected]>          To:       <[email protected]>                                          
                      Sent by:                         cc:                                                                                 
                      owner-statalist@hsphsun2.        Subject:  st: Re: Problem with foreach                                              
                      harvard.edu                                                                                                          
                                                                                                                                           
                                                                                                                                           
                      07/29/2004 04:38 PM                                                                                                  
                      Please respond to                                                                                                    
                      statalist                                                                                                            
                                                                                                                                           
                                                                                                                                           
                                                                                                                                           
                                                                                                                                           




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/




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