Rolling regression with some missing entries
Posted: Tue Mar 30, 2010 5:30 pm
Hi. I'm new to eviews programming, so I may need a little more guidance here. I'm working on getting rolling regression coefficients for several estimations. I have three time series,y,u, and c, each with 170 observations, but need to run rolling regressions with a window of 60 observations, and store the coefficients of the regressions. I also want to run these equations for 6 different country sets at once, to give cofficients for each country.
However, for some countries, there is no data for the independent varaible c, so when the program runs and finds no data, it terminates at the first set of rolling regression, and gives no coefficients.The program works fine for those countries with complete data.
So, is there a way to tell the program to skip the regression for the windows with no data on a specific variable, and put "N/A" and continue to the next window?
This is how my program is set up so far;
!window =60
' set step size
!step =1
' get size of workfile
!length = @obsrange
' declare equation for estimation
for %z can ger ken uk fra ger
equation eq1_{%z}
equation eq2_{%z}
next
'calculate number of rolls
!nrolls = @round((!length-!window)/!step)
'matrix to store coefficient estimates (2X!nrolls matrix) '
for %z can ger ken uk fra ger
matrix(2,!nrolls) coefmatC1C2_{%z}
next
'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
for %z can ger ken uk fra ger
'set sample to estimation period
vector p1_{%z} = @cmin(c_{%z})
vector p2_{%z} = @cmin(u_{%z})
vector p3_{%z} = @cmin(y_{%z})
next
smpl @first+!i @first+!i+!window-1
for %z can ger ken uk fra ger
'v1, v2 and v3 recode the series so that the NA's are replaced with -999999 and we can use the numerical commands for 'if'
'series v1_{%z} = @nan(c_{%z},lowerbound)
'series v2_{%z} = @nan(u_{%z},lowerbound)
'series v3_{%z} = @nan(y_{%z},lowerbound)
'p1, p2 and p3 simply computes the minimum of the original series - which implies e.g. that if the minimum of v1 is -999999, it will report NA instead
vector p1_{%z} = @cmin(c_{%z})
vector p2_{%z} = @cmin(u_{%z})
vector p3_{%z} = @cmin(y_{%z})
'mv1, mv2 and mv3 recode the minimum computed before so that the NA's are replaced with -999999 and we can use the numerical commands for 'if'
scalar lowerbound1 = -999999
vector mv1_{%z} = @nan(p1_{%z},lowerbound1)
vector mv2_{%z} = @nan(p2_{%z},lowerbound1)
vector mv3_{%z} = @nan(p3_{%z},lowerbound1)
if mv1_{%z} > -999999 and mv2_{%z} > -999999 and mv3_{%z} > -999999 then
eq1_{%z}.ls y_{%z} =C(1)*u_{%z}+C(2)* c_{%z}
endif
next
'store coefficients
for %z can ger ken uk fra ger
if mv1_{%z} > -999999 and mv2_{%z} > -999999 and mv3_{%z} > -999999 then
colplace(coefmatC1C2_{%z},eq1_{%z}.@coefs,!j)
else
'vec12 is created so that we can fill the blank spaces in those instances in which the regression did not run before because of insufficient data
vector (2) vec12_{%z}
vec12_{%z} = -999999
colplace(coefmatC1C2_{%z},vec12_{%z},!j)
endif
next
next
However, for some countries, there is no data for the independent varaible c, so when the program runs and finds no data, it terminates at the first set of rolling regression, and gives no coefficients.The program works fine for those countries with complete data.
So, is there a way to tell the program to skip the regression for the windows with no data on a specific variable, and put "N/A" and continue to the next window?
This is how my program is set up so far;
!window =60
' set step size
!step =1
' get size of workfile
!length = @obsrange
' declare equation for estimation
for %z can ger ken uk fra ger
equation eq1_{%z}
equation eq2_{%z}
next
'calculate number of rolls
!nrolls = @round((!length-!window)/!step)
'matrix to store coefficient estimates (2X!nrolls matrix) '
for %z can ger ken uk fra ger
matrix(2,!nrolls) coefmatC1C2_{%z}
next
'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
for %z can ger ken uk fra ger
'set sample to estimation period
vector p1_{%z} = @cmin(c_{%z})
vector p2_{%z} = @cmin(u_{%z})
vector p3_{%z} = @cmin(y_{%z})
next
smpl @first+!i @first+!i+!window-1
for %z can ger ken uk fra ger
'v1, v2 and v3 recode the series so that the NA's are replaced with -999999 and we can use the numerical commands for 'if'
'series v1_{%z} = @nan(c_{%z},lowerbound)
'series v2_{%z} = @nan(u_{%z},lowerbound)
'series v3_{%z} = @nan(y_{%z},lowerbound)
'p1, p2 and p3 simply computes the minimum of the original series - which implies e.g. that if the minimum of v1 is -999999, it will report NA instead
vector p1_{%z} = @cmin(c_{%z})
vector p2_{%z} = @cmin(u_{%z})
vector p3_{%z} = @cmin(y_{%z})
'mv1, mv2 and mv3 recode the minimum computed before so that the NA's are replaced with -999999 and we can use the numerical commands for 'if'
scalar lowerbound1 = -999999
vector mv1_{%z} = @nan(p1_{%z},lowerbound1)
vector mv2_{%z} = @nan(p2_{%z},lowerbound1)
vector mv3_{%z} = @nan(p3_{%z},lowerbound1)
if mv1_{%z} > -999999 and mv2_{%z} > -999999 and mv3_{%z} > -999999 then
eq1_{%z}.ls y_{%z} =C(1)*u_{%z}+C(2)* c_{%z}
endif
next
'store coefficients
for %z can ger ken uk fra ger
if mv1_{%z} > -999999 and mv2_{%z} > -999999 and mv3_{%z} > -999999 then
colplace(coefmatC1C2_{%z},eq1_{%z}.@coefs,!j)
else
'vec12 is created so that we can fill the blank spaces in those instances in which the regression did not run before because of insufficient data
vector (2) vec12_{%z}
vec12_{%z} = -999999
colplace(coefmatC1C2_{%z},vec12_{%z},!j)
endif
next
next