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]
Re: st: Using mata in semi-do-file / semi-interactive mode
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: Using mata in semi-do-file / semi-interactive mode
Date
Mon, 19 Mar 2012 15:43:50 +0000
What you describe sounds one good way of developing accurate code. I
often work similarly. I guess most people do. The main variable is the
frequency of mistakes.
However,
1. It's not inevitable that running a do-file clears Mata. If this
happens to you, you must
be asking for it to happen, perhaps as a side-effect of something else.
2. If there is a mistake in your Mata, what you would want to happen
instead? That Mata forges ahead regardless? Usually that would get you
nowhere useful. If a mistake is not fatal, then you need to make that
so by catching it with specific code; Mata can't usually do that on
your behalf.
I only use -printf()- for special effects. For rough-edged debugging
it is usually enough just to exploit the fact that typing a name of
some matrix (vector, scalar) is an instruction to print it.
Nick
On Mon, Mar 19, 2012 at 3:20 PM, Bert Lloyd <[email protected]> wrote:
> The way I usually build do-files in Stata is to go back and forth
> between writing in the do-file and issuing interactive commands -- you
> write a bit of code in a do-file, run it to see if it works, fiddle
> around in interactive mode to check that your code did what you wanted
> it to do and to understand mistakes, go back to correct the do-file,
> etc. This may not be the best way to work but it's what I'm used to.
>
> I am finding it difficult to work the same way in Mata, since when the
> do-file ends, the contents of Mata appear to be cleared. Similarly, if
> there's a mistake in the Mata code, the program seems to stop without
> making partial progress, or at least any partial progress that has
> been made seems to be cleared. (Please correct me if I'm wrong here.)
>
> The best way I've come up with is to make only tiny incremental
> changes to the Mata program, then run repeatedly with lots of "printf"
> commands and the like to display what is happening. This is somewhat
> slow and cumbersome. Is there a better way? How do others work with
> Mata?
>
*
* 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/