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: Interactive MATA and DO Files - Foreach Loops
From
Maarten Buis <[email protected]>
To
[email protected]
Subject
Re: st: Interactive MATA and DO Files - Foreach Loops
Date
Thu, 26 Jul 2012 08:33:57 +0200
The safest way to use Mata inside a Stata loop is to, outside the
Stata loop, put your Mata stuff inside a Mata function, and call that
that Mata function inside the Stata loop:
<http://www.stata.com/statalist/archive/2011-01/msg00393.html>
Hope this helps,
Maarten
On Thu, Jul 26, 2012 at 6:51 AM, Matthew McKay wrote:
> I have increasingly started to use MATA in an interactive manner within my
> Stata Do Files (mainly for easy matrix functions).
> The overall structure of my program is:
>
> local YearList = "1995 1996 1997 1998 1999 2000"
> local END = "end"
> foreach year of local YearList {
> {some STATA items}
> MATA
> {some MATA items}
> `END'
> {some STATA items}
> }
> display("OUT")
>
> To get around the parsing of the do file script issue with using "end" I
> have replaced that with a local which substitutes "end" on runtime to end
> the mata environment. This method has worked very well for me until recently
> where the foreach loop runs and everything is computed, except the program
> stops when exciting the foreach loop with the error: "program error:
> matching close brace not found".
>
> I have checked and rechecked and the brackets are balanced.
> Is there something syntactically wrong with using MATA in this way? Should I
> be using MATA functions instead?
--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany
http://www.maartenbuis.nl
--------------------------
*
* 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/