Bookmark and Share

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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From   "Hannes Stieperaere" <[email protected]>
To   <[email protected]>
Subject   st: Optimal AR-structure based on AIC - "initial values not feasible" problem
Date   Mon, 30 Sep 2013 16:59:51 +0200

Hello,

I'm having a problem using loops to get the best AR-structure based on AIC
(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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index