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, statalist.org is already up and running.

# Re: st: how to summarize a big matrix

 From Matthew Baker To statalist@hsphsun2.harvard.edu 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 <wuzhang50@yahoo.com> 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/