Announcement

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

  • coefplot: combining and color-code different models?

    Hi Statalist,

    I was trying to use coefplot, to combine an predictor's coefficients, estimated from two models. Basically I want to compare the effect size of this predictor in different models. below are the scripts I wrote, in which I hope to color the coeffects and the CIs in different colors from different models.

    Code:
    sysuse auto, clear
    regress price mpg trunk length turn if foreign==0
    estimates store D
    regress price mpg trunk length turn if foreign==1
    estimates store F
    *Solution 1: the ylabel is perfect; however I could not color D an F differently 
    coefplot D, bylabel(Domestic Cars) ///
            || F, bylabel(Foreign Cars)  ///
            ||, bycoefs keep(mpg) 
            
    *Solution 2: the colors can be re-coded; however, ylabel is not correct        
    coefplot (D, bcolor(grey))  ///
             (F,  bcolor(green)), ///
                keep(mpg)  legend(off)
    I could not seem to find a solution that combines both outputs: (1) ylabel: "Domestic Cars" and "Foreign Cars"; (2) different colors for the two coefficients and CIs.

    I also tried to add color options in Solution 1: things like below, but that color options apply to all graphs, instead of subgraph D
    Code:
    coefplot D, bylabel(Domestic Cars) mcolor(green) ///
            || F, bylabel(Foreign Cars)  ///
            ||, bycoefs keep(mpg)
    I wonder if I miss anything here? Please advise Any comments or directions are much appreciated!

    Thanks!!


  • #2
    coefplot is from SSC, as you are asked to explain (FAQ Advice #12). Thanks for the reproducible example. I think you just need the option -norecycle-.

    Code:
    sysuse auto, clear
    regress price mpg trunk length turn if foreign==0
    estimates store D
    regress price mpg trunk length turn if foreign==1
    estimates store F
    *Solution 1: the ylabel is perfect; however I could not color D an F differently 
    coefplot D, bylabel(Domestic Cars) ///
            || F, bylabel(Foreign Cars)  ///
            ||, bycoefs keep(mpg) norecycle
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	23.2 KB
ID:	1655162

    Comment


    • #3
      Hi Andrew, thank you so much for this neat solution! I am sorry that I forgot to mention this is from SSC; before posting, I did check -help coefplot- to search what is the color option for subgraphs but I could not find any keywords related to color. Now I realize it is this norecycle option! Wonderful, thank you again!

      Comment

      Working...
      X