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]
st: Matrices utilities, Basic calculations. When to start using Mata over Stata?
From
Radaf paf <[email protected]>
To
<[email protected]>
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/