Hello everyone,
The following subroutine searches for the best ARMA model according to Information criteria, taking into account the maximum amount of lags that we want it to analyse, which are specified in the second code, which calls the subroutine:
Subroutine:
' subroutine that estimates all arma models up to specified lags
'
' usage: call arma(ser1, group1, scalar_ar, scalar_ma, tab_name)
'
' where
'
' ser1: name of dependent variable series
' group1: name of group of exogenous regressors (should include constant, if desired)
' scalar_ar: integer for highest AR order
' scalar_ma: integer for highest MA order
' tab_name: name for stored table
'
' the program stores the AIC, SC, and HQ information criteria in a table named {%tabname}
subroutine arma(series y, group x, scalar ar_order, scalar ma_order, string %tabname)
' set upper limit lags
!pmax=ar_order
!qmax=ma_order
' declare test equation
equation eq_test
' declare table to store information criteria
table((!pmax+1)*(!qmax+1)+2,4) {%tabname}
setcolwidth({%tabname},1,11)
setcolwidth({%tabname},2,15)
setcolwidth({%tabname},3,15)
setcolwidth({%tabname},4,15)
{%tabname}(1,1) = "ARMA order"
{%tabname}(1,2) = "Akaike"
{%tabname}(1,3) = "Schwarz"
{%tabname}(1,4) = "Hannan-Quinn"
setline({%tabname},2)
' loop through every combination of arma lags
!row = 3
for !p=0 to !pmax
for !q=0 to !qmax
' build up ar terms
if !p=0 then
%1 = " "
else
for !i=1 to !p
%1 = %1 + "ar(" + @str(!i) + ") "
next
endif
' build up ma terms
if !q=0 then
%1 = %1 + " "
else
for !i=1 to !q
%1 = %1 + "ma(" + @str(!i) + ") "
next
endif
' estimate model
eq_test.ls(m=500,c=1e-5) y x {%1}
' store output in table
freeze(tab_{!p}{!q}) eq_test.output
%order = @str(!p) + "," + @str(!q)
{%tabname}(!row,1) = %order
{%tabname}(!row,2) = eq_test.@aic
{%tabname}(!row,3) = eq_test.@sc
{%tabname}(!row,4) = eq_test.@hq
' test for mininum noise model
if !row=3 then
!min_aic = eq_test.@aic
!min_sc = eq_test.@sc
!min_hq = eq_test.@hq
!order_aic = !row
!order_sc = !row
!order_hq = !row
else
if eq_test.@aic < !min_aic then
!min_aic = eq_test.@aic
!order_aic = !row
endif
if eq_test.@sc < !min_sc then
!min_sc = eq_test.@sc
!order_sc = !row
endif
if eq_test.@hq < !min_hq then
!min_hq = eq_test.@hq
!order_hq = !row
endif
endif
' clear string
%1 = " "
%order = " "
!row = !row+1
' delete table if not necessary
' delete tab_{!p}{!q}
next
next
' indicate best model in table
%aic = "*" + {%tabname}(!order_aic,2)
{%tabname}(!order_aic,2) = %aic
%sc = "*" + {%tabname}(!order_sc,3)
{%tabname}(!order_sc,3) = %sc
%hq = "*" + {%tabname}(!order_hq,4)
{%tabname}(!order_hq,4) = %hq
setline({%tabname},(!pmax+1)*(!qmax+1)+3)
{%tabname}((!pmax+1)*(!qmax+1)+4,1) = " * indicates best model"
endsub
2nd code:
' program to find best arma order
include sub_arma.prg
' Open data and create workfile with same name as excel file. AND rename it!!
wfopen C:\Users\gcoelho\Documents\Rentokil-Initial\E-views\Inputs_to_Eviews\mean_temperature_input.xlsx
rename series01 y
' Choose maximum of lags for MA and AR terms
!maxAR=3
!maxMA=3
' call subroutine
group x
x.add c
%tabname = "armaout"
call arma(y, x, !maxAR, !maxMA, %tabname)
show {%tabname}
I want to do so, but I want to include more variables and lags of those variables... How can I generalize this to a specified number of variables or if possible to a general one?
Moreover, as far as I know, Eviews considers an AR as an autoregressive process in the error term, instead of lags of the dependent variable. How can I change the code in order to consider this second option instead of the default one?
Any ideas?
Thank you,
Guilherme
Best ARMA multivariate model
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
Who is online
Users browsing this forum: No registered users and 2 guests
