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: looping in MATA

From   "Nick Cox" <>
To   <>
Subject   st: RE: looping in MATA
Date   Thu, 29 Apr 2010 15:08:33 +0100

The key principle here is that local macro references are not part of
Mata. So, they must be interpreted before Mata sees them. Calling Mata
line by line is a little clumsy, but will work, e.g. 

mata: x`y' = st_data(., (" g`y'", " g`y+1'", " g`y+2'"," g`y+3'", "
g`y+4'"), 0)

However, you must get the local macro syntax right too. `y+1', etc.
won't work as you intend. You need `=`y'+1', etc. 


Olga Gorbachev

I am a beginner in Mata language, but I need to do something, that to
me sounds complicated:

I need to create a rolling loop in stata mata language, I am using
some simple matrix algebra and it is easier to do in Mata than in
matrix functions.

I need to do something like this (within a do file):

foreach y in 1970/2000 {

x`y' = st_data(., (" g`y'", " g`y+1'", " g`y+2'"," g`y+3'", " g`y+4'"),



Ideally I would also like to save these cov`y' and var`y' data into a

*   For searches and help try:

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