series transformation using @recode

For questions regarding the import, export and manipulation of data in EViews, including graphing and basic statistics.

Moderators: EViews Gareth, EViews Steve, EViews Moderator, EViews Jason

DBel2012
Posts: 69
Joined: Sun Sep 30, 2012 5:37 am

series transformation using @recode

Postby DBel2012 » Mon Sep 30, 2013 4:23 am

Good morning,

I'm currently using Eviews 7.

I've got a quarterly time series, say varX, that I want to transform in the following way :

if first quarter then varX_C=varX
if second quarter then varX_C = mean of qarter 1 and 2
if third quarter then varX_C = mean of qarter 1, 2 and 3
if fourth quarter then varX_C = mean of qarter 1, 2, 3 and 4

Here is what I'v came up with :

series varX_C = @recode( @quarter=1, varX, @recode( @quarter=2,( varX + varX(-1) )/2, _
@recode( @quarter=3,( varX + varX(-1) + varX(-2) )/3, _
( varX + varX(-1) + varX(-2) + varX(-3) )/4) )
)

Even though this formula works fine, I was wondering if there is a more elegant way of computing varX_C ?

Thanks!

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

Re: series transformation using @recode

Postby EViews Glenn » Mon Sep 30, 2013 9:27 am

There may be a better way, but this should work if your workfile/sample starts in the first quarter.

Code: Select all

series anncumulative = @recode(@quarter=1, y, anncumulative(-1)+y(-1)) series ystar = @meansby(anncumulative, @quarter)
If we had a year-to-date function (we've added it to the list) this would be easier.

DBel2012
Posts: 69
Joined: Sun Sep 30, 2012 5:37 am

Re: series transformation using @recode

Postby DBel2012 » Tue Oct 01, 2013 4:35 am

I like the code you posted.

Many thanks Glenn!

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

Re: series transformation using @recode

Postby EViews Glenn » Tue Oct 01, 2013 10:04 am

It would be good if I posted correct code.

Code: Select all

series anncumulative = @recode(@quarter=1, y, anncumulative(-1)+y)
The last element on the first line should be Y, not Y(-1).


Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 1 guest