That's my fault. In both places, %pos should be !pos (since it is an integer, not a string).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.
Stepwise rolling regression: plot of coeffiecients
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
-
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
Keep my coding the same, but add a bit that inserts the constant. Something like: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
Code: Select all
coefs[1,!i) = eq1.@coef(1)
Re: Stepwise rolling regression: plot of coeffiecients
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?
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
Could you post your workfile, so I can run the code?
Re: Stepwise rolling regression: plot of coeffiecients
Is there an e-mail I can send it to?
Re: Stepwise rolling regression: plot of coeffiecients
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
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:
or
(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:
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.
Code: Select all
!pos = @wfind(@upper(%fullregs), %reg)
Code: Select all
!pos = @wfindnc(%fullregs, %reg)
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
You are amazing. Thank you very much.
Re: Stepwise rolling regression: plot of coeffiecients
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
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
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
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.
You could use a table rather than a matrix though.
Re: Stepwise rolling regression: plot of coeffiecients
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
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:
note that the !i+1 means that the labels start in the second column.
Code: Select all
table coefs
for !i=1 to @wcount(%fullregs)
coefs(1,!i+1) = @word(%fullregs,!i)
next
Who is online
Users browsing this forum: No registered users and 2 guests
