Naming variable question

For questions regarding programming in the EViews programming language.

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

miorinnovo
Posts: 199
Joined: Sun Mar 01, 2015 5:01 pm

Naming variable question

Postby miorinnovo » Tue Jun 18, 2019 12:46 pm

Hi,

Is there a way to name a variable something different depending on when the sample ends? I have an expanding sample and I'd like to rename my variable some thing based on what month it is relative to the quarter. So all Januarys, Aprils, Julys and Octobers would be X_1 because they are the first month of a quarter. Then X_2 would be February, May, August and November, etc.

Thanks!

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

Re: Naming variable question

Postby EViews Matt » Tue Jun 18, 2019 2:42 pm

Hello,

You can certainly calculate the correct month-of-the-quarter defined by the end of a sample, e.g., the current sample,

Code: Select all

!q = @mod(@datepart(@dateval(@word(@pagesmpl, 2)), "mm") - 1, 3) + 1
series x_!q = ...

miorinnovo
Posts: 199
Joined: Sun Mar 01, 2015 5:01 pm

Re: Naming variable question

Postby miorinnovo » Wed Jun 19, 2019 10:25 am

Thanks Matt. I think your solution would work in the case of doing them all at once. What I'm looking to do is find the rmse of a model with mixed frequencies. So I thought I could create different variables for the forecast depending on how many months are known as the forecasts are made in an expanding window.

Edit: Is there a way to calculate the RMSE of select observations in a series? that would be another way to get at what i want.

Thanks!

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

Re: Naming variable question

Postby EViews Matt » Wed Jun 19, 2019 11:47 am

Perhaps the simple solution is to perform the RMSE calculation explicitly, using either the current sample, e.g.,

Code: Select all

@sqrt(@sumsq(x - x_f) / @obs(x_f))

or an explicit sample, e.g.,

Code: Select all

@sqrt(@sumsq(x - x_f, "<sample>") / @obs(x_f, "<sample>"))

to specify the observations you're considering.

miorinnovo
Posts: 199
Joined: Sun Mar 01, 2015 5:01 pm

Re: Naming variable question

Postby miorinnovo » Wed Jun 19, 2019 12:06 pm

Yes this would be good. I suppose I could just create a sample for all first months, second months and third months. like this:

sample firstmonths = 2010m1 2010m4 2010m7 2010m10 2011m1 etc...

unless theres a quicker way?

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

Re: Naming variable question

Postby EViews Matt » Wed Jun 19, 2019 12:49 pm

How about,

Code: Select all

sample firstmonths @all if @mod(@month, 3) = 1
sample secondmonths @all if @mod(@month, 3) = 2
sample thirdmonths @all if @mod(@month, 3) = 0

miorinnovo
Posts: 199
Joined: Sun Mar 01, 2015 5:01 pm

Re: Naming variable question

Postby miorinnovo » Wed Jun 19, 2019 1:09 pm

I'm not sure thats working, but thinking about it its not a good solution anyway because the forecasted variable is quarterly, so I need to have a forecast for each month of the quarter in quarter frequency. In other words, I'm back to needing to be able to name my forecasted variable something different depending on how many months of data i have.

Maybe I can get around this with an if function?

is it possible to turn something like following into code

if the date is a first month
series xfirstmonth=x
if the date is a second month
series xsecondmonth=x

etc

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

Re: Naming variable question

Postby EViews Matt » Thu Jun 20, 2019 9:46 am

Would not a variation of my first response work then?

miorinnovo
Posts: 199
Joined: Sun Mar 01, 2015 5:01 pm

Re: Naming variable question

Postby miorinnovo » Thu Jun 20, 2019 11:09 am

I dont understand what that answer does. I tried plugging it in and it just gives me a copy of the same series

!q = @mod(@datepart(@dateval(@word(@pagesmpl, 2)), "mm") - 1, 3) + 1
series x_!q = ...

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

Re: Naming variable question

Postby EViews Matt » Thu Jun 20, 2019 1:13 pm

I believe I'm not understanding what you're trying to achieve. Could you provide a more detailed description and perhaps an example?

miorinnovo
Posts: 199
Joined: Sun Mar 01, 2015 5:01 pm

Re: Naming variable question

Postby miorinnovo » Fri Jun 21, 2019 8:56 am

Yes of course.

I want to write a program with a simple model y= c+Bx. My y is quarterly and my x is monthly. Lets say I have data for January 2019 for x. I want to fill in February and March in some way in order to have a full Q1 that can be used to forecast my y. I also want to be able to do this when I get February data for x, and March etc. To calculate the RMSE of an expanding window I usually just create the forecast and copy it to a new series so that I have a series of one period ahead forecasts. This works when I'm dealing with only quarterly data. But the fact that I'm working with mixed frequencies makes this more difficult. I want to know what the RMSE of my model is at different points in the quarter.

IS that a bit clearer?

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

Re: Naming variable question

Postby EViews Gareth » Fri Jun 21, 2019 10:05 am

That seems entirely unrelated to your original question, which was about naming series?
Follow us on Twitter @IHSEViews

miorinnovo
Posts: 199
Joined: Sun Mar 01, 2015 5:01 pm

Re: Naming variable question

Postby miorinnovo » Fri Jun 21, 2019 11:32 am

EViews Gareth wrote:That seems entirely unrelated to your original question, which was about naming series?


Not at all. My original question was about naming the series something different depending on how much data there is in order to separate the 0th months, first months and second months in order to calculate the rmses of each point in the quarter. I just gave more background as to what I'm trying to do.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 22 guests