Scalar of average of last 12 months

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt

BCNAV
Posts: 40
Joined: Tue Oct 31, 2017 9:06 am

Scalar of average of last 12 months

Postby BCNAV » Wed Jul 11, 2018 9:35 am

I have a work file from 2011M01 to 2018M12

The last date I have data for is 2018M06.

I need a away to automatically calculate the average of a variable over the last 12 months and dump it into a scalar.

I had tried smpl @last-12 @last but that does not work, as it does to the end of the workfile that has no data in it (data only does to june 2018).

Is there a way to get the last non-missing data point date (june 2018 in this case), have that be the end point, and then subtract 12 from it to get to the start?

for example

smpl date of last data point minus 12 date of last data point
scalar test = @mean(data)
smpl @all

startz
Non-normality and collinearity are NOT problems!
Posts: 3775
Joined: Wed Sep 17, 2008 2:25 pm

Re: Scalar of average of last 12 months

Postby startz » Wed Jul 11, 2018 9:57 am

See if @movav helps.

EViews Matt
EViews Developer
Posts: 557
Joined: Thu Apr 25, 2013 7:48 pm

Re: Scalar of average of last 12 months

Postby EViews Matt » Wed Jul 11, 2018 10:05 am

Hello,

Something along this line should work,

Code: Select all

%tmp = @datestr(@dateadd(@dateval(data.@last), -11, "MM")) + " " + data.@last
smpl %tmp
scalar test = @mean(data)
smpl @all


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 15 guests