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]

st: exit from interactive Mata, gracefully?


From   Stas Kolenikov <skolenik@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: exit from interactive Mata, gracefully?
Date   Wed, 25 May 2011 15:17:36 -0500

Dear statalisters,

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. So I have

--- the do-file ---

* some Stata code
sysuse auto

mata
// some Mata code
st_view(x=.,.,.)

if ( missing(x) ) {
  // something tragic happened; I want to break here and exit the do-file
  stata("exit")
}
else {
  // more Mata code
  sum( x )
}
// even more Mata code
mean( x )

end
* more Stata code
summarize

exit

--- end of do-file ---

So -stata("exit")- does not work there. I can just break it with
-stata("nonsense")- to really cause an error, but my execution would
still continue to run. I cannot put -end- there, as the interpreter
will stop treating this as Mata code after it. Short of rewriting my
code to create flags and branching on them on every occasion, what
else can I do? Essentially, I am looking for something like -break-
without the cycle context. I even thought of using -goto- (God
forbid), but it cannot be used interactively to jump to a label that
is a few lines down the code, so it has not yet been read.

-- 
Stas Kolenikov, also found at http://stas.kolenikov.name
Small print: I use this email account for mailing lists only.
*
*   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