Statalist


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

Re: st: no observation in while-loop


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: no observation in while-loop
Date   Fri, 19 Jun 2009 19:13:34 +0000 (GMT)

The more efficient way to loop is to use -forvalues- instead of -while-. You can avoid Stata stopping at an error message using -capture-.

However, you probably should avoid the loop and use -statsby- instead, see
-help statsby-.

Hope this helps,
Maarten

-----------------------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


--- On Fri, 19/6/09, Martin Baumgarten <[email protected]> wrote:

> From: Martin Baumgarten <[email protected]>
> Subject: st: no observation in while-loop
> To: [email protected]
> Date: Friday, 19 June, 2009, 7:51 PM
> Hello,
> 
> I have a panel with 148 countries (id) over 30 years
> (time).
> I need fitted values for one of the variables therefore I
> created this while loop
> 
> local i=1
> while `i'<=148 {
> use DataBase.dta
> keep if id==`i'
> reg machines import
> predict machfilled
> save A`i'
> local i=`i'+1
> }
> 
> However, for some countries, there is no data available and
> the loop stops. Then Stata returns "no observations". 
> 
> Is there a way to skip these countries without
> observations? So that the loop will not be interrupted.
> 
> Thank for your help
> 
> m. baumgarten
> -- 
> GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
> Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
> *
> *   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index