Announcement

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

  • Coefplot - color by level of significance

    Dear all,

    Is there a way to color the confidence intervals in a coefplot so that it reflects the level of significance of each coefficient? I know it is doable by manually changing the color but is there a way to do it on a systematic basis (i.e. when a coefficient statistically different from 0 with 99 percent certainty the confidence interval in the coefplot is green, when a coefficient is different from 0 at 95 percent then it is orange, 90 percent red, and below 90 percent navy?

    Below is an example of how to change the color manually. In the specification only mpg is significant at the 95% level (p-value .038), the other variables are not statistically different from 0. While it is easy to do it manually it takes a lot of time when one has to change manually the color for each confidence interval over multiple graphs. So I am looking for a more systematic way to do it.

    HTML Code:
    sysuse auto, clear
    regress price mpg trunk length turn
    estimates store reg1
    coefplot /*
    */ (reg1, keep(mpg) mcolor(orange) ciopts(color(orange))) /*
    */ (reg1, keep(trunk) mcolor(navy) ciopts(color(navy))) /*
    */ (reg1, keep(length) mcolor(navy) ciopts(color(navy))) /*
    */ (reg1, keep(turn) mcolor(navy) ciopts(color(navy))) /*
    */ , drop(_cons) xline(0) msymbol(s) mfcolor(white)

  • #2
    Hi Marcel,

    One (almost manual) option would be to export the estimates data into a new frame (in Stata16), then recode your p-values into numeric color codes. Then script out the coefficient plots to include the color in the plots. If you're doing this repeatedly, writing a short program should do the trick. Another option would be to reverse engineer coefplot to see if you can code the colors automatically based on a coefficient parameter.

    Comment


    • #3
      Hi Daniel Shin,
      Thank you very much for your reply. I will try the first suggestion but I guess I am not good enough to succeed. I am using Stata 16.

      Comment


      • #4
        Stata tip 103: Expressing confidence with gradations
        does something related.
        https://journals.sagepub.com/doi/pdf...867X1201100409

        Comment


        • #5
          Hi all,

          So I was able to do more or less what Daniel suggested (i.e. I stored coeff estimates, and pvalue in a new frame). I am not sure how to recode the p-values into numeric color codes. Does anyone have a guess? I added the frame as a .csv

          HTML Code:
          #delimit ;
          scatter _cb _cplot, mc(navy) msize(vsmall) || rcap _cul1 _cll1 _cplot, lc(navy) ||,
          yline(0, lp(dash)) xlabel(1(1)7, labsize(vsmall))
          ytitle("Beta coefficient (95% CI)", margin(small)) legend(off)
          ylab(,nogrid) graphregion(color(white)) aspectratio(1) 
          saving("output/test.pdf", replace) ;
          graph export "output/test.pdf", replace ;
          #delimit cr
          Attached Files

          Comment


          • #6
            I am trying to do something similar, but with coefplot. Were you able to get this figured out?

            Comment


            • #7
              Actually, scratch that, I figured it out
              Code:
              sysuse auto, clear
              regress price mpg trunk length turn if foreign==1
              
              coefplot (., if(@ll<0 & @ul>0)) /// nonsignificant (0 included in CI)
                      (., if(@ll>0 | @ul<0)) /// significant (0 not in CI)
                 , drop(_cons) nooffset xline(0) legend(off)

              Comment

              Working...
              X