Page 6 of 6

### Re: ARIMASel (Automatic ARIMA selection)

Posted: Tue Mar 01, 2016 1:18 pm
1-Got it!
2- we can show it like this (p,d,q)(P,D,Q) in this code. how can do this

### Re: ARIMASel (Automatic ARIMA selection)

Posted: Mon Apr 18, 2016 5:21 am
Hi all

Is there a way to regress a variable, where the lags on the independent variables are selected automatically, according to the SIC or AIC or HQ?

I modified an autoARMA code to look as follows, but the problem is that the code selects the best lag and adds it, but does not include the lags before that.

That is, i would have, say: GDP C EXPORTS(-6). Obviously I would like it to include all the lags from -1 to -6- Any idea of how to do this? My code is as below:

%eqname = "fore" 'name of equation object that will be used.
%dep = "y1_ind" 'dependent variable

%maxlag = "6" 'maximum number of AR terms
%maxlagabs="6" '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)
'!maxMA = @val(%maxMA)

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 = "dlog("+ %var+"(-" + @str(!i) + "))"
endif

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
'compare criterion
if !crit < !mincrit then
!mincrit = !crit
!bestlag = !i
'!bestMA = !j
%bestlagstr = %lagstring 'store the best lag string
endif
next

equation {%eqname}_{%var}.ls dlog({%dep}) {%regs} {%bestlagstr} '{%bestMAstr}

for !i= 0 to !maxlag
'build up string for AR terms.
if !i>0 then
%lagstring = "dlog("+ %var+"(-" + @str(!i) + "))"
endif

'show {%eqname}
'show {%matname}

smpl 2002m1 %forend
{%var} = @nan({%var},0)

'smpl if {%dep} = 0
{%eqname}.forecast {%dep}_f
series rm_{%var} = @rmse({%dep},{%dep}_f)

smpl %beg %forend
'plot @pca({%var}_f) @pca({%var})

next

Any help would be appreciated!

### Re: ARIMASel (Automatic ARIMA selection)

Posted: Mon Apr 18, 2016 6:35 am

Code: Select all

`if !i>0 then%lagstring = "dlog("+ %var+"(-1 to -" + @str(!i) + "))"endif`

### Re: ARIMASel (Automatic ARIMA selection)

Posted: Mon Apr 18, 2016 7:06 am
Hi Gareth

I put in in the first loop where the code exists, but I get the error message "-1 TO -1 is not a valid index for variable name in "EQUATION {%EQNAME}.LS DLOG(Y1) C DLOG(VARIABLE NAME(-1 TO -1))"

As far as I understand, the equation is trying to read the -1 TO -1 as part of the variable name, and getting confused.

Any suggestions

### Re: ARIMASel (Automatic ARIMA selection)

Posted: Mon Apr 18, 2016 7:33 am
Ah, I missed the dlog part.

You'll have to build up the full lag string manually

### Re: ARIMASel (Automatic ARIMA selection)

Posted: Mon Apr 18, 2016 11:35 pm
Hi Gareth

Does that mean that one cannot find the best lag according to an information criteria, and then just add lags going back to -1 automatically through a loop? So say the code identifies the best lag as -4, can we include code that says "For !maxlag back to -1, add to the regression"?

Thanks

### Re: ARIMASel (Automatic ARIMA selection)

Posted: Tue Apr 19, 2016 12:09 am
The problem is that the code isn't identifying cummulative lags - it is just finding the best single lag length. I presume you want to run all lags up to the lag length.

### Re: ARIMASel (Automatic ARIMA selection)

Posted: Tue Apr 19, 2016 12:52 am
Correct. So whichever is the best single lag length, then run all the lags up to that.

Although I see your point, we are identifying the single best lag length and then throwing it out the window by just adding other lags.

Is there a way to automatically code to find that best cumulative lags? Possibly by a loop that adds lags and then tests the SIC, then stops when the SIC reaches its max?

### Re: ARIMASel (Automatic ARIMA selection)

Posted: Tue Apr 19, 2016 1:01 am
Yes, you'll have to build up the full lag string manually, like in this example (with the AR terms):
viewtopic.php?f=15&t=1175

### Re: ARIMASel (Automatic ARIMA selection)

Posted: Tue Apr 19, 2016 1:40 am
Thanks. I figured it out, it was a case of adding %lagstring to [code]%lagstring = %lagstring + "dlog("+ %var+"(-" + @str(!i) + "))"[\code]

Is there a way to specify including variables if they show p-value significance? Or barring that, a minimum lag length? While the code worked, some of the equations were throwing out equations without any lags, just the constant.

### Re: ARIMASel (Automatic ARIMA selection)

Posted: Tue Apr 19, 2016 2:22 am
When you write the for loop for the lags, don't start at 0 lags