Bookmark and Share

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: Interactive MATA and DO Files - Foreach Loops


From   Matthew McKay <[email protected]>
To   [email protected]
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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index