Stepwise rolling regression: plot of coeffiecients

For questions regarding programming in the EViews programming language.

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

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

Re: Stepwise rolling regression: plot of coeffiecients

Postby EViews Gareth » Thu Aug 25, 2011 3:31 pm

Still trying to work through this. It's giving me the following error:

"scalar assigned to string in "%POS = @WFIND("_10YR CPI DURATION GOLD HY_SPREAD IG_SPREAD M1 MOVE OIL TEDSPREAD VIX YIELDCURVESLOPE", "_10YR")

I'm not sure if I implemented your coding right. Still trying to decipher it a bit.
That's my fault. In both places, %pos should be !pos (since it is an integer, not a string).

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

Re: Stepwise rolling regression: plot of coeffiecients

Postby EViews Gareth » Thu Aug 25, 2011 3:32 pm

And actually, I need to know the constant, so does that alter the coding you provided at all?

%chosenregs = @wmid(%chosenregs, 3) 'drop off y and C from the varlist

and

!nn = !n+1 'plus one because we don't care about C
Keep my coding the same, but add a bit that inserts the constant. Something like:

Code: Select all

coefs[1,!i) = eq1.@coef(1)

PCA
Posts: 24
Joined: Thu Aug 25, 2011 11:50 am

Re: Stepwise rolling regression: plot of coeffiecients

Postby PCA » Thu Aug 25, 2011 3:40 pm

Alright. I think there is something wrong with the matrix position, but I'm not sure. I am getting "(1,0) is not a valid index for matrix COEFS in "COEFS(1,0)=-.59095.....""

Thoughts?

Code: Select all

workfile riskvariables_eviews q 1990q1 2011q2 'group riskvariables 'run rolling regression ' set window size !window = 20 ' set step size !step = 1 ' get size of workfile !length = @obsrange ' declare equation for estimation equation eq2 'string of variables %fullregs = "_10yr cpi duration gold hy_spread ig_spread m1 move oil tedspread vix yieldcurveslope" 'calculate number of rolls !nrolls = @round((!length-!window)/!step) 'matrix to store coefficient estimates matrix(13,!nrolls) coefs' where 13 is the number of coefficients '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+!i-1 @first+!i+!window-2 ' estimate equation 'eq2.stepls(METHOD=UNI,BTOL=2,BACK,TSTAT) y c @ _10yr cpi duration gold hy_spread ig_spread m1 move oil tedspread vix yieldcurveslope 'after this inside your loop equation eq2.stepls(METHOD=UNI,BTOL=2,BACK,TSTAT) y c @ {%fullregs} %chosenregs = eq2.@varlist %chosenregs = @wmid(%chosenregs, 3) 'drop off y and C from the varlist for !n = 1 to @wcount(%chosenregs) %reg = @word(%chosenregs, !n) !nn = !n+1 'plus one because we don't care about C !coef = eq2.@coefs(!nn) coefs(1,!i) = eq2.@coef(1) !pos = @wfind(%fullregs, %reg) coefs(!i, !pos) = !coef next next

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

Re: Stepwise rolling regression: plot of coeffiecients

Postby EViews Gareth » Thu Aug 25, 2011 3:41 pm

Could you post your workfile, so I can run the code?

PCA
Posts: 24
Joined: Thu Aug 25, 2011 11:50 am

Re: Stepwise rolling regression: plot of coeffiecients

Postby PCA » Thu Aug 25, 2011 3:44 pm

Is there an e-mail I can send it to?

PCA
Posts: 24
Joined: Thu Aug 25, 2011 11:50 am

Re: Stepwise rolling regression: plot of coeffiecients

Postby PCA » Thu Aug 25, 2011 3:50 pm

use y_total as the dependent variable
Attachments
riskvariables_eviews.wf1
(43.28 KiB) Downloaded 417 times

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

Re: Stepwise rolling regression: plot of coeffiecients

Postby EViews Gareth » Thu Aug 25, 2011 4:00 pm

Problem is that %reg is in upper case, and %fullregs is in lower case, so it cannot find %reg in %fullregs. To fix it change that line to:

Code: Select all

!pos = @wfind(@upper(%fullregs), %reg)
or

Code: Select all

!pos = @wfindnc(%fullregs, %reg)
(or, alternatively, enter %fullregs in upper case)

I spotted another error, also. The way you've defined your coef matrix is that the iterations are long the columns, but my code inserts them by row. You need to change that insertion line to be:

Code: Select all

coefs(!pos, !i) = !coef

Finally, you'll get a problem where you run out of observations in the final part of your roll. You'll have to figure out how you want to handle that.

PCA
Posts: 24
Joined: Thu Aug 25, 2011 11:50 am

Re: Stepwise rolling regression: plot of coeffiecients

Postby PCA » Thu Aug 25, 2011 4:22 pm

You are amazing. Thank you very much.

PCA
Posts: 24
Joined: Thu Aug 25, 2011 11:50 am

Re: Stepwise rolling regression: plot of coeffiecients

Postby PCA » Thu Aug 25, 2011 4:26 pm

Now I'm trying to figure out how to rearrange my matrix so that the rows and columns are transposed (how you assumed they were, so explanatory variables are the columns). Which aside from the lines referring to the matrix, which other ones need to be altered?

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

Stepwise rolling regression: plot of coeffiecients

Postby EViews Gareth » Thu Aug 25, 2011 4:51 pm

When you declare your matrix, swap the number of rows and columns, then when you assign into the matrix, swap the positions around.

PCA
Posts: 24
Joined: Thu Aug 25, 2011 11:50 am

Re: Stepwise rolling regression: plot of coeffiecients

Postby PCA » Mon Sep 19, 2011 1:39 pm

Hopefully you (Gareth) remember this program. Do you know how I can get the names of the explanatory names to show up in the Matrix (as opposed to R1, R2, R3, .....)?

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

Re: Stepwise rolling regression: plot of coeffiecients

Postby EViews Gareth » Mon Sep 19, 2011 1:52 pm

Matrices cannot contain characters, nor can you assign labels to the columns or rows, so there is no way to do that.

You could use a table rather than a matrix though.

PCA
Posts: 24
Joined: Thu Aug 25, 2011 11:50 am

Re: Stepwise rolling regression: plot of coeffiecients

Postby PCA » Mon Sep 19, 2011 3:11 pm

Alright, I've switched it around so it is pumping all of the coefficients into a table. How do I program the table to automatically populate labels for the rows and columns?

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

Re: Stepwise rolling regression: plot of coeffiecients

Postby EViews Gareth » Mon Sep 19, 2011 3:37 pm

Not quite sure what you want to populate them with, or how you want to do it. But, say you want to put the list of variables along the top:

Code: Select all

table coefs for !i=1 to @wcount(%fullregs) coefs(1,!i+1) = @word(%fullregs,!i) next
note that the !i+1 means that the labels start in the second column.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests