question about specifying sample size
Posted: Sat Sep 18, 2010 11:06 am
Hi,
I use the following program to recursively forecast cpi-ind2_d with 0-4 lags of cpi_ind_d and 0-1 lags of x7,x8,x10,x11,using BIC to select lag length. Because x7,x8,x10,x11 starts at different quarters, I want to only used them if they have 79 observations. It seems to take forever to just do one forecast, but once I remove the
"if !xx7/8/10/11>={%obs} then", it takes a couple of seconds. I wonder what is reason for this. There are 5*2*2*2*2=80 models I have to estimate for each forecast, and the computer deside "if !xx7/8/10/11>={%obs} then" 80 times, should be very fast.
'create table for storing fitted values.
%table= "fited_value_xxx"
table(150,1) {%table}
' move sample 1 step obs at a time
for !s =1 to 88-80-1
' set sample to estimation period
smpl 1970q1 1970q1+79+!s-1
' estimate equation
'Program that calculates the "best" ARMA specification for an equation. Edit the variables below to match your particular data/setup.
%eqname ="xxx_"+"eq"+"!s" 'name of equation object that will be used.
%maxar= "4" 'maximum number of AR terms
%maxx7= "1"
%maxx8= "1"
%maxx10= "1"
%maxx11= "1"
%dep = "cpi_ind2_d" 'dependent variable
%ar="cpi_ind_d"
%x7="ins_d"
%x8="m1_ind"
%x10="ppi_in"
%x11="unemp_d"
%obs="79"
%criterion = "@AIC" 'which criterion to use enter "@AIC" for Akaike, "@schwarz" for Schwarz, and @HQ for Hannan-Quinn
!maxar = @val(%maxar)
!maxx7=@val(%maxx7)
!maxx8=@val(%maxx8)
!maxx10=@val(%maxx10)
!maxx11=@val(%maxx11)
close {%eqname}
!xx7 = @obs({%x7})
!xx8 = @obs({%x8})
!xx10 = @obs({%x10})
!xx11 = @obs({%x11})
!mincrit = 10000 'set the minimum to an artificially large value to begin
'estimate the models
%arstring = ""
for !i=0 to !maxar
'build up string for AR terms.
if !i>0 then
%arstring = %arstring + "cpi_ind_d"+"("+@str(!i) + "-1)"
endif
%x7string = ""
if !xx7>={%obs} then
for !p=0 to !maxx7
'build up string for x terms.
if !p>0 then
%x7string = %x7string + %space + %x7+"(" + @str(!p) + "-1)"
endif
endif
%x8string = ""
if !xx8>={%obs} then
for !q=0 to !maxx8
'build up string for x terms.
if !q>0 then
%x8string = %x8string + %space + %x8+"(" + @str(!q) + "-1)"
endif
endif
%x10string = ""
if !xx10>={%obs} then
for !t=0 to !maxx10
'build up string for x terms.
if !t>0 then
%x10string = %x10string + %space + %x10+"(" + @str(!t) + "-1)"
endif
endif
%x11string = ""
if !xx11>={%obs} then
for !u=0 to !maxx11
'build up string for x terms.
if !u>0 then
%x11string = %x11string + %space + %x11+"(" + @str(!u) + "-1)"
endif
endif
'estimate equation
equation {%eqname}.ls {%dep} c {%arstring} {%x7string} {%x8string} {%x10string} {%x11string}
'capture criterion
if @upper(%criterion) = "@AIC" then
!crit = {%eqname}.@aic
endif
if @upper(%criterion) = "@SCHWARZ" then
!crit = {%eqname}.@schwarz
endif
if @upper(%criterion) = "@HQ" then
!crit = {%eqname}.@hq
endif
'compare criterion
if !crit < !mincrit then
!mincrit = !crit
%bestARstr = %arstring 'store the best ar string
%bestx7str = %x7string
%bestx8str = %x8string
%bestx10str = %x10string
%bestx11str = %x11string
endif
next
next
next
next
next
equation {%eqname}.ls {%dep} c {%bestARstr} {%bestx7str} {%bestx8str} {%bestx10str} {%bestx11str}
'calculate fited value
smpl 1970q1+79+!s 1970q1+79+!s
{%eqname}.fit(f=na) inffit
'store fited value
{%table}(!s,1)=@mean(inffit)
next
show {%table}
I use the following program to recursively forecast cpi-ind2_d with 0-4 lags of cpi_ind_d and 0-1 lags of x7,x8,x10,x11,using BIC to select lag length. Because x7,x8,x10,x11 starts at different quarters, I want to only used them if they have 79 observations. It seems to take forever to just do one forecast, but once I remove the
"if !xx7/8/10/11>={%obs} then", it takes a couple of seconds. I wonder what is reason for this. There are 5*2*2*2*2=80 models I have to estimate for each forecast, and the computer deside "if !xx7/8/10/11>={%obs} then" 80 times, should be very fast.
'create table for storing fitted values.
%table= "fited_value_xxx"
table(150,1) {%table}
' move sample 1 step obs at a time
for !s =1 to 88-80-1
' set sample to estimation period
smpl 1970q1 1970q1+79+!s-1
' estimate equation
'Program that calculates the "best" ARMA specification for an equation. Edit the variables below to match your particular data/setup.
%eqname ="xxx_"+"eq"+"!s" 'name of equation object that will be used.
%maxar= "4" 'maximum number of AR terms
%maxx7= "1"
%maxx8= "1"
%maxx10= "1"
%maxx11= "1"
%dep = "cpi_ind2_d" 'dependent variable
%ar="cpi_ind_d"
%x7="ins_d"
%x8="m1_ind"
%x10="ppi_in"
%x11="unemp_d"
%obs="79"
%criterion = "@AIC" 'which criterion to use enter "@AIC" for Akaike, "@schwarz" for Schwarz, and @HQ for Hannan-Quinn
!maxar = @val(%maxar)
!maxx7=@val(%maxx7)
!maxx8=@val(%maxx8)
!maxx10=@val(%maxx10)
!maxx11=@val(%maxx11)
close {%eqname}
!xx7 = @obs({%x7})
!xx8 = @obs({%x8})
!xx10 = @obs({%x10})
!xx11 = @obs({%x11})
!mincrit = 10000 'set the minimum to an artificially large value to begin
'estimate the models
%arstring = ""
for !i=0 to !maxar
'build up string for AR terms.
if !i>0 then
%arstring = %arstring + "cpi_ind_d"+"("+@str(!i) + "-1)"
endif
%x7string = ""
if !xx7>={%obs} then
for !p=0 to !maxx7
'build up string for x terms.
if !p>0 then
%x7string = %x7string + %space + %x7+"(" + @str(!p) + "-1)"
endif
endif
%x8string = ""
if !xx8>={%obs} then
for !q=0 to !maxx8
'build up string for x terms.
if !q>0 then
%x8string = %x8string + %space + %x8+"(" + @str(!q) + "-1)"
endif
endif
%x10string = ""
if !xx10>={%obs} then
for !t=0 to !maxx10
'build up string for x terms.
if !t>0 then
%x10string = %x10string + %space + %x10+"(" + @str(!t) + "-1)"
endif
endif
%x11string = ""
if !xx11>={%obs} then
for !u=0 to !maxx11
'build up string for x terms.
if !u>0 then
%x11string = %x11string + %space + %x11+"(" + @str(!u) + "-1)"
endif
endif
'estimate equation
equation {%eqname}.ls {%dep} c {%arstring} {%x7string} {%x8string} {%x10string} {%x11string}
'capture criterion
if @upper(%criterion) = "@AIC" then
!crit = {%eqname}.@aic
endif
if @upper(%criterion) = "@SCHWARZ" then
!crit = {%eqname}.@schwarz
endif
if @upper(%criterion) = "@HQ" then
!crit = {%eqname}.@hq
endif
'compare criterion
if !crit < !mincrit then
!mincrit = !crit
%bestARstr = %arstring 'store the best ar string
%bestx7str = %x7string
%bestx8str = %x8string
%bestx10str = %x10string
%bestx11str = %x11string
endif
next
next
next
next
next
equation {%eqname}.ls {%dep} c {%bestARstr} {%bestx7str} {%bestx8str} {%bestx10str} {%bestx11str}
'calculate fited value
smpl 1970q1+79+!s 1970q1+79+!s
{%eqname}.fit(f=na) inffit
'store fited value
{%table}(!s,1)=@mean(inffit)
next
show {%table}