[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: absolute values from a matrix
On Nov 9, 2006, at 8:59 AM, Tom Boonen wrote:
is there an elegant way to create a matrix that contains the
absolute values of the entries of another matrix?
Mata is elegant. For example, Mata's scalar functions (like abs())
will all operate on matrices element-wise. Thus, to use your example
(from the Mata prompt):
: foo = (1, -1 \ 2, -2)
: abs(foo)
1 2
+---------+
1 | 1 1 |
2 | 2 2 |
+---------+
Type -help mata- to learn more. If you prefer instead to work within
Stata, you can use a single Mata call to do what you want, like this:
. mat foo = (1, -1 \ 2, -2)
. mata: st_matrix("absfoo",abs(st_matrix("foo")))
. mat li absfoo
absfoo[2,2]
c1 c2
r1 1 1
r2 2 2
-- Phil
*
* 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/