Automatic ARMA selection

For posting your own programs to share with others

Moderators: EViews Gareth, EViews Moderator

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13307
Joined: Tue Sep 16, 2008 5:38 pm

Re: Automatic ARMA selection

Postby EViews Gareth » Tue Sep 03, 2013 7:10 am

It probably won't run in EV6.
Follow us on Twitter @IHSEViews

priyanshi
Posts: 11
Joined: Wed Jun 19, 2013 12:36 pm

Re: Automatic ARMA selection

Postby priyanshi » Wed Sep 04, 2013 11:18 am

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.

diggetybo
Posts: 152
Joined: Mon Jun 23, 2014 12:04 am

Re: Automatic ARMA selection

Postby diggetybo » Fri Aug 07, 2015 9:04 pm

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!

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13307
Joined: Tue Sep 16, 2008 5:38 pm

Re: Automatic ARMA selection

Postby EViews Gareth » Fri Aug 07, 2015 9:27 pm

Code: Select all

smpl @first+!maxAR @last

Change that line.
Follow us on Twitter @IHSEViews

priyanshi
Posts: 11
Joined: Wed Jun 19, 2013 12:36 pm

Re: Automatic ARMA selection

Postby priyanshi » Sun Aug 23, 2015 7:15 pm

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

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13307
Joined: Tue Sep 16, 2008 5:38 pm

Re: Automatic ARMA selection

Postby EViews Gareth » Sun Aug 23, 2015 7:38 pm

There are many many reasons they could differ
Follow us on Twitter @IHSEViews

priyanshi
Posts: 11
Joined: Wed Jun 19, 2013 12:36 pm

Re: Automatic ARMA selection

Postby priyanshi » Sun Aug 23, 2015 10:10 pm

Thank you for your reply!

Sammoland
Posts: 18
Joined: Tue Mar 01, 2016 6:41 am

Re: Automatic ARMA selection

Postby Sammoland » Wed Mar 02, 2016 12:18 am

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 Hannan-Quinn

!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}

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13307
Joined: Tue Sep 16, 2008 5:38 pm

Re: Automatic ARMA selection

Postby EViews Gareth » Wed Mar 02, 2016 12:59 am

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

Sammoland
Posts: 18
Joined: Tue Mar 01, 2016 6:41 am

Re: Automatic ARMA selection

Postby Sammoland » Fri Apr 15, 2016 7:40 am

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:

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 Hannan-Quinn

!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}

dwinda
Posts: 1
Joined: Wed Mar 16, 2016 12:44 am

Re: Automatic ARMA selection

Postby dwinda » Thu Aug 11, 2016 8:09 pm

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

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13307
Joined: Tue Sep 16, 2008 5:38 pm

Re: Automatic ARMA selection

Postby EViews Gareth » Thu Aug 11, 2016 8:37 pm

Change the ARMA method to CLS.
Follow us on Twitter @IHSEViews

flourence
Posts: 5
Joined: Sat Oct 21, 2017 3:56 am

Re: Automatic ARMA selection

Postby flourence » Tue Nov 07, 2017 4:21 am

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 .

Felipe
Posts: 2
Joined: Wed Nov 08, 2017 4:23 pm

Re: Automatic ARMA selection

Postby Felipe » Wed Nov 08, 2017 4:47 pm

Hello!
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 Hannan-Quinn

!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.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13307
Joined: Tue Sep 16, 2008 5:38 pm

Re: Automatic ARMA selection

Postby EViews Gareth » Wed Nov 08, 2017 4:54 pm

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 11 guests