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: Re: Re: exit from interactive Mata, gracefully?


From   "Joseph Coveney" <[email protected]>
To   <[email protected]>
Subject   st: Re: Re: exit from interactive Mata, gracefully?
Date   Thu, 26 May 2011 13:54:29 +0900

Stas Kolenikov replied:

. . . May be I did not explain it well. I added just one line: . . .


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

Just add couple more lines to wrap the Mata code in a dummy-function envelope,
and then you can use Mata's -exit()-, like shown below.

Joseph Coveney

===begin do-file===

*! tryit.do

version 11.2

set more off

local decision `0'

mata:

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

dummy()

end

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

exit

===end do-file===

===begin output===

. do tryit bail

. *! tryit.do
. 
. version 11.2

. 
. set more off

. 
. local decision `0'

. 
. mata:
------------------------------------------------- mata (type end to exit) -
: 
: mata clear

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

: 
: dummy()
Bailing out!

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

end of do-file


. do tryit continue

. *! tryit.do
. 
. version 11.2

. 
. set more off

. 
. local decision `0'

. 
. mata:
------------------------------------------------- mata (type end to exit) -
: 
: mata clear

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

: 
: dummy()
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

===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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index