def _autolag(mod, endog, exog, startlag, maxlag, method, modargs=(), fitargs=(), regresults=False):
    "\n    Returns the results for the lag length that maximizes the info criterion.\n\n    Parameters\n    ----------\n    mod : Model class\n        Model estimator class\n    endog : array-like\n        nobs array containing endogenous variable\n    exog : array-like\n        nobs by (startlag + maxlag) array containing lags and possibly other\n        variables\n    startlag : int\n        The first zero-indexed column to hold a lag.  See Notes.\n    maxlag : int\n        The highest lag order for lag length selection.\n    method : {'aic', 'bic', 't-stat'}\n        aic - Akaike Information Criterion\n        bic - Bayes Information Criterion\n        t-stat - Based on last lag\n    modargs : tuple, optional\n        args to pass to model.  See notes.\n    fitargs : tuple, optional\n        args to pass to fit.  See notes.\n    regresults : bool, optional\n        Flag indicating to return optional return results\n\n    Returns\n    -------\n    icbest : float\n        Best information criteria.\n    bestlag : int\n        The lag length that maximizes the information criterion.\n    results : dict, optional\n        Dictionary containing all estimation results\n\n    Notes\n    -----\n    Does estimation like mod(endog, exog[:,:i], *modargs).fit(*fitargs)\n    where i goes from lagstart to lagstart+maxlag+1.  Therefore, lags are\n    assumed to be in contiguous columns from low to high lag length with\n    the highest lag in the last column.\n    "
    results = {}
    method = method.lower()
    for lag in range(startlag, ((startlag + maxlag) + 1)):
        mod_instance = mod(endog, exog[:, :lag], *modargs)
        results[lag] = mod_instance.fit()
    if (method == 'aic'):
        (icbest, bestlag) = min(((v.aic, k) for (k, v) in iteritems(results)))
    elif (method == 'bic'):
        (icbest, bestlag) = min(((v.bic, k) for (k, v) in iteritems(results)))
    elif (method == 't-stat'):
        stop = 1.6448536269514722
        for lag in range((startlag + maxlag), (startlag - 1), (- 1)):
            icbest = np.abs(results[lag].tvalues[(- 1)])
            if (np.abs(icbest) >= stop):
                bestlag = lag
                icbest = icbest
                break
    else:
        raise (ValueError('Information Criterion %s not understood.') % method)
    if (not regresults):
        return (icbest, bestlag)
    else:
        return (icbest, bestlag, results)
Returns the results for the lag length that maximizes the info criterion.

Parameters
----------
mod : Model class
    Model estimator class
endog : array-like
    nobs array containing endogenous variable
exog : array-like
    nobs by (startlag + maxlag) array containing lags and possibly other
    variables
startlag : int
    The first zero-indexed column to hold a lag.  See Notes.
maxlag : int
    The highest lag order for lag length selection.
method : {'aic', 'bic', 't-stat'}
    aic - Akaike Information Criterion
    bic - Bayes Information Criterion
    t-stat - Based on last lag
modargs : tuple, optional
    args to pass to model.  See notes.
fitargs : tuple, optional
    args to pass to fit.  See notes.
regresults : bool, optional
    Flag indicating to return optional return results

Returns
-------
icbest : float
    Best information criteria.
bestlag : int
    The lag length that maximizes the information criterion.
results : dict, optional
    Dictionary containing all estimation results

Notes
-----
Does estimation like mod(endog, exog[:,:i], *modargs).fit(*fitargs)
where i goes from lagstart to lagstart+maxlag+1.  Therefore, lags are
assumed to be in contiguous columns from low to high lag length with
the highest lag in the last column.
def _autolag(mod, endog, exog, startlag, maxlag, method, modargs=(), fitargs=(), regresults=False):
    "\n    Returns the results for the lag length that maximizes the info criterion.\n\n    Parameters\n    ----------\n    mod : Model class\n        Model estimator class\n    endog : array-like\n        nobs array containing endogenous variable\n    exog : array-like\n        nobs by (startlag + maxlag) array containing lags and possibly other\n        variables\n    startlag : int\n        The first zero-indexed column to hold a lag.  See Notes.\n    maxlag : int\n        The highest lag order for lag length selection.\n    method : {'aic', 'bic', 't-stat'}\n        aic - Akaike Information Criterion\n        bic - Bayes Information Criterion\n        t-stat - Based on last lag\n    modargs : tuple, optional\n        args to pass to model.  See notes.\n    fitargs : tuple, optional\n        args to pass to fit.  See notes.\n    regresults : bool, optional\n        Flag indicating to return optional return results\n\n    Returns\n    -------\n    icbest : float\n        Best information criteria.\n    bestlag : int\n        The lag length that maximizes the information criterion.\n    results : dict, optional\n        Dictionary containing all estimation results\n\n    Notes\n    -----\n    Does estimation like mod(endog, exog[:,:i], *modargs).fit(*fitargs)\n    where i goes from lagstart to lagstart+maxlag+1.  Therefore, lags are\n    assumed to be in contiguous columns from low to high lag length with\n    the highest lag in the last column.\n    "
    results = {}
    method = method.lower()
    for lag in range(startlag, ((startlag + maxlag) + 1)):
        mod_instance = mod(endog, exog[:, :lag], *modargs)
        results[lag] = mod_instance.fit()
    if (method == 'aic'):
        (icbest, bestlag) = min(((v.aic, k) for (k, v) in iteritems(results)))
    elif (method == 'bic'):
        (icbest, bestlag) = min(((v.bic, k) for (k, v) in iteritems(results)))
    elif (method == 't-stat'):
        stop = 1.6448536269514722
        for lag in range((startlag + maxlag), (startlag - 1), (- 1)):
            icbest = np.abs(results[lag].tvalues[(- 1)])
            if (np.abs(icbest) >= stop):
                bestlag = lag
                icbest = icbest
                break
    else:
        raise (ValueError('Information Criterion %s not understood.') % method)
    if (not regresults):
        return (icbest, bestlag)
    else:
        return (icbest, bestlag, results)