Announcement

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

  • Color of Confidence Intervals

    Dear Stata users,

    Is it possible to have the same color for 95 CI in all groups? I am using the following code:

    twoway (scatter coef species if (species==1 & country==1), msymbol(S) msize(medium) mcolor(red) ) ///
    (rcap ci_up ci_low species if (species==1 & country==1)) ///
    (scatter coef species if (species>1 & species<4 & country==1), msymbol(S) msize(medium) mcolor(red) ) ///
    (rcap ci_up ci_low species if (species>1 & species<4 & country==1)) (line coef species if (species>1 & species<4 & country==1), lwidth(thick) lcolor(navy) connect(direct)) ///
    (scatter coef species if (species>3 & species<7 & country==1), msymbol(S) msize(medium) mcolor(red) ) ///
    (rcap ci_up ci_low species if (species>3 & species<7 & country==1)) (line coef species if (species>3 & species<7 & country==1), lwidth(thick) lcolor(navy) connect(direct)), ///
    xlabel( 1 "2 conif" 2 "1 broad" 3 "2 broad" 4 "2 mix" 5 "3 mix" 6 "3 mix" ) ///
    ytitle(km) yline(0, lpattern(dash) lc(black)) legend(off)

    I can restrict the color of lines and markers to be the same in all groups but the colors of 95 CIs change across groups. Is there a way to have them the same in all groups? I've attached the graph that I get.

    Thank you
    Attached Files

  • #2
    Please do read and act on https://www.statalist.org/forums/help#stata There it is explained: do use CODE delimiters; don't post .gph attachments.

    But sure: I can't see any reason why the rcap calls can't be combined, in which case the colour problem is solved.

    Comment


    • #3
      Sorry, here is my code using CODE delimiters

      Code:
      twoway (scatter coef species if (species==1 & country==`x'), msymbol(S) msize(small) mcolor(red) ) ///
             (rcap ci_up ci_low species  if (species==1 & country==`x')) ///  
             (scatter coef species if (species>1 & species<4 & country==`x'), msymbol(S) msize(small) mcolor(red) ) ///  
             (rcap ci_up ci_low species if (species>1 & species<4 & country==`x')) (line coef species if (species>1 & species<4 & country==`x'), lcolor(navy) connect(direct))  ///
             (scatter coef species if (species>3 & species<7 & country==`x'), msymbol(S) msize(small) mcolor(red) ) ///
             (rcap ci_up ci_low species if (species>3 & species<7 & country==`x')) (line coef species if (species>3 & species<7 & country==`x'),  lcolor(navy) connect(direct)), ///
              xlabel( 1 "2Conf" 2 "1Brd" 3 "2Brd" 4 "2Mix" 5 "3Mix" 6 "3Mix"  ) title (`t')  ///
              ytitle(km) yline(0, lpattern(dash) lc(black)) legend(off)
      Maybe I was not sufficiently precise so I will try one more time. I have three goups defined based on the variable "species". The colors of 95 CI bars are the same within each group but vary across the three groups. Is there a way to have exactly the same color of 95 CI bars across the three groups? I am looking for an equivalent of lcolor(*) for CI bars.

      Thank you

      Comment


      • #4
        It's the same answer from me. Yes you can. I don't have any of your data to experiment but this syntax looks equivalent to me.

        Code:
        twoway (scatter coef species if country == `x', msymbol(S) msize(small) mcolor(red) ) ///
               (rcap ci_up ci_low species if country == `x')) ///  
               (line coef species if (species>1 & species<4 & country==`x'), lcolor(navy) connect(direct))  ///
               (line coef species if (species>3 & species<7 & country==`x'),  lcolor(navy) connect(direct)), ///
                xlabel( 1 "2Conf" 2 "1Brd" 3 "2Brd" 4 "2Mix" 5 "3Mix" 6 "3Mix"  ) title (`t')  ///
                ytitle(km) yline(0, lpattern(dash) lc(black)) legend(off)
        On a different note: you have enough space for less cryptic axis labels.
        Last edited by Nick Cox; 07 Jan 2020, 06:32.

        Comment

        Working...
        X