Re: An introduction to EViews programming.
Posted: Tue Jul 07, 2015 10:44 pm
xxx
Code: Select all
pageselect experiment
delete *
smpl 1980m1 2016m12
'read(b2, s=top_ten) {%pathread}\correl_first.xls range=B2
'wfopen {%pathread}\correl_first.xls range=B2
import {%pathread}\correl_first.xls range=A2
group gexp *
for %zz resid c
gexp.drop {%zz}
next
'copy *
for !j=1 to gexp.@count
%var = gexp.@seriesname(!j)
Code: Select all
%eqname = "arma" 'name of equation object that will be used.
'%dep = "y1_ind" 'dependent variable
%maxAR = "5" 'maximum number of AR terms
%maxMA = "5" 'maximum number of MA terms
%regs = "C " 'independent variables
%criterion = "@schwarz" 'which criterion to use enter "@AIC" for Akaike, "@schwarz" for Schwarz, and @HQ for Hannan-Quinn
!maxAR = @val(%maxAR)
!maxMA = @val(%maxMA)
close {%eqname}
'create table for storing critical values.
%matname = "crits"
if @isobject(%matname) then
%matname = "__crits"
if @isobject(%matname) then
delete {%matname}
endif
endif
table(!maxar+2,!maxma+2) {%matname}
{%matname}(1,1) = "AR / MA"
{%matname}.setlines(1) +b
{%matname}.setlines(a) +r
'set sample
smpl @first+!maxAR @last
!mincrit = 1e12 '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 + " ar(" + @str(!i) + ")"
endif
%mastring = ""
for !j=0 to !maxma
'build up string for MA terms
if !j>0 then
%mastring = %mastring + " ma(" + @str(!j) + ")"
endif
'estimate equation
smpl 1980m1 %end
equation {%eqname}.ls dlog({%var}) {%regs} {%arstring} {%mastring}
'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
!bestAR = !i
!bestMA = !j
%bestARstr = %arstring 'store the best ar string
%bestMAstr = %mastring 'store the best ma string
{%matname}.settextcolor(@all) black 'table formatting.
!ii=!i+2
!jj=!j+2
{%matname}.settextcolor(!ii,!jj) red
endif
{%matname}(!i+2,!j+2) = !crit
{%matname}(!i+2,1) = !i
{%matname}(1,!j+2) = !j
next
next
equation {%eqname}{%var}.ls dlog({%var}) {%regs} {%bestARstr} {%bestMAstr}
'show {%eqname}
'show {%matname}
smpl 2002m1 %forend
{%var} = @nan({%var},0)
smpl if {%var} = 0
{%eqname}.forecast {%var}_f
series MAPE_{%var} = @rmse({%var},{%var}_f)
smpl %beg %forend
'plot @pca({%var}_f) @pca({%var})
next
group g1_f *_f
group g1_mape mape_*
write {%pathwrite}\res_poolbrid_sam.xls g1 g1_f g1_mape
Code: Select all
!aic = 99999999
!maxlags = 4
!bestlag = 0
smpl @first+!maxlags @last
matrix(15,63) coefs
for !j=1 to !maxlags
for !i=1 to 63
equation eq{!i}.ls y{!i} c y{!i}(-1 to -!j) x(0 to -!j) z(0 to -!j)
if eq.@aic < !aic then
!bestlag = !j 'if this lag specification has the best AIC, then store this lag as !bestlag.
!aic = eq{!i}.@aic
endif
colplace(coefs, eq{!i}.@coefs, !i) 'store coefficients into matrix
next
Code: Select all
!aic = 99999999
!maxlags = 4
!bestlag = 0
smpl @first+!maxlags @last
for !j=1 to !maxlags
for !i=1 to 63
equation eq{!i}.ls cz_{!i} c cz_{!i}(-1 to -!j) ugap(0 to -!j) fx(0 to -!j) vatup vatdown
if eq{!i}.@aic < !aic then
!bestlag = !j 'if this lag specification has the best AIC, then store this lag as !bestlag.
!aic = eq{!i}.@aic
endif
next
next
Code: Select all
matrix(17,63) coefs ' at the beginning
colplace(coefs, eq{!i}.@coefs, !i) ' at the FOR statement after the regression