Announcement

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

  • Line graph where 3 shaded confidence intervals overlap

    Hello,

    I am trying to graph 4 lines that have shaded confidence intervals. I have the upper and lower bounds already and the data is formatted like below.

    Code:
    input float(year trendsm trendsl trendsh dgcl dgcm dgch gcl gcm gch al am ah)
    2020    0    0    0     0     0     0     0     0     0     0     0     0
    2021  .03  .01  .04  -.07  -.03     0   -.2  -.12  -.06  -.24  -.15  -.07
    2022  .03 -.02  .07  -.22  -.12  -.04  -.54  -.34   -.2  -.64  -.42  -.23
    2023 -.11 -.18 -.05  -.55  -.38  -.25  -1.1  -.78  -.53  -1.3  -.92  -.59
    2024 -.12 -.22 -.02  -.78  -.52  -.34 -1.63 -1.15  -.78 -1.93 -1.37  -.88
    2025 -.26  -.4 -.12 -1.16  -.82  -.57 -2.13 -1.54 -1.08 -2.61 -1.89 -1.26
    2026 -.23 -.42 -.05 -1.37  -.95  -.62 -2.34 -1.68 -1.15 -3.05 -2.21 -1.46
    2027 -.33 -.56 -.12  -1.7  -1.2  -.81 -2.59 -1.87  -1.3 -3.55 -2.62 -1.76
    2028 -.43 -.69 -.19 -2.02 -1.43  -.99 -2.73 -1.98 -1.37 -3.99 -2.99 -2.04
    2029 -.36 -.66 -.09 -2.17 -1.51 -1.01 -2.67  -1.9 -1.27 -4.25 -3.19 -2.16
    2030 -.46  -.8 -.16 -2.48 -1.76 -1.19 -2.77 -1.98 -1.34 -4.66 -3.54 -2.43
    The problem I am having is that the shaded area for 3 of the confidence intervals intersect. When the shaded areas intersect I need them to be transparent/blend.

    After searching I found drarea but I could only get it to work for 2 intersecting areas not 3.

    Any suggestions would be much appreciated. Thanks!

    EDIT:: I am using STATA 14.1

    Last edited by Scott Tschida; 10 Jun 2020, 14:35.

  • #2
    Hi Scott,
    Welcome to Statalist. You'll increase your chances of a useful answer by following the FAQ on asking questions - provide Stata code in code delimiters, readable Stata output, and sample data using dataex.

    Anyway, for your problem, you can use a combination of rarea and drarea, setting the opacity of the color of the rarea (that % after green), You could also use only rarea.

    Code:
    drarea dgcl gcl dgch gch year
    gr addplot  rarea dgcm gcm year, fc(green%20)
    Mattia

    Comment


    • #3
      Originally posted by Mattia Coppo View Post
      Hi Scott,
      Welcome to Statalist. You'll increase your chances of a useful answer by following the FAQ on asking questions - provide Stata code in code delimiters, readable Stata output, and sample data using dataex.

      Anyway, for your problem, you can use a combination of rarea and drarea, setting the opacity of the color of the rarea (that % after green), You could also use only rarea.

      Code:
      drarea dgcl gcl dgch gch year
      gr addplot rarea dgcm gcm year, fc(green%20)
      Mattia
      Hi Mattia,

      Thank you for the response. I have tried setting the opacity before and it doesn't work

      Code:
       twoway rarea al ah year, fc(green%20)
      Results in this error:

      (note: named style green % 20 not found in class color, default attributes used)

      Comment


      • #4
        I tried this and I did not get an error however it did not result in the overlapping areas to be transparent

        Code:
         twoway (rarea al ah year, fc(green*.5))(rarea gcl gch year, fc(blue*.5))(rarea dgcl dgch ye
        > ar, fc(orange*.5))
        I have stumbled upon this link where a user states that transparency is not available until STATA 15. Is it not possible in STATA 14?

        https://www.statalist.org/forums/for...s-transparency

        https://www.timberlake.co.uk/news/se...tata-graphics/
        Last edited by Scott Tschida; 10 Jun 2020, 15:27.

        Comment


        • #5
          That is correct. https://www.stata.com/help.cgi?whatsnew14to15 is accessible to you and explains that transparency was introduced in Stata 15. (Not STATA,please.)

          Rafal Raciborski was writing as a StataCorp employee and what he says remains correct.

          Comment

          Working...
          X