# Buggy code
def fit(self, maxlags=None, method="ols", ic=None, trend="c", verbose=False):
    """
    Fit the VAR model

    Parameters
    ----------
    maxlags : int
        Maximum number of lags to check for order selection, defaults to
        12 * (nobs/100.)**(1./4), see select_order function
    method : {'ols'}
        Estimation method to use
    ic : {'aic', 'fpe', 'hqic', 'bic', None}
        Information criterion to use for VAR order selection.
        aic : Akaike
        fpe : Final prediction error
        hqic : Hannan-Quinn
        bic : Bayesian a.k.a. Schwarz
    verbose : bool, default False
        Print order selection output to the screen
    trend, str {"c", "ct", "ctt", "nc"}
        "c" - add constant
        "ct" - constant and trend
        "ctt" - constant, linear and quadratic trend
        "nc" - co constant, no trend
        Note that these are prepended to the columns of the dataset.

    Notes
    -----
    Lutkepohl pp. 146-153

    Returns
    -------
    est : VARResults
    """
    lags = maxlags

    if ic is not None:
        selections = self.select_order(maxlags=maxlags, verbose=verbose)
        if ic not in selections:
            raise Exception(
                "%s not recognized, must be among %s" % (ic, sorted(selections))
            )
        lags = selections[ic]
        if verbose:
            print("Using %d based on %s criterion" % (lags, ic))
    else:
        if lags is None:
            lags = 1

    k_trend = util.get_trendorder(trend)
    self.exog_names = util.make_lag_names(self.endog_names, lags, k_trend)
    self.nobs = len(self.endog) - lags

    return self._estimate_var(lags, trend=trend)


# Traceback (UnboundLocalError)
model_t = VAR(data_t)
results = model.fit(4, trend = 't')

---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
<ipython-input-98-f7328095d596> in <module>()
1 model_t = VAR(data_t)
----> 2 results = model.fit(4, trend = 't')

e:\josef\eclipsegworkspace\statsmodels-git\statsmodels-all-new2_py27\statsmodels\statsmodels\tsa\vector_ar\var_model.py in fit(self, maxlags, method, ic, trend, verbose)
429                 lags = 1
430
--> 431         k_trend = util.get_trendorder(trend)
432         self.exog_names = util.make_lag_names(self.endog_names, lags, k_trend)
433         self.nobs = len(self.endog) - lags

e:\josef\eclipsegworkspace\statsmodels-git\statsmodels-all-new2_py27\statsmodels\statsmodels\tsa\vector_ar\util.pyc in get_trendorder(trend)
45     elif trend == 'ctt':
46         trendorder = 3
---> 47     return trendorder
48
49 def make_lag_names(names, lag_order, trendorder=1):

UnboundLocalError: local variable 'trendorder' referenced before assignment

# Fixed code
def fit(self, maxlags=None, method="ols", ic=None, trend="c", verbose=False):
    """
    Fit the VAR model

    Parameters
    ----------
    maxlags : int
        Maximum number of lags to check for order selection, defaults to
        12 * (nobs/100.)**(1./4), see select_order function
    method : {'ols'}
        Estimation method to use
    ic : {'aic', 'fpe', 'hqic', 'bic', None}
        Information criterion to use for VAR order selection.
        aic : Akaike
        fpe : Final prediction error
        hqic : Hannan-Quinn
        bic : Bayesian a.k.a. Schwarz
    verbose : bool, default False
        Print order selection output to the screen
    trend, str {"c", "ct", "ctt", "nc"}
        "c" - add constant
        "ct" - constant and trend
        "ctt" - constant, linear and quadratic trend
        "nc" - co constant, no trend
        Note that these are prepended to the columns of the dataset.

    Notes
    -----
    Lutkepohl pp. 146-153

    Returns
    -------
    est : VARResults
    """
    lags = maxlags

    if trend not in ["c", "ct", "ctt", "nc"]:
        raise ValueError("trend '{}' not supported for VAR".format(trend))

    if ic is not None:
        selections = self.select_order(maxlags=maxlags, verbose=verbose)
        if ic not in selections:
            raise Exception(
                "%s not recognized, must be among %s" % (ic, sorted(selections))
            )
        lags = selections[ic]
        if verbose:
            print("Using %d based on %s criterion" % (lags, ic))
    else:
        if lags is None:
            lags = 1

    k_trend = util.get_trendorder(trend)
    self.exog_names = util.make_lag_names(self.endog_names, lags, k_trend)
    self.nobs = len(self.endog) - lags

    return self._estimate_var(lags, trend=trend)