Stepwise rolling regression: plot of coeffiecients
Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt
Stepwise rolling regression: plot of coeffiecients
I have a stepwise rolling regression. For every subsample Ican have a different number of significant parameters. It is easy to get the calculation but my question now is how I can store the coefficients ( of the different equations) so, that I am able to plot a chart for the whole time period for every single coefficient (e.g. alpha, beta 1, beta 2 etc.).

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12384
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Stepwise rolling regression: plot of coeffiecients
Unfortunately this is not possible in the stepwise routine included in EViews (the main reason being that the stepwise routines doesn't actually calculate and/or store the coefficients). However you can always write your own stepwise routine and store them.
As a guide, here is a simple manual stepwise routine I wrote a while back:
As a guide, here is a simple manual stepwise routine I wrote a while back:
Code: Select all
'create some data  20 X variables and a Y variable that depends upon X11X15.
'X variables are put into a group called XS
create u 1000
rndseed 1
group xs
group g
for !i=1 to 20
series x!i=nrnd
%name="x"+@str(!i)
xs.add {%name}
g.add {%name}
next
series y = nrnd + 3
for !i=11 to 15
y = y + !i*x{!i}
next
'perform backwards stepwise regression  first run a model with all Xs, then remove Xs one at a time based upon tstat.
equation e1
!tstop=5
!stop=0
while !stop=0
e1.ls y c xs
!mint=10000
!removedvar=0
for !i=1 to xs.@count
!currentt = @abs(e1.@tstats(!i+1)) 'note plus one is since the equation has a constant as the first variable, but we are not testing the constant
if !currentt < !mint then
!mint = !currentt
!removedvar=!i
endif
next
if !mint>!tstop then
!stop=1
else
if !removedvar>0 then
%removedvarname=xs.@seriesname(!removedvar)
xs.drop {%removedvarname}
endif
endif
wend
show e1
'run an automatic stepwise and see if it matches
equation e2.stepls(METHOD=UNI,BTOL=5,BACK,TSTAT) y c @ g
show e2
Follow us on Twitter @IHSEViews
Re: Stepwise rolling regression: plot of coeffiecients
Thanks a lot for your answer. But I mean the values for the significant variable are calculated as observabe in the tables and the ones not included could simply be set to zero. Isn't there a possibility to save these values (just the ones included in the regression) and to recognize for each value to which variable it belongs. Sorry for asking again ..

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12384
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Stepwise rolling regression: plot of coeffiecients
You can use the @coefs datamember of the equation to store the chosen coefficients into a vector. If you wanted, you could then place that vector into a row/column of a matrix to store all of your "rolls" as one big matrix.
Follow us on Twitter @IHSEViews
Re: Stepwise rolling regression: plot of coeffiecients
Could you elaborate on storing the coefficients for a stepwise regression?
I am running a very similar regression, and for example, sometimes the stepwise procedure will keep 3 explanatory variables, and sometimes it will keep 8. I think that this anomaly messes with the matrix setup I have.
I am new to programming, so I know for a fact I am not setting up the matrix properly. Could you lend a hand?
I'm using eViews 7.
I am running a very similar regression, and for example, sometimes the stepwise procedure will keep 3 explanatory variables, and sometimes it will keep 8. I think that this anomaly messes with the matrix setup I have.
I am new to programming, so I know for a fact I am not setting up the matrix properly. Could you lend a hand?
I'm using eViews 7.
Code: Select all
workfile riskdata_eviews q 1990q1 2011q2
'run rolling regression
' set window size
!window = 20
' set step size
!step = 1
' get size of workfile
!length = @obsrange
' declare equation for estimation
equation eq1
'calculate number of rolls
!nrolls = @round((!length!window)/!step)
'matrix to store coefficient estimates
matrix(13,!nrolls) coefmat ' 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+!i1 @first+!i+!window2
' estimate equation
eq1.stepls(METHOD=step,BTOL=2,BACK,TSTAT) y c @ _10yr cpi duration gold hy_spread ig_spread m1 move oil tedspread vix yieldcurveslope
'store coefficients
colplace(coefmat,eq1.@coefs,!j)
next
show coefmat

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12384
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Stepwise rolling regression: plot of coeffiecients
Yeah, that's going to be problematic. From a conceptual point of view, how do you want to store the coefficients?
Follow us on Twitter @IHSEViews
Re: Stepwise rolling regression: plot of coeffiecients
What I would like is a column for each explanatory variable, and a row for each "regression roll".
Is there anyway to possible store each coefficient into its own vector? That way if it is excluded from the model based on tstat or pvalue, then it would just say NA for that particular regression?
Is there anyway to possible store each coefficient into its own vector? That way if it is excluded from the model based on tstat or pvalue, then it would just say NA for that particular regression?

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12384
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Stepwise rolling regression: plot of coeffiecients
That's going to be very tricky, because you need to keep track of which variables were kept, and their position in the original list (i.e. if only MOVE, OIL, VIX are kept, you need to know to fill in the 9, 10, and 12th elements of the matrix).
Follow us on Twitter @IHSEViews
Re: Stepwise rolling regression: plot of coeffiecients
Exactly. That is why I was wondering if it is possible to store every coefficient in a separate vector. Or somehow store each equation in its own matrix, and then combine them after the fact?

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12384
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Stepwise rolling regression: plot of coeffiecients
Sure, you can store every equation's coefficients in their own vector, just by doing something like:
immediately after you've performed the stepls. You're going to end up with a bunch of vectors with different lengths, but it will work.
Code: Select all
vector coefs!i = eq1.@coefs
immediately after you've performed the stepls. You're going to end up with a bunch of vectors with different lengths, but it will work.
Follow us on Twitter @IHSEViews
Re: Stepwise rolling regression: plot of coeffiecients
Yeah, a little cumbersome, but it does works.
Ideally though, I'd like a fully filled matrix. I know you said it's very tricky, but is it even feasible you think?
Ideally though, I'd like a fully filled matrix. I know you said it's very tricky, but is it even feasible you think?

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12384
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Stepwise rolling regression: plot of coeffiecients
Currently I'm going to say no
Follow us on Twitter @IHSEViews

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12384
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Stepwise rolling regression: plot of coeffiecients
Actually, I take that back.
Theoretically you could do the following....
So something, very roughly, equal to:
Theoretically you could do the following....
 Use equation.@varlist to return a string containing the list of regressors that were chosen by the stepwise procedure
 Loop through the elements of that string one at a time, and find their position in the original list of regressors using @wfind
 Copy the coefficient associated with that regressor into the corresponding position in the original matrix
So something, very roughly, equal to:
Code: Select all
%fullregs = "u v w y z"
matrix(5, !nrolls) coefs
'after this inside your loop
equation eq1.stepls y c @ {%fullregs}
%chosenregs = eq1.@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 = eq1.@coefs(!nn)
%pos = @wfind(%fullregs, %reg)
coefs(!i, %pos) = !coef
next
Follow us on Twitter @IHSEViews
Re: Stepwise rolling regression: plot of coeffiecients
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.
"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.
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+!i1 @first+!i+!window2
' 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)
%pos = @wfind(%fullregs, %reg)
coefs(!i, %pos) = !coef
next
next
Re: Stepwise rolling regression: plot of coeffiecients
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
%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
Who is online
Users browsing this forum: No registered users and 9 guests