If you sort on the first column, the value
in the second column corresponding to the
maximum of the first will end up last too, and as
such accessible.
: x = (3,2\5,3\4,6)
: sortx = sort(x,1)
: sortx
1 2
+---------+
1 | 3 2 |
2 | 4 6 |
3 | 5 3 |
+---------+
: sortx[rows(x),2]
3
Nick
[email protected]
Le Wang
> I have a question regarding Mata. Suppose I have an imaginary matrix
> with two columns as follows,
> x y
> 2.9479707 .15
> 2.926226 .16
> 2.8994321 .17
> 2.8691981 .18
> 2.8368784 .19
> 2.8035694 .2
> 2.7701303 .21
> 2.7372142 .22
> 2.705299 .23
> 2.6747184 .24
>
> I want Mata to return the maximum values of column 1 (x) AND its
> corresonding values in column 2 (y), in this example, 2.9479707 and
> 0.15. I understand I can use -rowmax- to find the maximum, but I am
> not quite sure how to find the corresponding value.
*
* 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/