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]

Re: st: how to summarize a big matrix


From   Matthew Baker <[email protected]>
To   [email protected]
Subject   Re: st: how to summarize a big matrix
Date   Tue, 9 Apr 2013 08:49:03 -0400

Wu --

The mata function sum() adds up everything in an arbitrary matrix, I
believe, so you might get your matrix into mata and compute the sum
that way, and then return the result as a scalar to stata. For
example:

mat Z=1,2,3 \ 4,5,6 \7,8,9
mata:
Z=st_matrix("Z")
sum=sum(Z)
st_numscalar("sum",sum)
end
display sum

For even very large matrices, the mata "sum" function is quite fast, I
have found.

Hope that helps!

Matt Baker


On Mon, Apr 8, 2013 at 4:40 PM, Wu Zhang <[email protected]> wrote:
> Hi there,
>
>    I am required to investigate the elements of a big matrix(1000X1000); what I am trying to do now is to VEC the matrix and change it into a variable, then use "sum" in stata. But that is very slow.
>
>   I am just wondering whether there is an easier way to summarize the matrix directly? By the way, the matrix is symmetric.
>
> Thank you very much!
>
> Wu
>
>
> *
> *   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/



-- 
Dr. Matthew J. Baker
Department of Economics
Hunter College and the Graduate Center, CUNY
*
*   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/


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