Time Series Functions - Year to Date (YTD) Variations

For notifying us of what you believe are bugs or errors in EViews.
Please ensure your copy of EViews is up-to-date before posting.

Moderators: EViews Gareth, EViews Moderator

fmramos
Posts: 116
Joined: Fri Sep 19, 2008 7:30 am
Location: Sao Paulo / Brazil

Time Series Functions - Year to Date (YTD) Variations

Postby fmramos » Wed May 13, 2009 6:50 am

Hi all!

I don't know if its a problem or a misunderstanding about time series functions (and date functions).

I usually take @pcy, @pc and @movsum to get yoy, 12m acum. sum and mom percentage changes from series.

Now I'd like to get ytd estimates (acum. in the year, until the specific month). I was trying to do @pcy(@movsum(X,@month)) or even (@movsum(X,@month))/(@movsum,X(-12),@month))*100-100, but It's not working.

In fact, If I use @month, I get the months of a series (1,2,...,12), but when used into another TS function, it returns only the last month available (for instance, if the last observation is abril, for all range EV is returning 4 moving sum even for jan, feb,mar,may,...dec).

Tks in advance, Fabio.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13605
Joined: Tue Sep 16, 2008 5:38 pm

Re: Time Series Functions - Year to Date (YTD) Variations

Postby EViews Gareth » Wed May 13, 2009 7:32 am

The @movsum function, and the @pcy function (indeed all such functions) only take a scalar for the second argument, not a series. By passing in @month, you're passing in a series, but the function is only using the first value of that series.

You could try using this:

Code: Select all

series sum=x sum= @recode(@month=1,sum,sum+sum(-1))
instead of @movsum(x,@month). I think the resulting series, sum, should be the year to date average.

fmramos
Posts: 116
Joined: Fri Sep 19, 2008 7:30 am
Location: Sao Paulo / Brazil

Re: Time Series Functions - Year to Date (YTD) Variations

Postby fmramos » Wed May 13, 2009 8:22 am

Pretty good alternative. Tks a lot. I didn't realize that I can use only scalars in TS functions.

So, I'd like to suggest the inclusion of somekind of functions in future versions to complement @pcy, @pca etc TS functions.

Fabio

fmramos
Posts: 116
Joined: Fri Sep 19, 2008 7:30 am
Location: Sao Paulo / Brazil

Re: Time Series Functions - Year to Date (YTD) Variations

Postby fmramos » Wed May 13, 2009 10:45 am

Ooops. I was using the code and I realize that this works only for January and February. To march until December, not.

In fact, Jan=Jan, Feb=Jan+Feb. Mar=Jan+Feb+Mar. Dec=Jan+...+Dec (not only the last two observations).

Do u have any suggestion to change this?!

I adapted your idea and used a succession of recodes (until @month=11) combined with @movsum function. But it seen really dumb. Do u think I have other option (without .prg files and ifs/elses)?!

Tks!

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13605
Joined: Tue Sep 16, 2008 5:38 pm

Re: Time Series Functions - Year to Date (YTD) Variations

Postby EViews Gareth » Wed May 13, 2009 11:08 am

I don't understand what you're saying.

If Jan=Jan
Feb=Jan+Feb
Mar = Jan+Feb+Mar
Dec=Jan+...+Dec

isn't that exactly what you want?

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13605
Joined: Tue Sep 16, 2008 5:38 pm

Re: Time Series Functions - Year to Date (YTD) Variations

Postby EViews Gareth » Wed May 13, 2009 11:51 am

Actually, my code wouldn't work if your workfile didn't start in January, which may be what was causing your problem. I have a better bit of code:

Code: Select all

series sum = @recode(@month=1 or @trend=0,x,x+sum(-1))
I will point out that if your workfile does start in March, say, then for the first year you're not really getting a year to date, you're getting a March-to-date.

fmramos
Posts: 116
Joined: Fri Sep 19, 2008 7:30 am
Location: Sao Paulo / Brazil

Re: Time Series Functions - Year to Date (YTD) Variations

Postby fmramos » Thu May 14, 2009 7:54 am

This last code worked well. Tks. Anyway, I wrote a set of @recodes do avoid creating another series (series 'sum'). It follows below.

If u have an instant idea how could I'd have a better line without creating another series (like the 'sum' one) or I'd appreciate.

As always, tks for yours, Glenns's and Startz's tips.

Code: Select all

@PCY(@RECODE(@MONTH=1,X,@RECODE(@MONTH=2,@MOVSUM(X,2),@RECODE(@MONTH=3,@MOVSUM(X,3),@RECODE(@MONTH=4,@MOVSUM(X,4), @RECODE(@MONTH=5,@MOVSUM(X,5),@RECODE(@MONTH=6,@MOVSUM(X,6),@RECODE(@MONTH=7,@MOVSUM(X,7),@RECODE(@MONTH=8,@MOVSUM(X,8), @RECODE(@MONTH=9,@MOVSUM(X,9),@RECODE(@MONTH=10,@MOVSUM(X,10),@RECODE(@MONTH=11,@MOVSUM(X,11),@MOVSUM(X,12)))))))))))))

fmramos
Posts: 116
Joined: Fri Sep 19, 2008 7:30 am
Location: Sao Paulo / Brazil

Re: Time Series Functions - Year to Date (YTD) Variations

Postby fmramos » Thu May 14, 2009 8:01 am

This last code worked well. Tks. Anyway, I wrote a set of @recodes do avoid creating another series (series 'sum'). It follows below.

If u have an instant idea how could I'd have a better line without creating another series (like the 'sum' one) or I'd appreciate.

As always, tks for yours, Glenns's and Startz's tips.

Code: Select all

@PCY(@RECODE(@MONTH=1,X,@RECODE(@MONTH=2,@MOVSUM(X,2),@RECODE(@MONTH=3,@MOVSUM(X,3),@RECODE(@MONTH=4,@MOVSUM(X,4), @RECODE(@MONTH=5,@MOVSUM(X,5),@RECODE(@MONTH=6,@MOVSUM(X,6),@RECODE(@MONTH=7,@MOVSUM(X,7),@RECODE(@MONTH=8,@MOVSUM(X,8), @RECODE(@MONTH=9,@MOVSUM(X,9),@RECODE(@MONTH=10,@MOVSUM(X,10),@RECODE(@MONTH=11,@MOVSUM(X,11),@MOVSUM(X,12)))))))))))))

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: Time Series Functions - Year to Date (YTD) Variations

Postby EViews Glenn » Thu May 14, 2009 10:32 am

Unless you really are worried about memory use, wouldn't just replacing the original series and deleting the temp be easier?

Code: Select all

series sum = @recode(@month=1 or @trend=0,x,x+sum(-1)) x=sum delete sum

fmramos
Posts: 116
Joined: Fri Sep 19, 2008 7:30 am
Location: Sao Paulo / Brazil

Re: Time Series Functions - Year to Date (YTD) Variations

Postby fmramos » Thu May 14, 2009 1:13 pm

The objective is automatize results. I have a model object that generates the forecasts (indexes). So, I have a group with results (_0 series) and its transformations (yoy, ytd, mom etc). In a group object I always have all the comparisons without any new manipulation. To one or two estimations, ok. But this kind of thing is my daily activity (forecasting economic variables and, after, explaining results x forecasting). The group showed as 'dated data table' is a very useful thing that your team created. Tks.

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: Time Series Functions - Year to Date (YTD) Variations

Postby EViews Glenn » Thu May 14, 2009 2:30 pm

If you are going to want to do this often, just put it in a local subroutine or two (which can be in its own file and referenced using an include, or as in the code below, at the top of the program file). Then call the subroutine. I'm including routines for both the individual series as well as the group.

Code: Select all

' individual series year-to-date subroutine local ytd(series x) series sum = @recode(@month=1 or @trend=0,x,x+sum(-1)) x=sum endsub ' group year-to-date subroutine local grp_ytd(group z) for !i=1 to z.@count call ytd(z(!i)) next ' call group routine group g1 x y z w call grp_ytd(g1)

HRV
Posts: 1
Joined: Wed Aug 03, 2011 8:08 am

Re: Time Series Functions - Year to Date (YTD) Variations

Postby HRV » Wed Aug 03, 2011 8:16 am

I was looking exactly for something like this in order to calculate YTD variations. Probably is too late to post but I found out a simple way to do computation. Just generate a new variable combining to function: cummulative sum and percentage change.

genr YTD=@CUMSUM(@PC(BVL),"1 146")

where the terms quoted is the number of observations. It could be left in blank and the function will use al the sample range.

Hope it could be useful to others!

fmramos
Posts: 116
Joined: Fri Sep 19, 2008 7:30 am
Location: Sao Paulo / Brazil

Re: Time Series Functions - Year to Date (YTD) Variations

Postby fmramos » Wed Aug 03, 2011 10:03 am

Hi,

I think this is not going to work. We are dealing with percentage numbers; they're compounded in geometric terms, not arithmetic ones. Furthermore, my idea of a function is to use it inasmuch as @pcy(@movsum(X,12)); a rolling function. Maybe in a future version, the EV's team could develop something like this.

Yours,

Fabio


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 2 guests