# st: RE: RE: Sort each column of a matrix to have the same rank order as another matrix

 From "Scott Merryman" To Subject st: RE: RE: Sort each column of a matrix to have the same rank order as another matrix Date Thu, 19 May 2005 12:51:56 -0500

```Nick,

Thanks.  I have been trying to use the -sort(,)- function but I don't think
it will do what I want.

I have found a partial solution: -y = x[r,1]- will permute vector x
according to vector r (see [M-1] p. 52)

. mata
------------------------------------------------- mata (type end to exit)
--: x = (6,9,2,4,7)'

: t = (1, -1,-2,2,0)'

: r = (2, 4, 5, 1, 3)'

: y = x[r,1]

: y
1
+-----+
1 |  9  |
2 |  4  |
3 |  7  |
4 |  6  |
5 |  2  |
+-----+

My new question is how to turn the vector t into the rank order vector r?

Scott

> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-
> statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
> Sent: Thursday, May 19, 2005 11:40 AM
> To: statalist@hsphsun2.harvard.edu
> Subject: st: RE: Sort each column of a matrix to have the same rank order
> as another matrix
>
> Is the Mata function -sort(,)- the answer here?
>
> Nick
> n.j.cox@durham.ac.uk
>

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