Announcement

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

  • Plotmatrix cannot accept matrix column names although it seems fine with rownames

    Hi all. The title says it all. The code below produces an example plotmatrix. Note that I have commented out the problematic line - but if you include this line, plotmatrix returns the error "invalid syntax". This is most dissatisfying as the labels are critical here.

    Any ideas? Using combinations of "labels" or `"labels" ' or even "` "label1" "label2" "etc" '' ' has not helped.

    Code:
    matrix def x = 0,0,0,0,2,5\2,4,2,5,19,43\7,6,8,12,51,161\10,11,12,31,84,190\4,5,13,24,57,96
    
    local rows 80-100 60-80 40-60 20-40 0-20
    local cols 0-2 2-4 4-6 6-8 8-10 10-12
    matrix rownames x=`rows'
    *matrix colnames x=`cols'        //this line causes the error
    mat li x
    
    plotmatrix, mat(x) split(0(30)210) freq  formatcells(%2.0f) title("Example") ylabel(, labsize(small)) xlabel(, labsize(small))

  • #2
    First, as the FAQ request you to explain for the benefit of readers: plotmatrix is a community-contributed command, available from SSC.

    I hadn't used the command before, but I tried your code with set trace on, and also looked at the source code using
    Code:
    viewsource plotmatrix.ado
    , and the answer seems to be that plotmatrix in turn calls svmat, which creates Stata variables using the column names of the matrix you supply in mat. Since the column names you are providing are not legal variable names, the code fails.

    Comment


    • #3
      We then have to ask for examples of what is allowed.
      Actually, matrix allows more than plotmatrix appears to support (I am not acquinted that much with this user community contributed package by Prof. Adrian Mander, Cardiff University).
      First, let us try 'single word' labels, like:
      Code:
      * SetUp
      ssc install plotmatrix , replace
      
      *Example
      matrix def x = 0,0,0,0,2,5\2,4,2,5,19,43\7,6,8,12,51,161\10,11,12,31,84,190\4,5,13,24,57,96
      
      local rows "80_100" "60_80" "40_60" "20_40" "0_20"
      local cols "0_2" "2_4" "4_6" "6_8" "8_10" "10_12"
      matrix rownames x="`rows'"
      matrix colnames x="`cols'"
      mat li x
      
      plotmatrix, mat(x) split(0(30)210) freq formatcells(%2.0f) title("Example") ylabel(, labsize(small)) xlabel(, labsize(small)) name(under, replace)
      graph export "plotmatrix_underscore.png", width(726) height(528) replace // Change path as required
      which results in:
      Click image for larger version

Name:	plotmatrix_underscore.png
Views:	1
Size:	27.8 KB
ID:	1684535


      Next, we can try various labels and check if matrix allows for them, but, sadly plotmatrix will not:
      Code:
      local rows "80|100" "60|80" "40|60" "20|40" "0|20"
      local cols "0|2" "2|4" "4|6" "6|8" "8|10" "10|12"
      matrix rownames x="`rows'"
      matrix colnames x="`cols'"
      mat li x
      
      plotmatrix, mat(x) split(0(30)210) freq formatcells(%2.0f) title("Example") ylabel(, labsize(small)) xlabel(, labsize(small))
      
      
      local rows "80~100" "60~80" "40~60" "20~40" "0~20"
      local cols "0~2" "2~4" "4~6" "6~8" "8~10" "10~12"
      matrix rownames x="`rows'"
      matrix colnames x="`cols'"
      mat li x
      
      plotmatrix, mat(x) split(0(30)210) freq formatcells(%2.0f) title("Example") ylabel(, labsize(small)) xlabel(, labsize(small))
      
      local rows "80-100" "60-80" "40-60" "20-40" "0-20"
      local cols "0-2" "2-4" "4-6" "6-8" "8-10" "10-12"
      matrix rownames x="`rows'"
      matrix colnames x="`cols'"
      mat li x
      
      plotmatrix, mat(x) split(0(30)210) freq formatcells(%2.0f) title("Example") ylabel(, labsize(small)) xlabel(, labsize(small))
      Then, our next best alternative is 'coding' the labels like we want them (after some tweaking with the calibration of the axis tick mark positions):
      Code:
      local rows "80_100" "60_80" "40_60" "20_40" "0_20"
      local cols "0_2" "2_4" "4_6" "6_8" "8_10" "10_12"
      matrix rownames x="`rows'"
      matrix colnames x="`cols'"
      mat li x
      
      plotmatrix, mat(x) split(0(30)210) freq formatcells(%2.0f) title("Example") ylabel(0 "80-100" -1 "60-80" -2 "40-60" -3 "20-40" -4 "0-20", labsize(small)) xlabel(1 "0-2" 2 "2-4" 3 "4-6" 4 "6-8" 5 "8-10" 6 "10-12", labsize(small))
      graph export "plotmatrix_dash.png", width(960) height(640) replace // Change path as required
      which results in:

      Click image for larger version

Name:	plotmatrix_dash.png
Views:	1
Size:	37.2 KB
ID:	1684536
      http://publicationslist.org/eric.melse

      Comment


      • #4
        Hello both

        Thanks for your comments and my apologies for not highlighting that the command is user written.

        @ericmelse I tried the underscores but was dissatisfied as they don't imply the concept of a range (or buckets) as well as hyphens do. Thanks for trying a couple specifications.

        The last solution will do the trick!

        Regards,
        Bruce

        Comment

        Working...
        X