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

From   Stas Kolenikov <>
Subject   st: Re: exit from interactive Mata, gracefully?
Date   Wed, 25 May 2011 23:29:27 -0500

On Wed, May 25, 2011 at 10:35 PM, Joseph Coveney <> 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

May be I did not explain it well. I added just one line:

== do-file ==
*! by Joseph Coveney

version 11.2

set more off

local decision `0'


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


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

== end of do-file ==

You are "still there" no matter what the `decision' is. And I wanted
to exit before that once and for all.

Stas Kolenikov, also found at
Small print: I use this email account for mailing lists only.

*   For searches and help try:

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