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


From   Olga Gorbachev <[email protected]>
To   [email protected]
Subject   st: looping in MATA
Date   Thu, 29 Apr 2010 09:51:10 -0400

Dear Statalisters,

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):
*****************************************
mata

foreach y in 1970/2000 {

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

r=rows(x`y')
vc=x`y'*x`y''
vc=vc/25
var`y'=sqrt(trace(vc)/rows(vc))
tr=vc-diag(vc)
cov`y'=sum(tr)
cov`y'=sqrt(cov`y'/(r^2-r)/2)
}

end
*************************

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

Thank you in advance, I really appreciate your help.

Olga
*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index