Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How get row name matrix for especific condition


    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'"
    three

    My goal its get the row and col names for frequency 27: three and Juan.
    Last edited by Rodrigo Badilla; 23 Oct 2018, 13:59.

  • #2
    Rodrigo: Have you tried st_matrixrowstripe() and st_matrixcolstripe() in Mata? See help mf_st_matrix

    Comment


    • #3
      Hi, John,

      Thanks for you reply.

      st_matrixrowstripe() and st_matrixcolstripe() work great :

      Code:
      . mata : st_matrixrowstripe("x")
                 1       2
          +-----------------+
        1 |           Juan  |
        2 |          Pedro  |
          +-----------------+


      I will try go get names for max values with: st_matrixrowstripe("x", max(st_matrix("x")))

      Comment

      Working...
      X