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 |
Radaf paf <ladwen@hotmail.com> |

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

Subject |
st: Matrices utilities, Basic calculations. When to start using Mata over Stata? |

Date |
Fri, 23 Apr 2010 11:50:20 +0000 |

Hi all, I have a total of 20 matrices, A1-A10 and B1-B10 of size 25x36 I am trying to do the sum of each row of the matrix A and compare them with the sum of each row of the matrix B. Then I retain the highest sum and put it in a new matrix, say C. The "rowsum" utility in Mata is appealing, but I couldn't figure out how to create the loops ( no "foreach" command?), generate new matrixes names automatically (for the matrices C) and access my 20 matrices within the loops in Mata. Here is what I would do if I could use "rowsum" in Stata: foreach n in 1 2 3 4 5 6 7 8 9 10 {; matrix c'n´= J(rowsof(A'n´),1,0) *I create my matrix c (vector of 25 rows) containing only 0 values ; foreach i in 1-25 {; * where i correspond to the number of rows; R_sum_A'n´=rowsum(A'n´) ; R_sum_B'n´=rowsum(B'n´) ; *I compare the two sums and if the rowsum of A is bigger than B I put it in the new matric C, if not I leave it equals to 0 ; if el(R_sum_A'n´,'i´,1)> el(R_sum_B'n´,'i´,1) matrix C'n´['i´,1] =el(R_sum_A'n´,'i´,1) ; }; }; But I cannot use "rowsum" into stata . So what would you suggest ? Thanks a lot Raphael _________________________________________________________________ Your E-mail and More On-the-Go. Get Windows Live Hotmail Free. https://signup.live.com/signup.aspx?id=60969 * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**st: Re: st: Matrices utilities, Basic calculations. When to start using Mata over Stata?***From:*Tirthankar Chakravarty <tirthankar.chakravarty@gmail.com>

**st: Re: st: Matrices utilities, Basic calculations. When to start using Mata over Stata?***From:*Austin Nichols <austinnichols@gmail.com>

**st: AW: Matrices utilities, Basic calculations. When to start using Mata over Stata?***From:*"Martin Weiss" <martin.weiss1@gmx.de>

**st: RE: Matrices utilities, Basic calculations. When to start using Mata over Stata?***From:*"Abhimanyu Arora" <abhimanyu.arora@student.kuleuven.be>

- Prev by Date:
**Re: Re: st: RE: AW: ratio function** - Next by Date:
**st: RE: Matrices utilities, Basic calculations. When to start using Mata over Stata?** - Previous by thread:
**st: Tabstat - how to get min & max stats in one row to show range** - Next by thread:
**st: RE: Matrices utilities, Basic calculations. When to start using Mata over Stata?** - Index(es):