2
$\begingroup$

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"][[1]];
t = GDPQ["DateList"][[1]];
recdentGDPQ = EventSeries[v[[-11 ;;]], {t[[-11 ;;]]}];

But this does not:

recentGDPQ = GDPQ[[-11;;]]

Is there a simple expression to do this?

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

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])]

Blockquote

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.