Hi all I wonder if its possible get row names for a matrix for the max value in all matrix.
Andrew Mosau sent me this great code to get columns names but I could not remake to get names rows:
Code:
sysuse auto, clear
qui tabulate foreign rep78, matcell(x)
matrix colnames x= one two three four five
matrix rownames x= Juan Pedro
mat lis x
local ma : coln (x)
x[2,5]
one two three four five
Juan 2 8 27 9 2
Pedro 0 0 3 9 9
mata
x= st_matrix("x")
xs = sort(-x,1)
v = xs[(1), .]
maxcol = selectindex(v:==rowmin(v))
st_numscalar("max", maxcol)
end
local maxcol= max
local maxcolname: word `maxcol' of `ma'
di "`maxcolname'"
My goal its get the row and col names for frequency 27: three and Juan.

Comment