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]

st: Re: exit from interactive Mata, gracefully?


From   "Joseph Coveney" <jcoveney@bigplanet.com>
To   <statalist@hsphsun2.harvard.edu>
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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index