Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: sum of rows in matrix


From   [email protected]
To   [email protected]
Subject   Re: st: sum of rows in matrix
Date   Tue, 21 Feb 2006 06:19:36 -0600

. matrix A=(1,2,3,4,5\6,7,8,9,10)

. matrix C = J(5,1,1)

. matrix B = A*C

. matrix list B

B[2,1]
    c1
r1  15
r2  40


Hope this helps,
Scott


----- Original Message -----
From: Lucy Morecroft <[email protected]>
Date: Tuesday, February 21, 2006 5:36 am
Subject: st: sum of rows in matrix

> Hi Statalist,
> 
> Appologies if this is a very basic question, but a lengthy search of
> the archives didn't answer my query.
> 
> How can I create a vector, where each element is the sum of each 
> row in
> a matrix A?
> 
> e.g. let,
> 
> mat A=(1,2,3,4,5\6,7,8,9,10)
> 
> mat list A
> 
> A[2,5]
>    c1  c2  c3  c4  c5
> r1   1   2   3   4   5
> r2   6   7   8   9  10
> 
> I would like to create B where:
> 
> B[2,1]
>    c1
> r1  15
> r2  40
> 
> Thanks in advance,
> 
> Lucy
> 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index