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


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

Stas Kolenikov wrote:

what is the appropriate way of handling the following situation? I
have a do-file that uses a mix of Stata and Mata. At some point, due
to some unsurmountable (numeric) difficulties (I actually have a
rather complicated optimization problem), Mata has to break, and the
do-file needs to be exited.  . . .

[do-file omitted]

So -stata("exit")- does not work there.  . . .

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

It does for me.  See do-file and output below.
 
Joseph Coveney

===begin do-file===

*! test.do

version 11.2

set more off

local decision `0'

mata:

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

end

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

exit

==end do-file==

=== begin output ===

. do test bail

. *! test.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")
> }
> else {
>         st_local("decision", "Flying home!")
> }
Bailing out!

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

end of do-file


. do test continue

. *! test.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")
> }
> else {
>         st_local("decision", "Flying home!")
> }

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