Announcement

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

  • colours for coefplot with matrix

    Hi,

    I am using Stata16 and would like to produce a multicoloured coefplot from a matrix that contains means, p25 and p75 from a tabstat command:
    Code:
    tabstat dom1-dom9, by(cluster_num) stat(mean p25 p75) save
    matrix c1 = r(Stat1)
    My coefplot code is:
    Code:
        coefplot matrix(c1[1]), ///
            ci((2 3)) ///
            msymbol(x) msize(large) ///
            ylabel(, labsize(small)) xlabel(, labsize(small)) xlab(0(20)100) xsca(range(0(20)100)) ///
            graphregion(color(white) fcolor(white) lcolor(white) ilcolor(white) ifcolor(white)) ///
            title("Cluster 1", ///
            size(small)) name("scores_cluster_1", replace)
    I would like to plot each interquartile range in a different colour. Unfortunately, I am using a martix for the coefplot, so I wonder if there is a workaround for this?

    Thanks,
    Jane.

  • #2
    Jane,

    It should not make a difference for the coefplot options if your data source is a matrix or saved results (which are matrices).
    Do have a look at Ben Jann's website about coefplot.
    Otherwise, you should provide data with your code to enable forum members to respond as per FAQ, point 12.
    http://publicationslist.org/eric.melse

    Comment


    • #3
      As Eric states (covered in FAQ Advice #12), the fastest way to obtain help is provide a reproducible example. Your code in #1 is helpful, but bear in mind that in the context of coefplot, what you are asking is how to change the color of the confidence interval (CI) spike. Whether using matrices or stored estimates, you will want to have the ability to affect the rendition of a particular CI spike, and in the latter case, you use multiple stored estimates. In a similar fashion, you can use multiple matrices. This suggests extracting submatrices from your matrix. In the example below, my matrix has 2 columns, implying that I can extract 2 submatrices.

      Code:
      sysuse auto, clear
      tabstat head gear, by(foreign) stat(mean p25 p75) save
      matrix c1 = r(Stat1)
      forval i= 1/ `=colsof(c1)'{
          mat c1`i'= c1[1..`=rowsof(c1)', `i']
      }
      
      coefplot (matrix(c11[1]), ci((2 3)) msymbol(x) mc(red) msize(large) ///
      ylabel(, labsize(small)) xlabel(, labsize(small)) graphregion(color(white) ///
      fcolor(white) lcolor(white) ilcolor(white) ifcolor(white)) ciopt(lc(red)) nokey) ///
      (matrix(c12[1]), ci((2 3)) msymbol(x) msize(large) mc(blue) ciopt(lc(blue)) nokey)
      Res.:
      Click image for larger version

Name:	Graph.png
Views:	1
Size:	13.8 KB
ID:	1630505


      Last edited by Andrew Musau; 06 Oct 2021, 03:04.

      Comment


      • #4
        Thank you Andrew and Eric. This works perfectly!

        Comment

        Working...
        X