Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: continue loop if file not found


From   daniel klein <klein.daniel.81@googlemail.com>
To   statalist@hsphsun2.harvard.edu
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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index