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, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Interactive MATA and DO Files - Foreach Loops


From   Matthew McKay <matthew.mckay@anu.edu.au>
To   statalist@hsphsun2.harvard.edu
Subject   st: Interactive MATA and DO Files - Foreach Loops
Date   Thu, 26 Jul 2012 14:51:11 +1000

Dear StataList,

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?

Cheers,
Matt


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