Announcement

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

  • Shading Graphs - Area Plot Tapered

    Hello,

    I am trying to plot a trend line with recessionary periods shaded in grey. Prior posts on this forum address the methods of shading graphs (e.g., https://www.stata.com/statalist/arch.../msg00121.html). These discussions were helpful in creating a graph that nearly does what I want. The problem is that the grey shaded areas are wider on the bottom than on the top. Does anyone know how to make the shaded area have vertical lines perpendicular to the x-axis?

    Here is a snippet of data that shows the issue.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(time recession trend)
    184 0  5.275247
    185 0  5.435284
    186 0  5.782407
    187 0  5.680537
    188 0  5.860635
    189 0  5.696178
    190 0  5.665268
    191 7  5.749439
    192 7   5.69439
    193 7  5.597833
    194 7  5.342285
    195 7  5.042449
    196 7 4.5402293
    197 7 4.2877626
    198 0  3.875503
    199 0  3.930877
    200 0  4.123271
    201 0  4.307055
    202 0  4.420278
    203 0 4.5420003
    end
    format %tq time
    This is the command that generates the graph with the tapered areas.
    Code:
    twoway  (area recession time, color(gs12)) (line trend time, xlab(184(4)203,labsize(small) angle(45)) yscale(range(0 7)) yla(0(1)7) legend(order(2 1) label(1 "Recession") label(2 "Trend")))
    In case it is helpful, I am using Stata/SE 15.1. Thanks.



  • #2
    SJ-16-3 gr0067 . Speaking Stata: Shading zones on time series and other plots
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
    Q3/16 SJ 16(3):805--812 (no commands)
    discusses background shading of time series and other plots

    is a recent survey of this topic. https://www.stata-journal.com/articl...article=gr0067 is a URL. The .pdf version should become visible to all shortly following the Stata Journal's three-year rule.

    Comment


    • #3
      Limit the area graph to just the recession:
      Code:
       ... (area recession time if recession == 7, color(gs12%50)...

      Comment


      • #4
        Thanks to you both for the advice. Nick's Stata Journal article helped me resolve the issue.

        Comment

        Working...
        X