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: Make ado file end processing of calling do file


From   Phil Schumm <pschumm@uchicago.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Make ado file end processing of calling do file
Date   Mon, 23 May 2011 20:08:40 -0500

On May 23, 2011, at 7:02 PM, Paul Burkander wrote:
I'm new to writing ado files, and I'm having some trouble. I'd really like my ado file to stop the processing of the calling do file if certain conditions are met. I guess "exit" just returns control to the calling program.

Is there any way to make the calling program completely top based on a condition encountered in the ado file?


There are several ways to do what you want. For example, you could have your program exit with a specific return code, and then trap this in your do-file:


program define foo
    <program code ...>
    if <condition> {
        exit = <return code>
    }
end


cap foo
if _rc == <return code> {
    exit
}


Alternatively, you could have your program set a global macro, and then check for specific values of this macro in your do-file following your call to the program. Though there are other ways, these are perhaps the best two.

The real question, however, is what are you trying to do? I'm guessing that there might be an alternative (and perhaps better) way to approach the problem...


-- Phil

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