Announcement

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

  • Shade area between two lines

    Hi everyone

    I am having issues with shading the area between two lines.

    Below is the data & code I have used to generate my line graphs.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int year float(delta30 timevarsd upper lower)
    2005   .036 .7602793 1.5261474 -1.4541475
    2006  .2751 .7602793 1.7652475 -1.2150475
    2007  .8808 .7602793 2.3709474  -.6093474
    2008  1.779 .7602793 3.2691474  .28885263
    2009 1.8134 .7602793 3.3035474   .3232526
    2010 2.1472 .7602793 3.6373475   .6570527
    2011 2.0348 .7602793 3.5249474  .54465264
    2012 1.2762 .7602793 2.7663474 -.21394737
    2013  .3713 .7602793 1.8614475 -1.1188474
    2014  .4978 .7602793 1.9879475  -.9923474
    2015  .2991 .7602793 1.7892474 -1.1910474
    2016   .844 .7602793 2.3341475  -.6461474
    end
    
    // Plot
    twoway (line delta30 year, lcolor(black)) ///
    (line upper year, lcolor(gs12) lpattern(dash)) ///
    (line lower year, lcolor(gs12) lpattern(dash)), ytitle(Deltas) ylabel(-2(1)4) ytitle(, size(small) margin(medsmall)) yline(1, lpattern(dash) lcolor(gray)) ylabel(, labsize(vsmall) labgap(medsmall)) xtitle(Year) xlabel(2005(1)2016) xtitle(, size(small) margin(medsmall)) xlabel(, labsize(vsmall) labgap(medsmall)) ///
    legend(off) ///
    title(Figure 2: The time-variation in the stock return sensitivity - All 20 MNAs in the sample, size(small) margin(medsmall)) legend(off)
    The shaded line is the object of interest, while the two dashed grey lines are +/- 2 standard-error bands.

    1. I want to shade the area between the two dashed gray lines in light gray while keeping the line in between those two solid black. Any tips how I can go around doing this?

    2. I'd also like the vertical line from 0 to be solid black.

    Thanks in advance for helping me out.

  • #2
    Code:
    twoway (rarea lower upper year, color(gs15)) ///
    (function y=1, ra(2005 2016) lpattern(dash) lcolor(gray)) ///
    etc
    The second line is a workaround to display the reference line on top of the area plot.

    I don't understand what you mean by "the vertical line from 0", so I can't help you there.

    Comment


    • #3
      Hi Nils

      Thanks for helping out.

      Code works perfect - used it to graph the standard error bands first and plot the black line on top of it; which was my aim.

      About my 2nd question please disregard it....was somewhat of a stupid thing I was trying anyway.

      Thanks again!

      Regards
      Parvesh

      Comment

      Working...
      X