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}
question about specifying sample size
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13585
- Joined: Tue Sep 16, 2008 5:38 pm
Re: question about specifying sample size
You might like to post the accompanying workfile.
-
kanonathena
- Posts: 14
- Joined: Thu Jul 15, 2010 2:24 am
Re: question about specifying sample size
I have attached the workfile.
- Attachments
-
- 1970-2009.wf1
- (364.37 KiB) Downloaded 327 times
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13585
- Joined: Tue Sep 16, 2008 5:38 pm
Re: question about specifying sample size
Program runs very quickly (less than a second) for me.
-
kanonathena
- Posts: 14
- Joined: Thu Jul 15, 2010 2:24 am
Re: question about specifying sample size
Hi, Gareth
Could you run the program and workfile in the this attachment?
I found that eviews 6 seems to be stuck determining "%x4string" (saw this in the bottom left status bar where %x4string flashes a lot), and this problem is specific to certain time series, if I change %x4 from gold_ind to ppi_ind, the program run smoothly.
Could you run the program and workfile in the this attachment?
I found that eviews 6 seems to be stuck determining "%x4string" (saw this in the bottom left status bar where %x4string flashes a lot), and this problem is specific to certain time series, if I change %x4 from gold_ind to ppi_ind, the program run smoothly.
- Attachments
-
- xxx 5 1970.prg
- (3.84 KiB) Downloaded 340 times
-
- 1970-1989.wf1
- (687.3 KiB) Downloaded 326 times
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13585
- Joined: Tue Sep 16, 2008 5:38 pm
Re: question about specifying sample size
Your program is structured quite inefficiently, I think.
All of the stuff at the top of the program doesn't seem to change from 1 loop to the next, so they should probably be outside of the loop. For example, I don't see why you need to re-define %maxx1 each time through the loop, when it isn't changing.
Secondly your if-statements are structured badly. It seems to me, from looking at your code, that you only want to do something if !ar>40, !xx1>40, !xx2><40 etc..., yet you do a lot of work between testing those. For example, if !xx5<40, you don't want to do anything, but your program has actually done a lot of work, in building up the xx4,xx3,xx2 strings etc...
All of the stuff at the top of the program doesn't seem to change from 1 loop to the next, so they should probably be outside of the loop. For example, I don't see why you need to re-define %maxx1 each time through the loop, when it isn't changing.
Secondly your if-statements are structured badly. It seems to me, from looking at your code, that you only want to do something if !ar>40, !xx1>40, !xx2><40 etc..., yet you do a lot of work between testing those. For example, if !xx5<40, you don't want to do anything, but your program has actually done a lot of work, in building up the xx4,xx3,xx2 strings etc...
-
kanonathena
- Posts: 14
- Joined: Thu Jul 15, 2010 2:24 am
Re: question about specifying sample size
if !xx5<40, I don't want to include variable x5 in the forecasting equation. What I want is to include varaibles that has more than 40 observations to do the forecast, so if !xx5<40 I will just use x1,x2,x3,x4. I tried the program on another computer with eviews 7, and it is still very slow, seems that the program stuck with variable with lass than 40 obs.
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13585
- Joined: Tue Sep 16, 2008 5:38 pm
Re: question about specifying sample size
I think you need to look at the position of your if and endif statements. They're not doing what you want, I think.
Who is online
Users browsing this forum: No registered users and 2 guests
