Automatic ARMA selection
Moderators: EViews Gareth, EViews Moderator

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 11411
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Automatic ARMA selection
Thank you Gareth. Then I think I will go ahead with the try and error method by fixing the maximum lag length at 4 for the daily data.
Re: Automatic ARMA selection
Hello,
I was wondering which spot is right for entering a sample restriction clause. I originally thought this could be toggled from the workfile interface, but even when I restrict the workfile sample range, the ARMA selection program always uses the full range of the data.
Thanks again for your excellent programming resources!
I was wondering which spot is right for entering a sample restriction clause. I originally thought this could be toggled from the workfile interface, but even when I restrict the workfile sample range, the ARMA selection program always uses the full range of the data.
Thanks again for your excellent programming resources!

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 11411
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Automatic ARMA selection
Code: Select all
smpl @first+!maxAR @last
Change that line.
Follow us on Twitter @IHSEViews
Re: Automatic ARMA selection
Hi Gareth,
I ran the code on one of my series. In addition, i tried to confirm results using the Automatic ARIMA selection addin. The results vary. While the Schwarz value against zero lag comes same in both cases, it varies for lag 1,2,3 and 4.
i want to specify that i have one more independent variable other than "c". Also i am setting MA=0 and i am checking upto 4 lags of AR.
Please help me. I would be very thankful.
Priyanshi
I ran the code on one of my series. In addition, i tried to confirm results using the Automatic ARIMA selection addin. The results vary. While the Schwarz value against zero lag comes same in both cases, it varies for lag 1,2,3 and 4.
i want to specify that i have one more independent variable other than "c". Also i am setting MA=0 and i am checking upto 4 lags of AR.
Please help me. I would be very thankful.
Priyanshi

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 11411
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Automatic ARMA selection
There are many many reasons they could differ
Follow us on Twitter @IHSEViews
Re: Automatic ARMA selection
Thank you for your reply!
Re: Automatic ARMA selection
Hi
I am trying to run an auto ARMA selection code, with a base in the code discussed here. However, I would like to run the code using a for loop that creates equations for each series in a group. I've tried to use a common identifier of "m_*", but still struggling. I've placed the code below, can anyone advise? The idea is it creates and names each equation as dl+the name of the original series.
for !i=1 to batch01.count 'create the group name
%iname= batch01.@seriesname(!i) 'identifiy the individual series in the group
next
%iname = "{dl}_{%iname}" 'name of equation object that will be used.
%maxAR = "4" 'maximum number of AR terms
%maxMA = "4" 'maximum number of MA terms
%dep = "d(log{%iname})" 'dependent variable
%regs = "C " 'independent variables
%criterion = "@AIC" 'which criterion to use enter "@AIC" for Akaike, "@schwarz" for Schwarz, and @HQ for HannanQuinn
!maxAR = @val(%maxAR)
!maxMA = @val(%maxMA)
close {%iname}
'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
equation {%iname}.ls {%dep} {%regs} {%arstring} {%mastring}
'capture criterion
if @upper(%criterion) = "@AIC" then
!crit = {%iname}.@aic
endif
if @upper(%criterion) = "@SCHWARZ" then
!crit = {%i
name}.@schwarz
endif
if @upper(%criterion) = "@HQ" then
!crit = {%iname}.@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 {%iname}.ls {%dep} {%regs} {%bestARstr} {%bestMAstr}
show {%iname}
show {%matname}
I am trying to run an auto ARMA selection code, with a base in the code discussed here. However, I would like to run the code using a for loop that creates equations for each series in a group. I've tried to use a common identifier of "m_*", but still struggling. I've placed the code below, can anyone advise? The idea is it creates and names each equation as dl+the name of the original series.
for !i=1 to batch01.count 'create the group name
%iname= batch01.@seriesname(!i) 'identifiy the individual series in the group
next
%iname = "{dl}_{%iname}" 'name of equation object that will be used.
%maxAR = "4" 'maximum number of AR terms
%maxMA = "4" 'maximum number of MA terms
%dep = "d(log{%iname})" 'dependent variable
%regs = "C " 'independent variables
%criterion = "@AIC" 'which criterion to use enter "@AIC" for Akaike, "@schwarz" for Schwarz, and @HQ for HannanQuinn
!maxAR = @val(%maxAR)
!maxMA = @val(%maxMA)
close {%iname}
'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
equation {%iname}.ls {%dep} {%regs} {%arstring} {%mastring}
'capture criterion
if @upper(%criterion) = "@AIC" then
!crit = {%iname}.@aic
endif
if @upper(%criterion) = "@SCHWARZ" then
!crit = {%i
name}.@schwarz
endif
if @upper(%criterion) = "@HQ" then
!crit = {%iname}.@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 {%iname}.ls {%dep} {%regs} {%bestARstr} {%bestMAstr}
show {%iname}
show {%matname}

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 11411
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Automatic ARMA selection
All of the estimation stuff is done outside your loop the loops through the group members. It needs to be done inside the loop
Follow us on Twitter @IHSEViews
Re: Automatic ARMA selection
Hi All
I am attempting to run a program that runs an ols equation where the lag length of the independent variables are selected automatically. The idea is to run through each independent variable, select the optimum lags, and then forecast the dependent variable based on this.
The code is a variation of the auto ARMA selection, but I feel I am missing something. Any help here?
Here is the code:
I am attempting to run a program that runs an ols equation where the lag length of the independent variables are selected automatically. The idea is to run through each independent variable, select the optimum lags, and then forecast the dependent variable based on this.
The code is a variation of the auto ARMA selection, but I feel I am missing something. Any help here?
Here is the code:
Code: Select all
for !p=1 to gexp_f.count
%var = gexp_f.@seriesname(!p) 'name of var
'h_mark_stre h_sup_stre pmi veh_s_com veh_s_pas veh_s_tot
%eqname = "fore" 'name of equation object that will be used.
%dep = "y1_ind" 'dependent variable
%maxlag = "4" 'maximum number of AR terms
%maxlagabs="4" 'maximum number of AR terms (absolute)
'%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 HannanQuinn
!maxlag = @val(%maxlag)
!maxlagabs=@val(%maxlagabs)
close {%eqname}
'set sample
smpl @first+!maxlagabs @last
!mincrit = 1e12 'set the minimum to an artificially large value to begin
'estimate the models
%lagstring = ""
for !i=0 to !maxlag
'build up string for lag terms.
if !i>0 then
%lagstring = %var+"(" + @str(!i) + ")"
endif
'%mastring = ""
'for !j=0 to !maxma
'build up string for MA terms
'if !j>0 then
'estimate equation
smpl 1980m1 %end
equation {%eqname}.ls dlog({%dep}) {%regs} {%lagstring} '{%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
next
equation {%eqname}_{%var}.ls dlog({%dep}) {%regs} {%bestlagstr}
Re: Automatic ARMA selection
Dear Gareth or Trubador
I am using Eviews 9, the ARMA method is maximum likelihood and it could not be tested with LM test. Do you know the reason behind this? or how can we change the method in order to use LM test.
Thank you
I am using Eviews 9, the ARMA method is maximum likelihood and it could not be tested with LM test. Do you know the reason behind this? or how can we change the method in order to use LM test.
Thank you

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 11411
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Automatic ARMA selection
Hello I'm using eviews 9. And I am currently using Automatic Arima to find the best model for our data series but we had a hard time understanding the rules in AR and MA that's why we dont know if 4 is fixed in both MA and AR or we need to change that and how ? Thank you for your kindly consideration .
Re: Automatic ARMA selection
Hello!
I want to change the program beacuse I need a regression without constant. I stablished a conditional, but it does't work.
I have an error because %eqname is undeterminated or undifined. I think last conditionals isn't correct but I don't know why.
I want to change the program beacuse I need a regression without constant. I stablished a conditional, but it does't work.
Code: Select all
'Create some data. Delete these first few lines if you want to run on your existing workfile.
series y_SW =0
copy etec y_SW
'Program that calculates the "best" ARMA specification for an equation. Edit the variables below to match your particular data/setup.
%eqname = "ciclo_SW" 'name of equation object that will be used.
%maxAR = "4" 'maximum number of AR terms
%maxMA = "4" 'maximum number of MA terms
%dep = "Y_SW" 'dependent variable
%regs = "C " 'independent variables
%criterion = "@schwarz" 'which criterion to use enter "@AIC" for Akaike, "@schwarz" for Schwarz, and @HQ for HannanQuinn
!maxAR = @val(%maxAR)
!maxMA = @val(%maxMA)
close {%eqname}
'create table for storing critical values.
%matname = "crits_SW"
if @isobject(%matname) then
%matname = "__crits_SW"
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 @all
!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
if %arstring="ar(1)" or %arstring="ar(2)" or %arstring="ar(3)" or %arstring="ar(4)" or %mastring="ma(1)" or %mastring="ma(2)" or %mastring="ma(3)" or %mastring="ma(4)" then
equation {%eqname}.ls(arma=cls, optmethod=legacy) {%dep} {%arstring}{%mastring}
endif
if %arstring="ar(0)" and %mastring="ma(0)" then
equation{%eqname}.ls(arma=cls, optmethod=legacy) {%dep} {%regs}
endif
'capture criterion
if @upper(%criterion) = "@SCHWARZ" then
!crit = {%eqname}.@schwarz
endif
next
next
I have an error because %eqname is undeterminated or undifined. I think last conditionals isn't correct but I don't know why.

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 11411
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Automatic ARMA selection
Not sure what you're trying to do  but have you tried the built in automatic ARMA forecasting (which also does arma model selection)?
Follow us on Twitter @IHSEViews
Return to “Program Repository”
Who is online
Users browsing this forum: No registered users and 1 guest