'Select the lag order according to the information criterion.
Parameters
maxlag : int
The highest lag length tried. See `AR.fit`.
ic : str {\'aic\',\'bic\',\'hqic\',\'t-stat\'}
Criterion used for selecting the optimal lag length.
See `AR.fit`.
trend : str {\'c\',\'nc\'}
Whether to include a constant or not. \'c\' - include constant.
\'nc\' - no constant.
Returns
bestlag : int
Best lag according to IC.'

def select_order(self, maxlag, ic, trend='c', method='mle'):

    endog = self.endog
    Y = endog[maxlag:]
    self.Y = Y
    X = self._stackX(maxlag, trend)
    self.X = X
    k = self.k_trend
    k = max(1, k)
    results = {}
    if (ic != 't-stat'):
        for lag in range(k, (maxlag + 1)):
            endog_tmp = endog[(maxlag - lag):]
            fit = AR(endog_tmp).fit(maxlag=lag, method=method, full_output=0, trend=trend, maxiter=100, disp=0)
            results[lag] = eval(('fit.' + ic))
        (bestic, bestlag) = min(((res, k) for (k, res) in iteritems(results)))
    else:
        stop = 1.6448536269514722
        for lag in range(maxlag, (k - 1), (-1)):
            endog_tmp = endog[(maxlag - lag):]
            fit = AR(endog_tmp).fit(maxlag=lag, method=method, full_output=0, trend=trend, maxiter=35, disp=(-1))
            bestlag = 0
            if (np.abs(fit.tvalues[(-1)]) >= stop):
                bestlag = lag
                break
    return bestlag
