Page 2 of 2

Re: Stepwise rolling regression: plot of coeffiecients

Posted: Thu Aug 25, 2011 3:31 pm
by EViews Gareth
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).

Re: Stepwise rolling regression: plot of coeffiecients

Posted: Thu Aug 25, 2011 3:32 pm
by EViews Gareth
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)

Re: Stepwise rolling regression: plot of coeffiecients

Posted: Thu Aug 25, 2011 3:40 pm
by PCA
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

Re: Stepwise rolling regression: plot of coeffiecients

Posted: Thu Aug 25, 2011 3:41 pm
by EViews Gareth
Could you post your workfile, so I can run the code?

Re: Stepwise rolling regression: plot of coeffiecients

Posted: Thu Aug 25, 2011 3:44 pm
by PCA
Is there an e-mail I can send it to?

Re: Stepwise rolling regression: plot of coeffiecients

Posted: Thu Aug 25, 2011 3:50 pm
by PCA
use y_total as the dependent variable

Re: Stepwise rolling regression: plot of coeffiecients

Posted: Thu Aug 25, 2011 4:00 pm
by EViews Gareth
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.

Re: Stepwise rolling regression: plot of coeffiecients

Posted: Thu Aug 25, 2011 4:22 pm
by PCA
You are amazing. Thank you very much.

Re: Stepwise rolling regression: plot of coeffiecients

Posted: Thu Aug 25, 2011 4:26 pm
by PCA
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?

Stepwise rolling regression: plot of coeffiecients

Posted: Thu Aug 25, 2011 4:51 pm
by EViews Gareth
When you declare your matrix, swap the number of rows and columns, then when you assign into the matrix, swap the positions around.

Re: Stepwise rolling regression: plot of coeffiecients

Posted: Mon Sep 19, 2011 1:39 pm
by PCA
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, .....)?

Re: Stepwise rolling regression: plot of coeffiecients

Posted: Mon Sep 19, 2011 1:52 pm
by EViews Gareth
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.

Re: Stepwise rolling regression: plot of coeffiecients

Posted: Mon Sep 19, 2011 3:11 pm
by PCA
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?

Re: Stepwise rolling regression: plot of coeffiecients

Posted: Mon Sep 19, 2011 3:37 pm
by EViews Gareth
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.