Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: continuing a loop from after it encounters an error


From   Nick Mosely <mosely@uw.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: continuing a loop from after it encounters an error
Date   Thu, 3 Feb 2011 10:41:38 -0800

Hello _all,

I've built a loop that encounters an error periodically due to the
fact that stata can't find one of the objects specified in the list. I
don't mind the error, but I would like stata to skip objects in list
that encounter the error and continue to the next iteration of the
loop, rather than breaking the loop. I've tried the continue command,
but am not sure that is what it's meant for.

Here is a simplified version of the code. In this example, assume that
objects1 and object3 are valid commands but object2 is not:

foreach i in object1 object2 object3 {
display `i'
continue
}
>object1
>unrecognized command:  object2
>r(199);

What can I do get the code to continue running through object3?

Thanks,
`Nick Mosely'
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index