Statalist The Stata Listserver

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

st: return the maximum and corresponding value...

From   Kit Baum <>
Subject   st: return the maximum and corresponding value...
Date   Sun, 5 Nov 2006 14:13:09 -0500

Le Wang said

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.

The good news: there is a function undocumented in the manual to handle this.
The bad news: it does not appear to work.

This workaround does:

real scalar lewang(real matrix a)
real vector i

Now all this horsing around should be unnecessary, for you should just be able to call


But that yields

<istmt>: 3499 ii not found

minindex() doesn't seem to work either, even on the examples in the helpfile:

: v = (3,1,5,7,6)

: minindex(v, 1, i, w)
<istmt>: 3499 i not found

Looks like a bug to me.

Kit Baum, Boston College Economics
An Introduction to Modern Econometrics Using Stata:

* For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index