Rolling Multiple Regression
Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt
Rolling Multiple Regression
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
' 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
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13318
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Rolling Multiple Regression
You're not estimating your equation anywhere.
Follow us on Twitter @IHSEViews
Re: Rolling Multiple Regression
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?
' 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
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)
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)
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13318
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Rolling Multiple Regression
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.
Use rowplace with the transpose of the coefficient vector.
Follow us on Twitter @IHSEViews
Re: Rolling Multiple Regression
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?
"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?
-
- Non-normality and collinearity are NOT problems!
- Posts: 3775
- Joined: Wed Sep 17, 2008 2:25 pm
Re: Rolling Multiple Regression
hedgie wrote: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)?
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13318
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Rolling Multiple Regression
Code: Select all
%cmd = eq01.@command
eq01.{%cmd}
Follow us on Twitter @IHSEViews
Re: Rolling Multiple Regression
startz wrote:hedgie wrote: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
-
- Non-normality and collinearity are NOT problems!
- Posts: 3775
- Joined: Wed Sep 17, 2008 2:25 pm
Re: Rolling Multiple Regression
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
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.
- Attachments
-
- rolling regression fixed window m2.prg
- (1.44 KiB) Downloaded 534 times
-
- rolling regression fixed window m1.prg
- (1.44 KiB) Downloaded 418 times
-
- Near Singular Matrix Error Sample.wf1
- (38.59 KiB) Downloaded 317 times
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13318
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Rolling Multiple Regression
The most likely cause is just as the error message indicates - your regressors are perfectly colinear.
Follow us on Twitter @IHSEViews
Re: Rolling Multiple Regression
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.
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13318
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Rolling Multiple Regression
Which just means that they are colinear over 31st sample, but not over the whole sample.
Yes dropping a regressor is the only solution.
Yes dropping a regressor is the only solution.
Follow us on Twitter @IHSEViews
Who is online
Users browsing this forum: No registered users and 57 guests