Announcement

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

  • Line graph with interquartile ranges as shaded area rather than error bars

    Hello, I wondered if anyone can help. I followed some guidance on here to generate new variables for the median and IQR.
    I now want to generate a line graph for three variables (possibly more), each are showing the median by year. I want to add the interquartile range as a shaded area for two (mcorn and mderby) rather than as error bars (tried in excel but if the series' intersect it won't show both).
    I have created variables for the 25th and 75th percentile for both 'mcorn' and 'mderby' but I don't know how to plot these. Please let me know if this is possible?!

    the line graph is as follows: twoway (line medianvar1 mcorn mderby year, sort)

    Thank you in advance!
    Last edited by Kate Harris; 14 Oct 2015, 07:39.

  • #2
    Like this:
    Code:
    webuse grunfeld,clear
    collapse (p50) invest_50=  invest (p75) invest_75 = invest (p25) invest_25=invest (p50) /// 
        kstock_50=  kstock (p75) kstock_75 = kstock (p25) kstock_25=kstock, by(year)
    twoway rarea invest_75 invest_25 year, fcolor(gs8) ///
        || rarea kstock_75 kstock_25 year, color(blue*.25) /// 
        || line invest_50 year, lc(black) lw(medium)  /// 
        || line kstock_50 year, lc(blue) lw(medium) /// 
        || line invest_25 year, lc(gs8) lw(medium) /// 
        || line invest_75 year, lc(gs8) lw(medium) /// 
        ||, legend(off)
    Click image for larger version

Name:	Graph.png
Views:	2
Size:	22.5 KB
ID:	1313038
    Attached Files

    Comment


    • #3
      Yes exactly like that thank you Scott! I will try it out on my data now,

      Comment


      • #4
        This is excellent, thanks, but it's a bit cumbersome to collapse if you have multiple "by" covariates.
        As a rough alternative, when using a continuous x variable, is there a way to add IQR to the median band plot?
        Thanks!

        Comment


        • #5
          Very helpful thanks!!!
          Last edited by Jannis Keller; 21 Jun 2021, 12:28.

          Comment

          Working...
          X