Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# st: RE: Optimal AR-structure based on AIC - "initial values not feasible" problem

 From "hasnain.yousaf" <[email protected]> To "[email protected]" <[email protected]> Subject st: RE: Optimal AR-structure based on AIC - "initial values not feasible" problem Date Tue, 1 Oct 2013 05:24:37 +0000

```I am not aware how IC results are stored in matrix (trying scalar didn't work for me). You can write a smaller loop for getting the results table for AR structures
here is how i did it
1- for strictly AR models upto ARIMA(5,1,0) for one variable
forv i=1(1)5{
quietly arima variable,arima(`i',1,0)
estat ic
}
2- for strictly AR models upto ARIMA(5,1,0) for multiple  variables
foreach v of varlist variable1 variable 2{
forv i=1(1)5 {
quietly arima `v',arima(`i',1,0)
estat ic
}
}
3- for  ARMA (Including AR models in case 1) models upto ARIMA(5,1,5) for multiple  variables
foreach v of varlist variable1 variable 2{
forv i=1(1)5 {
for k=0(1)5{
quietly arima `v',arima(`i',1,`k')
estat ic
}
}
}
See if it works

________________________________________
From: [email protected] <[email protected]> on behalf of Hannes Stieperaere <[email protected]>
Sent: Monday, September 30, 2013 7:59 PM
To: [email protected]
Subject: st: Optimal AR-structure based on AIC - "initial values not feasible" problem

Hello,

(Akaike Information Criterion).
I use Stata 12.1.

I want to use Stata to compare the AIC values of AR models. It is not
necessary that all previous lags are included. C.f. an AR(1 3 4) without the
second lag must be possible.
The code below works fine until I adjust the code to include 5 lags or more.
In the end I want to include 12 possible lags.
When there are 5 possible lags or more, Stata returns the error: "initial
values not feasible r(1400)" after the phase I estimate the models by using
loops.
I know that the possible models Stata has to estimate rise exponentially,
but estimating 32 models doesn't seem problematic to me.

If we look at the code, the problem is situated in the first part between
the ---- brackets. Here, all the possible models are estimated and the AIC
are stored.
I use a loop that makes it possible per lag to be "number of lag" or "". The
latter is done to have the possibility that stata does not add a lag for a
specific lag (like in the AR(1 3 4) model, the second value would be "" or
no lag).

I am relatively new to Stata so maybe this is not the correct and fasted way
to program it.
Thanks in advance for any help on this code, or on sharing a faster way to
select an AR model based on AIC.

Stata Code:

The code that generates the error:
----------
local ok_1_1 = ""
local ok_1_2 = 1
local ok_2_1 = ""
local ok_2_2 = 2
local ok_3_1 = ""
local ok_3_2 = 3
local ok_4_1 = ""
local ok_4_2 = 4
local ok_5_1 = ""
local ok_5_2 = 5

forvalues lag5 = 1/2 {
forvalues lag4 = 1/2 {
forvalues lag3 = 1/2 {
forvalues lag2 = 1/2 {
forvalues lag1 = 1/2 {
qui arima l_regr in 17/92, ar(`ok_1_`lag1'' `ok_2_`lag2'' `ok_3_`lag3''
`ok_4_`lag4'' `ok_5_`lag5'')
qui estat ic
matrix xs`lag1'`lag2'`lag3'`lag4'`lag5' = r(S)
svmat xs`lag1'`lag2'`lag3'`lag4'`lag5',
name(xs`lag1'`lag2'`lag3'`lag4'`lag5')
}
}
}
}
}
--------

Rest of the code that must return the model with the lowest AIC-value:
----------
qui mkmat xs*5 in 1, matrix(AIC) obs nchar(1)
qui matrix list AIC
qui egen min_aic = rowmin(xs*5)
qui local names : colnames AIC
qui generate model = "`names'"
qui split(model)
qui forvalues i = 1/32 {
qui split model`i', parse(s) generate(modelaic`i')
}
qui destring modelaic*2 , replace float
qui mkmat modelaic*2 in 1, matrix(models) obs nchar(1)
qui svmat AIC, name(AIC)
qui matrix lag_aic = [models \ AIC]
qui forvalues i = 1/32 {
qui gen opt_lag`i' = lag_aic[1 , (`i')]  if lag_aic[2 , (`i')] == min_aic
}
qui egen opt_lag_aic = rowmax(opt_lag*)
qui display opt_lag_aic
qui tostring opt_lag_aic, replace
qui forvalues j = 1/5 {
qui gen ar`j' =  substr(opt_lag_aic,`j',1)
}
qui destring ar* , replace float
qui forvalues j = 1/5 {
qui if ar`j' == 1 gen ar_`j' = ""
qui if ar`j' == 2 gen ar_`j' = `j'
}
qui forvalues j = 1/5 {
qui local ar_`j' = ar_`j'
}
arima l_regr in 17/92, ar(`ar_1' `ar_2' `ar_3' `ar_4' `ar_5')
------

Kind regards,
Hannes Stieperaere
PhD Student Ghent University, Belgium

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/
```