Automatic ARMA selection

For posting your own programs to share with others

Moderators: EViews Gareth, EViews Moderator

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

Re: Automatic ARMA selection

Postby Felipe » Thu Nov 09, 2017 9:21 am

Thanks for your answer.

I want the same program, the automatic ARMA selection, but the program posted in this forum consider a regression with constant.

Code: Select all

equation {%eqname}.ls dlog({%dep}) {%regs} {%lagstring} {%mastring}


Code: Select all


is the constant.
So I want a regression without this parameter

Code: Select all


I thought if I stablished a conditional I could resolve this problem, because I need to avoid a regression without parameters.
The first conditional considers the case without ARMA terms. So the regression is with constant:

Code: Select all

if %arstring="ar(0)" and  %mastring="ma(0)" then
      equation {%eqname}.ls(arma=cls, optmethod=legacy) {%dep} {%regs}

The second conditional considers the case with ARMA terms without constant:

Code: Select all

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}

But this conditionals doesn't work.
Last edited by Felipe on Thu Nov 09, 2017 10:03 am, edited 3 times in total.

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

Re: Automatic ARMA selection

Postby EViews Gareth » Thu Nov 09, 2017 9:22 am

Code: Select all

'Create some data.  Delete these first few lines if you want to run on your existing workfile.

create u 1000
series y=nrnd

'Program that calculates the "best" ARMA specification for an equation.  Edit the variables below to match your particular data/setup.

%eqname = "EQ01"   'name of equation object that will be used.
%maxAR = "2"            'maximum number of AR terms
%maxMA = "3"   'maximum number of MA terms
%dep = "Y"   'dependent variable
%regs = " "   '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 {%eqname}

'create table for storing critical values.
%matname = "crits"
if @isobject(%matname) then
   %matname = "__crits"
   if @isobject(%matname) then
      delete {%matname}
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) + ")"
   %mastring = ""
   for !j=0 to !maxma
      'build up string for MA terms
      if !j>0 then
         %mastring = %mastring + " ma(" + @str(!j) + ")"
      'estimate equation
      %allregs = %regs + %arstring + %mastring
      if @len(%allregs)>1 then
         equation {%eqname}.ls {%dep} {%regs} {%arstring} {%mastring}
         'capture criterion
         if @upper(%criterion) = "@AIC" then
            !crit = {%eqname}.@aic
         if @upper(%criterion) = "@SCHWARZ" then
            !crit = {%eqname}.@schwarz
         if @upper(%criterion) = "@HQ" then
            !crit = {%eqname}.@hq
         '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.
            {%matname}.settextcolor(!ii,!jj) red
         {%matname}(!i+2,!j+2) = !crit
         {%matname}(!i+2,1) = !i
         {%matname}(1,!j+2) = !j

equation {%eqname}.ls {%dep} {%regs} {%bestARstr} {%bestMAstr}

show {%eqname}
show {%matname}

Follow us on Twitter @IHSEViews

Posts: 1
Joined: Sun Feb 11, 2018 8:19 pm

Residuals from an AR(1) for a number of macroeconomic variables & countries

Postby sazad » Wed Feb 14, 2018 4:24 pm

I have not programmed much in E-views, so not an export. I am trying to obtain absolute values of residuals from an AR(1) model for time series data of more than one macroeconomic variable and country in one go. Attached a test file for just one variable. How can I create a loop to store the abs value for each of the macro variables for each country? Any prompt help is much appreciated.
Many thanks,
(16.24 KiB) Downloaded 17 times

Return to “Program Repository”

Who is online

Users browsing this forum: No registered users and 1 guest