I am trying to solve a problem in name selection (row selection) for a specific condition (max value), I only could select names with a one word but my data have names with 2 or three words, example:
Code:
sysuse auto, clear
keep in 1/5
keep if !missing(rep)
tabulate make turn, matcell(x)
| Turn Circle (ft.)
Make and Model | 40 43 | Total
-------------------+----------------------+----------
AMC Concord | 1 0 | 1
AMC Pacer | 1 0 | 1
Buick Century | 1 0 | 1
Buick Electra | 0 1 | 1
-------------------+----------------------+----------
Total | 3 1 | 4
levels make, local(makes)
mat rownames x = `makes'
local ma2 : rown (x)
mat xp= x'
mata
x= st_matrix("xp")
xs = colmax(x)\colmax(x)\colmax(x)\colmax(x)
v = xs[(1), .]
maxcol = selectindex(v:==rowmax(v))
end
local maxrow= max
local maxrowname: word `maxrow' of `ma2'
di "`maxrowname'"
AMCRegards
Rodrigo
0 Response to Row selection in two words names
Post a Comment