<>
For whatever it's worth, the following mata one-liner will also do the
job (using your A, i, and j notation from below):
sort(A,i)[rows(A),j]
Best,
Glenn
Re: st: row number corresponding to a column maximum
Gabi Huiber <[email protected]> wrote:
Thank you, Maarten. I already cobbled together something similar. It
can be saved as a .mo file, maybe it helps somebody:
// Mata function for getting value in col i
// on row that corresponds to max in col j
// (that is, the i neighbor of the max in j)
capture mata mata drop maxneighbor()
mata
real scalar maxneighbor(real matrix A, real scalar i, real scalar j)
{
real scalar k, r, max
r=rows(A)
max=colmax(A)[1,j]
k=1
while(A[k,j]<max) {
k=k+1
}
return(A[k,i])
}
mata mosave maxneighbor(), dir("${adoroot}") replace
end
Thanks again,
Gabi
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/