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]

Re: st: continue loop if file not found


From   daniel klein <[email protected]>
To   [email protected]
Subject   Re: st: continue loop if file not found
Date   Sat, 7 May 2011 11:34:06 +0200

If there is still the same problem, and I assume there is, although
this is not entirely clear from your post, get rid of the -break-
option. The -break- option causes Stata to break out of the loop,
while -continue- without -break- continues with the next element in a
loop. It does not continue with the next lines.

See this example (from the help file).

       forvalues x = 1/10 {
                if mod(`x',2) {
                        display "`x' is odd"
                        continue
                }
                display "`x' is even"
        }

will loop 10 times. It will display numers 1 to 10 and inform you if
they are odd or even. I guess this is what you are looking for.

Compare the above loop with a modified version:

       forvalues x = 1/10 {
                if mod(`x',2) {
                        display "`x' is odd"
                        continue ,break
                }
                display "`x' is even"
        }

This will not loop. Since 1 is an odd number, the loop will display "1
is odd", then exit.

In your case, the do-file exits the first time a file is not found.

also see -help continue-

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