Announcement

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

  • Coefplot different colours confidence intervals

    Hi, I am creating a coefficient plot with confidence intervals at the 99, 95, 90 percent significance intervals. I would like the confident intervals to be different colours depending on the significance level

    Code:
    sysuse auto
    eststo reg_1: reg price mpg
    eststo reg_2: reg price mpg headroom
    coefplot reg_1 reg_2, keep(mpg) levels(99 95 90)
    I tried adding the following:
    Code:
    coefplot (reg_1, mcolor(ebblue) ciopts(color(ebblue))) (reg_2, mcolor(ebblue) ciopts(color(ebblue))), keep(mpg) levels(99 95 90)
    but it seems only the 99% confidence interval is affected, how can I chose the colour of each confidence interval?

  • #2
    Cross-posted at https://stackoverflow.com/questions/...vals-by-colour

    coefplot is a great command I never use -- because I just don't write papers using that kind of plot. More importantly, it is a very popular command but none of its users answered this, so the best advice is to email its author Ben Jann directly. But I can't speak for Ben's policy on user support. He has written so many excellent and popular commands that he may not be able to provide one-to-one support.

    Comment


    • #3
      A chunk of repeated codes and not sure whether it is what you need:
      Code:
      coefplot (reg_1, mcolor(ebblue) ciopts(color(ebblue)) level(90)) (reg_1, mcolor(navy) ciopts(color(navy)) level(95)) (reg_1, mcolor(maroon) ciopts(color(maroon)) level(99)) (reg_2, mcolor(ebblue) ciopts(color(ebblue)) level(90)) (reg_2, mcolor(navy) ciopts(color(navy)) level(95)) (reg_2, mcolor(maroon) ciopts(color(maroon)) level(99)), keep(mpg) legend(row(2))
      Click image for larger version

Name:	Graph.png
Views:	1
Size:	35.0 KB
ID:	1696750

      Comment


      • #4
        Thank you Chen, however I was trying to have the three confidence intervals on top of each other, like in the example code I sent, do you think it is possible?

        Comment


        • #5
          Maybe you can try this (I use more distinguishable color instead of navy and maroon in #3):
          Code:
          coefplot (reg_1, mcolor(ebblue) ciopts(color(ebblue yellow red)) level(99 95 90)) ///
                   (reg_2, mcolor(ebblue) ciopts(color(ebblue yellow red)) level(99 95 90)), keep(mpg)
          see #6
          Last edited by Chen Samulsion; 11 Jan 2023, 08:58. Reason: Sorry I cannot delete this redundant post

          Comment


          • #6
            Maybe you can try this (I use more distinguishable color instead of navy and maroon in #3):
            Code:
            coefplot (reg_1, mcolor(ebblue) ciopts(color(ebblue yellow red)) level(99 95 90)) (reg_2, mcolor(ebblue) ciopts(color(ebblue yellow red)) level(99 95 90)), keep(mpg)
            Click image for larger version

Name:	Graph2.png
Views:	1
Size:	32.0 KB
ID:	1696795

            Comment


            • #7
              this is perfect! thank you very much!

              Comment


              • #8
                Also, in this case, if I distinguish both regression models by changing the shape of the coefficient interval (e.g. msymbol(t) in reg_1 and msymbol(s) in reg_2), is there a way to have two legends, one showing the distinction by colour and other other one by msymbol? All I have managed to do is ammend the existing legend which is based on the regression models but ideally I guess the best approach would be to create a custom legend from scratch (if at all possible)?


                thank you very much again

                Comment

                Working...
                X