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: Filling mata results in a matrix
From
"Sobott, Jonas" <[email protected]>
To
[email protected]
Subject
st: Filling mata results in a matrix
Date
Mon, 7 Oct 2013 15:18:34 +0200
Dear Statalist,
I have a problem with filling results from a mata function into matrix.
I want to loop over 6 regions and 10 sectors, perform for each a mata
function (see above) and store the result in a matrix. To do so, I
created to scalars from the loop variables (row_mata and column_mata) to
tell mata where to put the results.
However, all I get is the sub_matriy(): 3301 subscript invalid,
<istmt>: - function returned error
clear all
mata
V = J(6,10,.)
end
forvalues j = 1/6 {
forvalues i=1/10{
clear
use master2
scalar columns_mata = `i'
scalar row_mata = `j'
quietly: drop if missing(sector_num)
quietly: keep if sector_num == `i'
quietly: xtset entity_num date, daily delta(7)
quietly: keep entity_num sector_num date newtrades
quietly: reshape wide newtrades, i(entity_num) j(date)
quietly: xpose, clear
quietly: drop if v1 + v2 == 2* `i'
quietly: recode _all (missing =0)
quietly: corr _all
quietly: matrix X = r(C)
mata sub_matriy()
}
}
with
mata
void sub_matriy()
{
D = st_matrix("X")
r = st_numscalar("row_mata")
o = st_numscalar("columns_mata")
V[r,o] = mean(select(vech(D), vech(D) :< 1))
}
mata mosave sub_matriy(), replace
end
Thank you very much!
Best regards
Jonas Sobott
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/