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

// some Mata code

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

* more Stata code


--- 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
Small print: I use this email account for mailing lists only.
*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index