Statalist The Stata Listserver


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

st: RE: absolute values from a matrix


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: absolute values from a matrix
Date   Thu, 9 Nov 2006 15:07:51 -0000

Use Mata. 

: x = uniform(3,3) :- 0.5

: x
                  1              2              3
    +----------------------------------------------+
  1 |   .3714490768   -.2448501205   -.4554811986  |
  2 |  -.0758442807    .3983461575    .0219247625  |
  3 |   .3414094402   -.2889923407    .0644091703  |
    +----------------------------------------------+

: y = abs(x)

: y
                 1             2             3
    +-------------------------------------------+
  1 |  .3714490768   .2448501205   .4554811986  |
  2 |  .0758442807   .3983461575   .0219247625  |
  3 |  .3414094402   .2889923407   .0644091703  |
    +-------------------------------------------+

If you are on Stata <9, then do say so in your postings. 

In that case, one inelegant but functional tool
is -matmap- from SSC. 

Nick 
[email protected] 

Tom Boonen
 
> is there an elegant way to create a matrix that contains the absolute
> values of the entries of another matrix?
> 
> Something like:
> 
> matrix w = (1 , -1 \ 2,	-2)
> matrix list w
> 
> *w[2,2]
> *c1  c2
> *r1   1  -1
> *r2   2  -2
> 
> * But then:
> 
> . matrix w = abs(w)
> type mismatch
> r(109);

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