Announcement

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

  • Graphing positive and negative spells in cyclic series

    I was fooling around with MEI data (https://en.wikipedia.org/wiki/Multivariate_ENSO_index) from here
    http://www.esrl.noaa.gov/psd/enso/mei/table.html

    In essence MEI quantifies the El Niño-La Niña cycle, positive values flagging El Niño and negative values flagging La Niña.

    Once reshaped from their idiosyncratic dataset structure, which has its own logic, I created this graph, which might interest some on various grounds, perhaps especially people working with economic or financial data going up and down in irregular but definite cycles.
    Click image for larger version

Name:	mei.png
Views:	2
Size:	20.4 KB
ID:	1330029






    The main trick is to separate the time series into positive or negative variables (or more generally, values above and below some reasonable reference level).

    Code:
    separate MEI, by(MEI>=0)
    gen zero = 0
    twoway rarea MEI1 zero mdate, color(red*0.8) cmissing(no) || rarea MEI0 zero mdate, color(blue*0.8) cmissing(no) legend(off) ytitle(MEI) yla(, ang(h)) xla(`=ym(1950, 1)'(120)`=ym(2010,1)') xtitle("") aspect(0.5)
    I am not normally especially fond of area graphs, but I thought this one worth sharing.

    Note: In this case twoway area could be used directly, as the default of zero as the base is exactly what is needed. But the code above is easy to extend to other cases. Alternatively, use twoway area with base().
    Attached Files
    Last edited by Nick Cox; 09 Mar 2016, 07:38.

  • #2
    I can see this being very useful for some of my time series graphs. Thanks for sharing!

    Comment

    Working...
    X