getting variable names from stepwise regression

For questions regarding programming in the EViews programming language.

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

Sophronius
Posts: 3
Joined: Thu Feb 13, 2014 1:09 pm

getting variable names from stepwise regression

Postby Sophronius » Thu Feb 13, 2014 1:46 pm

Hey,

I am using eviews 7 for my master thesis to try and find a way to forecast exchange rates using a variety of factors. I do this by using rolling regressions on one variable at a time by means of a For loop with a rolling window that moves forward one month at a time. I then forecast the future exchange rate each month by calculating C(0) + C(1) * most recent variable value (as part of the loop, so it's automated as well), which gives me a time series with predictions for each month once the program has finished running. So far so good. Next, I try to improve on the result by using backwards stepwise regression to automatically select a combination of significant variables each month instead of choosing one variable at a time and checking for significance manually. The problem is that by getting the program to select the significant variables in this way, I don't know which variables are actually used each month, so I can't refer back to these variables within the For loop. I need a function that returns the variables used in each equation of the rolling regression so I can use them in the above formula to make predictions. However, @varlist only returns a string, which doesn't help me any. On the other hand, if I write something like "genr C2_stepwise{%S}{%N}(23) = eq{!J}.c(1)", then I have the first factor coefficient, but I still don't know which variable value I should multiply the coefficient with since I don't know which variables were selected.

Can anyone tell me if there is a good way to do this? Or do I have to scratch the whole idea? Below is the code for my stepwise rolling regression, if that helps.

Code: Select all

for %N _1m _3m _12m for %S _eur _jap _uk FOR !J = 1 to 145 smpl 1995M11+!J 1997M10+!J equation eq{!J}.stepls(back,COV=HAC) exp{%S}{%N} @ c int_dif{%S}{%N} m_dif{%S} m_dif2{%S}{%N} tb_gdp{%S} tb_gdp_us cpi_dif{%S} genr varlist{%S}{%N} = eq{!J}.@varlist delete eq{!J} next next next
And the original (regular LS) program, just in case:

Code: Select all

%M = "_uip" %Y = "exchange_dif" %X = "int_dif" (I change the variable each time I run the program) for %N 1 3 12 for %S _eur _jap _uk FOR !J = 1 to 145 smpl 1995M11+!J 1997M10+!J equation eq{!J}.ls(COV=HAC) {%Y}{%S}_{%N}m c {%X}{%S}_{%N}m genr forecast{%M}{%S}_{%N}m(22+!J) = eq{!J}.c(1) + eq{!J}.c(2) * {%X}{%S}_{%N}m(22+!J+{%N}) delete eq{!J} next next next
Any help is appreciated!

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

Re: getting variable names from stepwise regression

Postby EViews Gareth » Thu Feb 13, 2014 2:54 pm

I don't see why @varlist doesn't do what you want.

Sophronius
Posts: 3
Joined: Thu Feb 13, 2014 1:09 pm

Re: getting variable names from stepwise regression

Postby Sophronius » Fri Feb 14, 2014 2:32 am

Because if I use @varlist, it returns something like "EXP_EUR_12M CPI_DIF_EUR TB_GDP_EUR TB_GDP_US C M_DIF2_EUR_12M M_DIF_EUR", which is a single string containing all the variable names. That would be fine if all I wanted was to look at the variables after the fact, but the fact is that I want to refer back to the time series with these names using the program. The issue is that within the same loop that calculates the equations, I want to then calculate "Genr Forecast = C(1) + C(2) * var(1) + C(3) * var(2) + C(4) * var(3) + C(5) * var(4) + C(6) * var(5) + C(2) * var(6)". However, some of the months var(3) will be TB_GDP_EUR, another month var(3) will be M_DIF2_EUR_12M, and yet another month there won't be a var(3) at all because stepwise regression only selected 1 or 2 variables. So I can't use the same formula for each equation. Rather, I need to rewrite the formula in such a way that I can literally refer to the first, second, third and so on variables used in each equation, so it literally multiplies the first coefficient with the first variable that is used, whichever variable that is. And that means I need a function that returns the Xth variable used in the equation, so I can write something like "Genr Forecast = C(1) + C(2) * eq{!J}.@varlist(1) + C(3) * eq{!J}.@varlist(2) + C(4) * eq{!J}.@varlist(3) + ... + ...". But @varlist doesn't do that, it only returns a single string containing all of the variable names, so that doesn't work.

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

Re: getting variable names from stepwise regression

Postby EViews Gareth » Fri Feb 14, 2014 8:39 am

Apart from the fact I can't see why you're not just using the built in forecast from the equation, you can use the @word function to get the ith element of a string list.

Sophronius
Posts: 3
Joined: Thu Feb 13, 2014 1:09 pm

Re: getting variable names from stepwise regression

Postby Sophronius » Mon Feb 17, 2014 6:19 am

Aha! I did not realize it was a string list, I thought it was just a single string. @word worked, thanks a lot!

I have checked the eviews forecast function, but it returns different values from what I calculated using my formula. Would you say that the eviews forecast is better? Could you perhaps direct me to an explanation regarding how Eviews forecasts are generated, exactly?

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

Re: getting variable names from stepwise regression

Postby EViews Gareth » Mon Feb 17, 2014 8:12 am

The User Guide has good descriptions.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest