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: exit from interactive Mata, gracefully?
From
Stas Kolenikov <[email protected]>
To
[email protected]
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/