Statalist The Stata Listserver


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

RE: st: sum of rows in matrix


From   "Lucy Morecroft" <[email protected]>
To   <[email protected]>, <[email protected]>
Subject   RE: st: sum of rows in matrix
Date   Wed, 22 Feb 2006 11:44:05 +0000

Appologies I should have said that I am using Stata 8.2, and that I also
searched the help files before going to the archives.

Thank you for your help

>>> [email protected] 21/02/2006 18:16:11 >>>
Various broader issues are raised by Lucy's post. 

First, the Statalist default is to assume that 
everyone is using the latest version of Stata. 
(If not, then do say so.) On this basis, do 
check out Mata for matrix calculations. 

Second, starting from the archives is like 
deciding how to live one's life from the 
contents of problem pages. You will learn a lot, and 
most of the advice grows out
of judgement and experience, but -- here Stata is 
different from life -- a better sequence is 
to use online help, including -search- and -findit-, 
and the manual. 

In this case, 

. search matrix row sum

points again to Mata functions. 


Nick 
[email protected] 

[email protected] 
 
> . 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
 
Lucy Morecroft <[email protected]>
 
 > 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

*
*   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/


                                        

*
*   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