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]

From |
Nick Cox <njcoxstata@gmail.com> |

To |
"statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |

Subject |
Re: st: RE: sum of rows in stata matrix |

Date |
Mon, 7 Oct 2013 10:52:32 +0100 |

In addition, you could read that matrix into Mata, calculate row sums and then push back the result. That may sound more work than it is, as it is just one line. . matrix A = (1,2,9\2,7,5\2,4,18) . mata : st_matrix("B", rowsum(st_matrix("A"))) . mat li B B[3,1] c1 r1 12 r2 14 r3 24 Alternatively, various add-ons were published by users between 1997 and 2000. Although it's a better strategy to work in Mata, these commands will work if installed. -matfunc- includes a -matsum- command. STB-39 dm49 . . . . . . . . . . . . . . . . . . . . Some new matrix commands (help matfunc, varfunc if installed) . . . . . . . . . . . J. Weesie 9/97 pp.17--20; STB Reprints Vol 7, pp.43--48 collection of new matrix commands; several for explicit matrices and a few for implicit matrices (i.e., variables) see mata matrix language incorporated into Stata 9 STB-50 dm69 . . . . . . . . . . . . . . . . . . Further new matrix commands (help matdelrc, matewm, matmad, matpow if installed) . . . N. J. Cox 7/99 pp.5--9; STB Reprints Vol 9, pp.29--34 collection of new matrix commands providing additional matrix checking, management, element-wise operators, maximum absolute difference, and power STB-56 dm79 . . . . . . . . . . . . . . . . . . Yet more new matrix commands (help matcorr, matewmf, matvsort, svmat2 if installed) . . N. J. Cox 7/00 pp.4--8; STB Reprints Vol 10, pp.17--23 commands to produce a correlation matrix, elementwise monadic function of another matrix, selected subsets of matrix rows and columns, vec or vech of a matrix, elements sorted within a vector, matrix from a vector, and commands to save matrices see mata matrix language incorporated into Stata 9.0 Nick njcoxstata@gmail.com On 7 October 2013 05:18, Kieran McCaul <kieran.mccaul@uwa.edu.au> wrote: > matrix A = (1,2,9\2,7,5\2,4,18) > matrix list A > > * This sums across rows of A > matrix X1 = J(3,1,1) > matrix list X1 > > matrix B1 = A*X1 > > matrix list B1 > > *This sums down columns of A > matrix X2 = J(1,3,1) > matrix list X2 > > matrix B2 = X2*A > > matrix list B2 Shuaizhang Feng > Suppose I have a matrix A in stata and I want to calculate sum of rows > for each column. What would the most simple way to do it? thanks. * * 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/

**References**:**st: sum of rows in stata matrix***From:*Shuaizhang Feng <shuaizhang.feng@gmail.com>

**st: RE: sum of rows in stata matrix***From:*Kieran McCaul <kieran.mccaul@uwa.edu.au>

- Prev by Date:
**st: xtpoisson clustering** - Next by Date:
**RE: st: bootsrap random number use** - Previous by thread:
**st: RE: sum of rows in stata matrix** - Next by thread:
**Re: st: RE: sum of rows in stata matrix** - Index(es):