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 at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: Re: Re: exit from interactive Mata, gracefully?


From   "Joseph Coveney" <jcoveney@bigplanet.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Re: Re: exit from interactive Mata, gracefully?
Date   Fri, 27 May 2011 18:13:41 +0900

Stas Kolenikov wrote:

So I still need a wrapper. I see. Thanks.

--------------------------------------------------------------------------------

Well, not really. If you change the argument for Mata's -exit()- function to 1,
then it will be exactly the same as pressing the BREAK key on your keyboard to 
manually terminate the optimization.  If you're willing to accept the resulting
"--Break--" message and corresponding return code as graceful enough, then you 
could go that route.  

It has the advantage of conditionally skipping the both the Mata and Stata code
that follow it without messing up anything else.  

Leaving in the -stata("exit")- line avoids seeing the break message twice.

Joseph Coveney

===begin do-file===

*! tryit.do

version 11.2

set more off

local decision `0'

mata:

if (st_local("decision") == "bail") {
    printf("Bailing out!\n")
    stata("exit = 0")
    exit(1)
}
else {
    st_local("decision", "Flying home!")
}
printf("Still there...\n")

end

display in smcl as text "`decision'"
display in smcl as text "do-file terminated normally"

exit

===end do-file===

===begin output===

. do tryit continue

. *! tryit.do
. 
. version 11.2

. 
. set more off

. 
. local decision `0'

. 
. mata:
------------------------------------------------- mata (type end to exit) -
: 
: if (st_local("decision") == "bail") {
>     printf("Bailing out!\n")
>     stata("exit = 0")
>     exit(1)
> }
> else {
>     st_local("decision", "Flying home!")
> }

: printf("Still there...\n")
Still there...

: 
: end
---------------------------------------------------------------------------

. 
. display in smcl as text "`decision'"
Flying home!

. display in smcl as text "do-file terminated normally"
do-file terminated normally

. 
. exit

end of do-file


. do tryit bail

. *! tryit.do
. 
. version 11.2

. 
. set more off

. 
. local decision `0'

. 
. mata:
------------------------------------------------- mata (type end to exit) -
: 
: if (st_local("decision") == "bail") {
>     printf("Bailing out!\n")
>     stata("exit = 0")
>     exit(1)
> }
> else {
>     st_local("decision", "Flying home!")
> }
Bailing out!
(2 lines skipped)
---------------------------------------------------------------------------

end of do-file

--Break--
r(1);

===end output===


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