# Last n elements of an EventSeries

Is there a simple way to take an EventSeries (in my case quarterly GDP) and get a new EventSeries consisting of say the last $n$ entries?

This works:

v = GDPQ["ValueList"][];
t = GDPQ["DateList"][];
recdentGDPQ = EventSeries[v[[-11 ;;]], {t[[-11 ;;]]}];


But this does not:

recentGDPQ = GDPQ[[-11;;]]


Is there a simple expression to do this?

• perhaps this might be helpful – user42582 May 7 '18 at 19:32
• EventSeries[GDPQ["Path"][[-11;;]]]? – kglr May 8 '18 at 2:05

It is certainly possible to obtain GDP (quarterly or annual) in an EventSeries nevertheless it seems as slightly counter-intuitive; in what follows we'll use annual GDP figures as returned by evaluating y=CountryData["USA", {{"GDP"}, {1950, 2018}}]; please note that y is a TimeSeries object, therefore we'll first turn it into an EventSeries and then we'll obtain its last eg 10 entries.

In the following code segment, I strip away the Quantity unit and keep only the magnitude from the values but that's just a personal preference; it is not essential to do that for the purpose of this answer.

gdp = EventSeries[QuantityMagnitude[y["Values"]], {y["Times"]}]


Next, using TimeSeriesWindow, we can obtain the desired sample:

DateListPlot[{
TimeSeriesWindow[gdp, {Automatic, AbsoluteTime["1994"]}],
TimeSeriesWindow[gdp, {AbsoluteTime["1995"], Automatic}]
},
PlotLabel -> "US Annual GDP",
PlotLegends -> (
Row[Riffle[#, "-"]] & /@ MapAt[
Reverse,
Transpose[{
DateString[#, {"Year"}] & /@
Through[{First, Last}[gdp["Times"]]],
{1994, 1995}}
], 2])] 