Page 1 of 1

Rolling Multiple Regression

Posted: Fri Aug 22, 2014 1:29 pm
by hedgie
I'm trying to run a rolling multiple regression for 52 weeks for the last 10 years. I've looked up the forum and was able to put together a code to generate and store the rolling r2. However, my r2 vector is giving me the same r2 at every point in time. The code is below - can you please suggest any changes required? Thanks

' set window size
!window = 52

' set step size
!step = 1

' get size of workfile
!length = @obsrange

' declare equation for estimation
equation eq01

'calculate number of rolls
!nrolls = @floor((!length-!window)/!step)

'vector to store r2s
vector(!nrolls) r2s

' variable keeping track of how many rolls we've done
!j=0

' move sample !step obs at a time
for !i = 1 to !length-!window+1-!step step !step
!j=!j+1

' set sample to estimation period
smpl @first @first+!i+!window-2

'store r2s in vector
r2s(!i) = eq01.@r2

next

Re: Rolling Multiple Regression

Posted: Fri Aug 22, 2014 1:44 pm
by EViews Gareth
You're not estimating your equation anywhere.

Re: Rolling Multiple Regression

Posted: Fri Aug 22, 2014 1:56 pm
by hedgie
Thank you. I added the below and it works fine

' estimate equation
eq01.ls log(y) c log(x) log(y)

Question: Given that I already have eq01 in the workfile, is there a way for me to reference the equation in the workfile instead of manually inputting the entire equation in the program?

Re: Rolling Multiple Regression

Posted: Mon Aug 25, 2014 10:03 am
by hedgie
Given that I already have eq01 in the workfile, is there a way for me to reference the equation in the workfile instead of manually inputting the entire equation in the program?

I also have a matrix with 3 columns and would like to store regression coefficients in the columns (instead of rows that are in the code example). Any suggestions on the code below? I tried rowplace instead of columnplace but that didn't seem to work.

store coefficients in matrix
colplace(coeffs,eq01.@coefs,!j)

Re: Rolling Multiple Regression

Posted: Mon Aug 25, 2014 10:43 am
by EViews Gareth
You can grab the command string of the existing equation (equation.@command) and use that to re-estimate it as is.

Use rowplace with the transpose of the coefficient vector.

Re: Rolling Multiple Regression

Posted: Fri Sep 05, 2014 8:39 am
by hedgie
Sorry, don't follow. Can you please show an example?
"You can grab the command string of the existing equation (equation.@command) and use that to re-estimate it as is."

I also tend to get this error message quite often when I run the regression: "Near singular matrix error. Regressors may be perfectly collinear." Not sure why I'm getting this, even if the r2s are 1. Is this a bug in EViews?

Re: Rolling Multiple Regression

Posted: Fri Sep 05, 2014 9:00 am
by startz
Thank you. I added the below and it works fine

' estimate equation
eq01.ls log(y) c log(x) log(y)
Do you really want to be regressing log(y) on log(y)?

Re: Rolling Multiple Regression

Posted: Fri Sep 05, 2014 9:38 am
by EViews Gareth

Code: Select all

%cmd = eq01.@command eq01.{%cmd}

Re: Rolling Multiple Regression

Posted: Fri Sep 05, 2014 10:24 pm
by hedgie
Thank you. I added the below and it works fine

' estimate equation
eq01.ls log(y) c log(x) log(y)
Do you really want to be regressing log(y) on log(y)?
That's a typo in the example - its log(z) or any other variable.

A lot of other equations give me the same error message. "Near singular matrix error. Regressors may be perfectly collinear." I also get this error in certain equations when testing for stability using the Quandt-Andrews Breakpoint test

Re: Rolling Multiple Regression

Posted: Sat Sep 06, 2014 7:55 am
by startz
The near singular matrix error almost always indicates user error, but the only way to see for sure is to look at the equation and data that causes it. You might want to post an EViews workfile together with an equation that causes the error.

Re: Rolling Multiple Regression

Posted: Mon Nov 03, 2014 12:34 pm
by hedgie
Attached is the EViews workfile and the rolling regression programs for the two equations in the workfile. You'll see that in both models, once you start running the rolling regression program, you get the message "Near singular matrix error. Regressors may be perfectly collinear." I'm not sure why this error shows - I have noticed that if an equation has a high r2, this error tends to be more frequent.

Re: Rolling Multiple Regression

Posted: Mon Nov 03, 2014 1:03 pm
by EViews Gareth
The most likely cause is just as the error message indicates - your regressors are perfectly colinear.

Re: Rolling Multiple Regression

Posted: Mon Nov 03, 2014 1:33 pm
by hedgie
Is dropping one of the regressors the only option? Notice that for model1, the rolling regression runs a number 30odd iterations and on the 31st gives the error. I don't get this error message when I run it on the entire sample, just over a fixed period window.

Re: Rolling Multiple Regression

Posted: Mon Nov 03, 2014 2:01 pm
by EViews Gareth
Which just means that they are colinear over 31st sample, but not over the whole sample.

Yes dropping a regressor is the only solution.