Announcement

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

  • Row selection in two words names

    Hi all,

    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'"
    
    AMC
    Thanks in advance
    Regards
    Rodrigo

  • #2
    -help strtoname()- That function will replace the blanks, which are not legal in names, with underscore (_) characters, which are.

    Comment


    • #3
      Thanks Clyde Schechter for your reply, this solve my problem. Sorry my code had a problem. I could not edit...

      Anyway below I give other example with the same problem:

      Code:
      sysuse auto, clear
      
       keep in 1/5
       keep if !missing(rep)
       tabulate make turn, matcell(x)
      
       levels make, local(makes)
       mat rownames x = `makes'
      
      *ssc install matsort
       matsort x 1 "down"
       mat li x
      
      x[4,2]
               c1  c2
          AMC   1   0
      Concord   1   0
          AMC   1   0
        Pacer   0   1
      
       local rownms: rown x
       local rowname: word 1 of `rownms'
      
      di "`rowname'"
      AMC

      Comment

      Working...
      X