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 at the end of May, and its replacement, statalist.org is already up and running.


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

st: looping in MATA


From   Olga Gorbachev <olga.gorbachev@gmail.com>
To   statalist@hsphsun2.harvard.edu
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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index