Ejemplo n.º 1
0
    def __init__(self, y, x, yend, q,
                 w=None,
                 robust=None, gwk=None, sig2n_k=False,
                 spat_diag=False,
                 vm=False, name_y=None, name_x=None,
                 name_yend=None, name_q=None,
                 name_w=None, name_gwk=None, name_ds=None):

        n = USER.check_arrays(y, x, yend, q)
        USER.check_y(y, n)
        USER.check_weights(w, y)
        USER.check_robust(robust, gwk)
        USER.check_spat_diag(spat_diag, w)
        x_constant = USER.check_constant(x)
        BaseTSLS.__init__(self, y=y, x=x_constant, yend=yend, q=q,
                          robust=robust, gwk=gwk, sig2n_k=sig2n_k)
        self.title = "TWO STAGE LEAST SQUARES"
        self.name_ds = USER.set_name_ds(name_ds)
        self.name_y = USER.set_name_y(name_y)
        self.name_x = USER.set_name_x(name_x, x)
        self.name_yend = USER.set_name_yend(name_yend, yend)
        self.name_z = self.name_x + self.name_yend
        self.name_q = USER.set_name_q(name_q, q)
        self.name_h = USER.set_name_h(self.name_x, self.name_q)
        self.robust = USER.set_robust(robust)
        self.name_w = USER.set_name_w(name_w, w)
        self.name_gwk = USER.set_name_w(name_gwk, gwk)
        SUMMARY.TSLS(reg=self, vm=vm, w=w, spat_diag=spat_diag)
Ejemplo n.º 2
0
    def __init__(self, y, x, regimes,
                 w=None, robust=None, gwk=None, sig2n_k=True,
                 nonspat_diag=True, spat_diag=False, moran=False, white_test=False,
                 vm=False, constant_regi='many', cols2regi='all',
                 regime_err_sep=True, cores=False,
                 name_y=None, name_x=None, name_regimes=None,
                 name_w=None, name_gwk=None, name_ds=None):

        n = USER.check_arrays(y, x)
        USER.check_y(y, n)
        USER.check_weights(w, y)
        USER.check_robust(robust, gwk)
        USER.check_spat_diag(spat_diag, w)
        self.name_x_r = USER.set_name_x(name_x, x)
        self.constant_regi = constant_regi
        self.cols2regi = cols2regi
        self.name_w = USER.set_name_w(name_w, w)
        self.name_gwk = USER.set_name_w(name_gwk, gwk)
        self.name_ds = USER.set_name_ds(name_ds)
        self.name_y = USER.set_name_y(name_y)
        self.name_regimes = USER.set_name_ds(name_regimes)
        self.n = n
        cols2regi = REGI.check_cols2regi(
            constant_regi, cols2regi, x, add_cons=False)
        self.regimes_set = REGI._get_regimes_set(regimes)
        self.regimes = regimes
        USER.check_regimes(self.regimes_set, self.n, x.shape[1])
        if regime_err_sep == True and robust == 'hac':
            set_warn(
                self, "Error by regimes is incompatible with HAC estimation. Hence, error by regimes has been disabled for this model.")
            regime_err_sep = False
        self.regime_err_sep = regime_err_sep
        if regime_err_sep == True and set(cols2regi) == set([True]) and constant_regi == 'many':
            self.y = y
            name_x = USER.set_name_x(name_x, x)
            regi_ids = dict(
                (r, list(np.where(np.array(regimes) == r)[0])) for r in self.regimes_set)
            self._ols_regimes_multi(x, w, regi_ids, cores,
                                    gwk, sig2n_k, robust, nonspat_diag, spat_diag, vm, name_x, moran, white_test)
        else:
            name_x = USER.set_name_x(name_x, x, constant=True)
            x, self.name_x = REGI.Regimes_Frame.__init__(self, x,
                                                         regimes, constant_regi, cols2regi, name_x)
            BaseOLS.__init__(
                self, y=y, x=x, robust=robust, gwk=gwk, sig2n_k=sig2n_k)
            if regime_err_sep == True and robust == None:
                y2, x2 = REGI._get_weighted_var(
                    regimes, self.regimes_set, sig2n_k, self.u, y, x)
                ols2 = BaseOLS(y=y2, x=x2, sig2n_k=sig2n_k)
                RegressionProps_basic(self, betas=ols2.betas, vm=ols2.vm)
                self.title = "ORDINARY LEAST SQUARES - REGIMES (Group-wise heteroskedasticity)"
                nonspat_diag = None
                set_warn(
                    self, "Residuals treated as homoskedastic for the purpose of diagnostics.")
            else:
                self.title = "ORDINARY LEAST SQUARES - REGIMES"
            self.robust = USER.set_robust(robust)
            self.chow = REGI.Chow(self)
            SUMMARY.OLS(reg=self, vm=vm, w=w, nonspat_diag=nonspat_diag,
                        spat_diag=spat_diag, moran=moran, white_test=white_test, regimes=True)
Ejemplo n.º 3
0
    def __init__(self, y, x, yend=None, q=None,\
                 w=None, w_lags=1, lag_q=True,\
                 robust=None, gwk=None, sig2n_k=False,\
                 spat_diag=False,\
                 vm=False, name_y=None, name_x=None,\
                 name_yend=None, name_q=None,\
                 name_w=None, name_gwk=None, name_ds=None):

        n = USER.check_arrays(x, yend, q)
        USER.check_y(y, n)
        USER.check_weights(w, y, w_required=True)
        USER.check_robust(robust, gwk)
        yend2, q2 = set_endog(y, x, w, yend, q, w_lags, lag_q)
        x_constant = USER.check_constant(x)
        BaseGM_Lag.__init__(self, y=y, x=x_constant, w=w.sparse, yend=yend2, q=q2,\
                            w_lags=w_lags, robust=robust, gwk=gwk,\
                            lag_q=lag_q, sig2n_k=sig2n_k)
        self.predy_e, self.e_pred, warn = sp_att(w,self.y,self.predy,\
                      yend2[:,-1].reshape(self.n,1),self.betas[-1])
        set_warn(self,warn)
        self.title = "SPATIAL TWO STAGE LEAST SQUARES"        
        self.name_ds = USER.set_name_ds(name_ds)
        self.name_y = USER.set_name_y(name_y)
        self.name_x = USER.set_name_x(name_x, x)
        self.name_yend = USER.set_name_yend(name_yend, yend)
        self.name_yend.append(USER.set_name_yend_sp(self.name_y))
        self.name_z = self.name_x + self.name_yend
        self.name_q = USER.set_name_q(name_q, q)
        self.name_q.extend(USER.set_name_q_sp(self.name_x, w_lags, self.name_q, lag_q))
        self.name_h = USER.set_name_h(self.name_x, self.name_q)
        self.robust = USER.set_robust(robust)
        self.name_w = USER.set_name_w(name_w, w)
        self.name_gwk = USER.set_name_w(name_gwk, gwk)
        SUMMARY.GM_Lag(reg=self, w=w, vm=vm, spat_diag=spat_diag)
Ejemplo n.º 4
0
    def __init__(self, y, x, yend, q,
                 w=None,
                 robust=None, gwk=None, sig2n_k=False,
                 spat_diag=False,
                 vm=False, name_y=None, name_x=None,
                 name_yend=None, name_q=None,
                 name_w=None, name_gwk=None, name_ds=None):

        n = USER.check_arrays(y, x, yend, q)
        USER.check_y(y, n)
        USER.check_weights(w, y)
        USER.check_robust(robust, gwk)
        USER.check_spat_diag(spat_diag, w)
        x_constant = USER.check_constant(x)
        BaseTSLS.__init__(self, y=y, x=x_constant, yend=yend, q=q,
                          robust=robust, gwk=gwk, sig2n_k=sig2n_k)
        self.title = "TWO STAGE LEAST SQUARES"
        self.name_ds = USER.set_name_ds(name_ds)
        self.name_y = USER.set_name_y(name_y)
        self.name_x = USER.set_name_x(name_x, x)
        self.name_yend = USER.set_name_yend(name_yend, yend)
        self.name_z = self.name_x + self.name_yend
        self.name_q = USER.set_name_q(name_q, q)
        self.name_h = USER.set_name_h(self.name_x, self.name_q)
        self.robust = USER.set_robust(robust)
        self.name_w = USER.set_name_w(name_w, w)
        self.name_gwk = USER.set_name_w(name_gwk, gwk)
        SUMMARY.TSLS(reg=self, vm=vm, w=w, spat_diag=spat_diag)
Ejemplo n.º 5
0
    def __init__(self, y, x, yend=None, q=None,\
                 w=None, w_lags=1, lag_q=True,\
                 robust=None, gwk=None, sig2n_k=False,\
                 spat_diag=False,\
                 vm=False, name_y=None, name_x=None,\
                 name_yend=None, name_q=None,\
                 name_w=None, name_gwk=None, name_ds=None):

        n = USER.check_arrays(x, yend, q)
        USER.check_y(y, n)
        USER.check_weights(w, y, w_required=True)
        USER.check_robust(robust, gwk)
        yend2, q2 = set_endog(y, x, w, yend, q, w_lags, lag_q)
        x_constant = USER.check_constant(x)
        BaseGM_Lag.__init__(self, y=y, x=x_constant, w=w.sparse, yend=yend2, q=q2,\
                            w_lags=w_lags, robust=robust, gwk=gwk,\
                            lag_q=lag_q, sig2n_k=sig2n_k)
        self.predy_e, self.e_pred, warn = sp_att(w,self.y,self.predy,\
                      yend2[:,-1].reshape(self.n,1),self.betas[-1])
        set_warn(self, warn)
        self.title = "SPATIAL TWO STAGE LEAST SQUARES"
        self.name_ds = USER.set_name_ds(name_ds)
        self.name_y = USER.set_name_y(name_y)
        self.name_x = USER.set_name_x(name_x, x)
        self.name_yend = USER.set_name_yend(name_yend, yend)
        self.name_yend.append(USER.set_name_yend_sp(self.name_y))
        self.name_z = self.name_x + self.name_yend
        self.name_q = USER.set_name_q(name_q, q)
        self.name_q.extend(
            USER.set_name_q_sp(self.name_x, w_lags, self.name_q, lag_q))
        self.name_h = USER.set_name_h(self.name_x, self.name_q)
        self.robust = USER.set_robust(robust)
        self.name_w = USER.set_name_w(name_w, w)
        self.name_gwk = USER.set_name_w(name_gwk, gwk)
        SUMMARY.GM_Lag(reg=self, w=w, vm=vm, spat_diag=spat_diag)
Ejemplo n.º 6
0
    def __init__(self, y, x, regimes,
                 w=None, robust=None, gwk=None, sig2n_k=True,
                 nonspat_diag=True, spat_diag=False, moran=False, white_test=False,
                 vm=False, constant_regi='many', cols2regi='all',
                 regime_err_sep=True, cores=None,
                 name_y=None, name_x=None, name_regimes=None,
                 name_w=None, name_gwk=None, name_ds=None):

        n = USER.check_arrays(y, x)
        USER.check_y(y, n)
        USER.check_weights(w, y)
        USER.check_robust(robust, gwk)
        USER.check_spat_diag(spat_diag, w)
        self.name_x_r = USER.set_name_x(name_x, x)
        self.constant_regi = constant_regi
        self.cols2regi = cols2regi
        self.name_w = USER.set_name_w(name_w, w)
        self.name_gwk = USER.set_name_w(name_gwk, gwk)
        self.name_ds = USER.set_name_ds(name_ds)
        self.name_y = USER.set_name_y(name_y)
        self.name_regimes = USER.set_name_ds(name_regimes)
        self.n = n
        cols2regi = REGI.check_cols2regi(
            constant_regi, cols2regi, x, add_cons=False)
        self.regimes_set = REGI._get_regimes_set(regimes)
        self.regimes = regimes
        USER.check_regimes(self.regimes_set, self.n, x.shape[1])
        if regime_err_sep == True and robust == 'hac':
            set_warn(
                self, "Error by regimes is incompatible with HAC estimation. Hence, error by regimes has been disabled for this model.")
            regime_err_sep = False
        self.regime_err_sep = regime_err_sep
        if regime_err_sep == True and set(cols2regi) == set([True]) and constant_regi == 'many':
            self.y = y
            name_x = USER.set_name_x(name_x, x)
            regi_ids = dict((r, list(np.where(np.array(regimes) == r)[0]))
                            for r in self.regimes_set)
            self._ols_regimes_multi(x, w, regi_ids, cores,
                                    gwk, sig2n_k, robust, nonspat_diag, spat_diag, vm, name_x, moran, white_test)
        else:
            name_x = USER.set_name_x(name_x, x, constant=True)
            x, self.name_x = REGI.Regimes_Frame.__init__(self, x,
                                                         regimes, constant_regi, cols2regi, name_x)
            BaseOLS.__init__(self, y=y, x=x, robust=robust,
                             gwk=gwk, sig2n_k=sig2n_k)
            if regime_err_sep == True and robust == None:
                y2, x2 = REGI._get_weighted_var(
                    regimes, self.regimes_set, sig2n_k, self.u, y, x)
                ols2 = BaseOLS(y=y2, x=x2, sig2n_k=sig2n_k)
                RegressionProps_basic(self, betas=ols2.betas, vm=ols2.vm)
                self.title = "ORDINARY LEAST SQUARES - REGIMES (Group-wise heteroskedasticity)"
                nonspat_diag = None
                set_warn(
                    self, "Residuals treated as homoskedastic for the purpose of diagnostics.")
            else:
                self.title = "ORDINARY LEAST SQUARES - REGIMES"
            self.robust = USER.set_robust(robust)
            self.chow = REGI.Chow(self)
            SUMMARY.OLS(reg=self, vm=vm, w=w, nonspat_diag=nonspat_diag,
                        spat_diag=spat_diag, moran=moran, white_test=white_test, regimes=True)
Ejemplo n.º 7
0
 def __init__(self, y, x, yend, q, regimes,\
          w=None, robust=None, gwk=None, sig2n_k=True,\
          spat_diag=False, vm=False, constant_regi='many',\
          cols2regi='all', regime_err_sep=False, name_y=None, name_x=None,\
          cores=None, name_yend=None, name_q=None, name_regimes=None,\
          name_w=None, name_gwk=None, name_ds=None, summ=True):
    
     n = USER.check_arrays(y, x)
     USER.check_y(y, n)
     USER.check_weights(w, y)
     USER.check_robust(robust, gwk)
     USER.check_spat_diag(spat_diag, w)
     self.constant_regi = constant_regi
     self.cols2regi = cols2regi
     self.name_ds = USER.set_name_ds(name_ds)
     self.name_regimes = USER.set_name_ds(name_regimes)
     self.name_w = USER.set_name_w(name_w, w)
     self.name_gwk = USER.set_name_w(name_gwk, gwk)
     self.name_y = USER.set_name_y(name_y)
     name_yend = USER.set_name_yend(name_yend, yend)
     name_q = USER.set_name_q(name_q, q)
     self.name_x_r = USER.set_name_x(name_x, x) + name_yend            
     self.n = n
     if regime_err_sep == True:
         name_x = USER.set_name_x(name_x, x)
         self.y = y
         if cols2regi == 'all':
             cols2regi = [True] * (x.shape[1]+yend.shape[1])
         self.regimes_set = list(set(regimes))
         self.regimes_set.sort()
         if w:
             w_i,regi_ids,warn = REGI.w_regimes(w, regimes, self.regimes_set, transform=True, get_ids=True, min_n=len(self.cols2regi)+1)
             set_warn(self,warn)
         else:
             regi_ids = dict((r, list(np.where(np.array(regimes) == r)[0])) for r in self.regimes_set)
             w_i = None
         if set(cols2regi) == set([True]):
             self._tsls_regimes_multi(x, yend, q, w_i, regi_ids, cores,\
              gwk, sig2n_k, robust, spat_diag, vm, name_x, name_yend, name_q)
         else:
             raise Exception, "All coefficients must vary accross regimes if regime_err_sep = True."
     else:
         name_x = USER.set_name_x(name_x, x,constant=True)
         q, self.name_q = REGI.Regimes_Frame.__init__(self, q, \
                 regimes, constant_regi=None, cols2regi='all', names=name_q)
         x, self.name_x = REGI.Regimes_Frame.__init__(self, x, \
                 regimes, constant_regi, cols2regi=cols2regi, names=name_x)
         yend, self.name_yend = REGI.Regimes_Frame.__init__(self, yend, \
                 regimes, constant_regi=None, \
                 cols2regi=cols2regi, yend=True, names=name_yend)
         BaseTSLS.__init__(self, y=y, x=x, yend=yend, q=q, \
                 robust=robust, gwk=gwk, sig2n_k=sig2n_k)
         self.name_z = self.name_x + self.name_yend
         self.name_h = USER.set_name_h(self.name_x, self.name_q)
         self.chow = REGI.Chow(self)
         self.robust = USER.set_robust(robust)
         if summ:
             self.title = "TWO STAGE LEAST SQUARES - REGIMES"
             SUMMARY.TSLS(reg=self, vm=vm, w=w, spat_diag=spat_diag, regimes=True)
Ejemplo n.º 8
0
 def __init__(self, y, x, regimes,\
              w=None, robust=None, gwk=None, sig2n_k=True,\
              nonspat_diag=True, spat_diag=False, moran=False,\
              vm=False, constant_regi='many', cols2regi='all',\
              regime_err_sep=False, cores=None,\
              name_y=None, name_x=None, name_regimes=None,\
              name_w=None, name_gwk=None, name_ds=None):         
     
     n = USER.check_arrays(y, x)
     USER.check_y(y, n)
     USER.check_weights(w, y)
     USER.check_robust(robust, gwk)
     USER.check_spat_diag(spat_diag, w)
     self.name_x_r = USER.set_name_x(name_x, x)
     self.constant_regi = constant_regi
     self.cols2regi = cols2regi        
     self.name_w = USER.set_name_w(name_w, w)
     self.name_gwk = USER.set_name_w(name_gwk, gwk)
     self.name_ds = USER.set_name_ds(name_ds)
     self.name_y = USER.set_name_y(name_y)
     self.name_regimes = USER.set_name_ds(name_regimes)
     self.n = n        
     if regime_err_sep == True:
         name_x = USER.set_name_x(name_x, x)
         self.y = y
         if cols2regi == 'all':
             cols2regi = [True] * (x.shape[1])
         self.regimes_set = list(set(regimes))
         self.regimes_set.sort()
         if w:
             w_i,regi_ids,warn = REGI.w_regimes(w, regimes, self.regimes_set, transform=True, get_ids=True, min_n=len(self.cols2regi)+1)
             set_warn(self,warn)
         else:
             regi_ids = dict((r, list(np.where(np.array(regimes) == r)[0])) for r in self.regimes_set)
             w_i = None
         if set(cols2regi) == set([True]):
             self._ols_regimes_multi(x, w_i, regi_ids, cores,\
              gwk, sig2n_k, robust, nonspat_diag, spat_diag, vm, name_x, moran)
         else:
             raise Exception, "All coefficients must vary accross regimes if regime_err_sep = True."
     else:
         name_x = USER.set_name_x(name_x, x,constant=True)
         x, self.name_x = REGI.Regimes_Frame.__init__(self, x,\
                 regimes, constant_regi, cols2regi, name_x)
         BaseOLS.__init__(self, y=y, x=x, robust=robust, gwk=gwk, \
                 sig2n_k=sig2n_k)
         self.title = "ORDINARY LEAST SQUARES - REGIMES"
         self.robust = USER.set_robust(robust)
         self.chow = REGI.Chow(self)
         SUMMARY.OLS(reg=self, vm=vm, w=w, nonspat_diag=nonspat_diag,\
                     spat_diag=spat_diag, moran=moran, regimes=True)
Ejemplo n.º 9
0
    def __init__(self,
                 y,
                 x,
                 w=None,
                 robust=None,
                 gwk=None,
                 sig2n_k=True,
                 nonspat_diag=True,
                 spat_diag=False,
                 moran=False,
                 white_test=False,
                 vm=False,
                 name_y=None,
                 name_x=None,
                 name_w=None,
                 name_gwk=None,
                 name_ds=None):

        n = USER.check_arrays(y, x)
        y = USER.check_y(y, n)
        USER.check_weights(w, y)
        USER.check_robust(robust, gwk)
        USER.check_spat_diag(spat_diag, w)
        x_constant = USER.check_constant(x)
        BaseOLS.__init__(self,
                         y=y,
                         x=x_constant,
                         robust=robust,
                         gwk=gwk,
                         sig2n_k=sig2n_k)
        self.title = "ORDINARY LEAST SQUARES"
        self.name_ds = USER.set_name_ds(name_ds)
        self.name_y = USER.set_name_y(name_y)
        self.name_x = USER.set_name_x(name_x, x)
        self.robust = USER.set_robust(robust)
        self.name_w = USER.set_name_w(name_w, w)
        self.name_gwk = USER.set_name_w(name_gwk, gwk)
        SUMMARY.OLS(reg=self,
                    vm=vm,
                    w=w,
                    nonspat_diag=nonspat_diag,
                    spat_diag=spat_diag,
                    moran=moran,
                    white_test=white_test)
Ejemplo n.º 10
0
    def __init__(self, y, x,\
                 w=None,\
                 robust=None, gwk=None, sig2n_k=True,\
                 nonspat_diag=True, spat_diag=False, moran=False,\
                 vm=False, name_y=None, name_x=None,\
                 name_w=None, name_gwk=None, name_ds=None):

        n = USER.check_arrays(y, x)
        USER.check_y(y, n)
        USER.check_weights(w, y)
        USER.check_robust(robust, gwk)
        USER.check_spat_diag(spat_diag, w)
        x_constant = USER.check_constant(x)
        BaseOLS.__init__(self, y=y, x=x_constant, robust=robust,\
                     gwk=gwk, sig2n_k=sig2n_k) 
        self.title = "ORDINARY LEAST SQUARES"
        self.name_ds = USER.set_name_ds(name_ds)
        self.name_y = USER.set_name_y(name_y)
        self.name_x = USER.set_name_x(name_x, x)
        self.robust = USER.set_robust(robust)
        self.name_w = USER.set_name_w(name_w, w)
        self.name_gwk = USER.set_name_w(name_gwk, gwk)
        SUMMARY.OLS(reg=self, vm=vm, w=w, nonspat_diag=nonspat_diag,\
                    spat_diag=spat_diag, moran=moran)
Ejemplo n.º 11
0
    def __init__(self,
                 y,
                 x,
                 regimes,
                 yend=None,
                 q=None,
                 w=None,
                 w_lags=1,
                 lag_q=True,
                 robust=None,
                 gwk=None,
                 sig2n_k=False,
                 spat_diag=False,
                 constant_regi='many',
                 cols2regi='all',
                 regime_lag_sep=False,
                 regime_err_sep=True,
                 cores=False,
                 vm=False,
                 name_y=None,
                 name_x=None,
                 name_yend=None,
                 name_q=None,
                 name_regimes=None,
                 name_w=None,
                 name_gwk=None,
                 name_ds=None):

        n = USER.check_arrays(y, x)
        USER.check_y(y, n)
        USER.check_weights(w, y, w_required=True)
        USER.check_robust(robust, gwk)
        USER.check_spat_diag(spat_diag, w)
        name_x = USER.set_name_x(name_x, x, constant=True)
        name_y = USER.set_name_y(name_y)
        name_yend = USER.set_name_yend(name_yend, yend)
        name_q = USER.set_name_q(name_q, q)
        name_q.extend(
            USER.set_name_q_sp(name_x, w_lags, name_q, lag_q, force_all=True))
        self.name_regimes = USER.set_name_ds(name_regimes)
        self.constant_regi = constant_regi
        self.n = n
        cols2regi = REGI.check_cols2regi(constant_regi,
                                         cols2regi,
                                         x,
                                         yend=yend,
                                         add_cons=False)
        self.cols2regi = cols2regi
        self.regimes_set = REGI._get_regimes_set(regimes)
        self.regimes = regimes
        USER.check_regimes(self.regimes_set, self.n, x.shape[1])
        if regime_err_sep == True and robust == 'hac':
            set_warn(
                self,
                "Error by regimes is incompatible with HAC estimation for Spatial Lag models. Hence, error and lag by regimes have been disabled for this model."
            )
            regime_err_sep = False
            regime_lag_sep = False
        self.regime_err_sep = regime_err_sep
        self.regime_lag_sep = regime_lag_sep
        if regime_lag_sep == True:
            if not regime_err_sep:
                raise Exception, "regime_err_sep must be True when regime_lag_sep=True."
            cols2regi += [True]
            w_i, regi_ids, warn = REGI.w_regimes(w,
                                                 regimes,
                                                 self.regimes_set,
                                                 transform=True,
                                                 get_ids=True,
                                                 min_n=len(cols2regi) + 1)
            set_warn(self, warn)

        else:
            cols2regi += [False]

        if regime_err_sep == True and set(cols2regi) == set(
            [True]) and constant_regi == 'many':
            self.y = y
            self.GM_Lag_Regimes_Multi(y,
                                      x,
                                      w_i,
                                      w,
                                      regi_ids,
                                      yend=yend,
                                      q=q,
                                      w_lags=w_lags,
                                      lag_q=lag_q,
                                      cores=cores,
                                      robust=robust,
                                      gwk=gwk,
                                      sig2n_k=sig2n_k,
                                      cols2regi=cols2regi,
                                      spat_diag=spat_diag,
                                      vm=vm,
                                      name_y=name_y,
                                      name_x=name_x,
                                      name_yend=name_yend,
                                      name_q=name_q,
                                      name_regimes=self.name_regimes,
                                      name_w=name_w,
                                      name_gwk=name_gwk,
                                      name_ds=name_ds)
        else:
            if regime_lag_sep == True:
                w = REGI.w_regimes_union(w, w_i, self.regimes_set)
            yend2, q2 = set_endog(y, x, w, yend, q, w_lags, lag_q)
            name_yend.append(USER.set_name_yend_sp(name_y))
            TSLS_Regimes.__init__(self,
                                  y=y,
                                  x=x,
                                  yend=yend2,
                                  q=q2,
                                  regimes=regimes,
                                  w=w,
                                  robust=robust,
                                  gwk=gwk,
                                  sig2n_k=sig2n_k,
                                  spat_diag=spat_diag,
                                  vm=vm,
                                  constant_regi=constant_regi,
                                  cols2regi=cols2regi,
                                  regime_err_sep=regime_err_sep,
                                  name_y=name_y,
                                  name_x=name_x,
                                  name_yend=name_yend,
                                  name_q=name_q,
                                  name_regimes=name_regimes,
                                  name_w=name_w,
                                  name_gwk=name_gwk,
                                  name_ds=name_ds,
                                  summ=False)
            if regime_lag_sep:
                self.sp_att_reg(w_i, regi_ids, yend2[:, -1].reshape(self.n, 1))
            else:
                self.rho = self.betas[-1]
                self.predy_e, self.e_pred, warn = sp_att(
                    w, self.y, self.predy, yend2[:, -1].reshape(self.n, 1),
                    self.rho)
                set_warn(self, warn)
            self.regime_lag_sep = regime_lag_sep
            self.title = "SPATIAL " + self.title
            SUMMARY.GM_Lag(reg=self,
                           w=w,
                           vm=vm,
                           spat_diag=spat_diag,
                           regimes=True)
Ejemplo n.º 12
0
    def __init__(self, y, x, regimes, yend=None, q=None,\
                 w=None, w_lags=1, lag_q=True,\
                 robust=None, gwk=None, sig2n_k=False,\
                 spat_diag=False, constant_regi='many',\
                 cols2regi='all', regime_lag_sep=False, regime_err_sep=True,\
                 cores=None, vm=False, name_y=None, name_x=None,\
                 name_yend=None, name_q=None, name_regimes=None,\
                 name_w=None, name_gwk=None, name_ds=None):

        n = USER.check_arrays(y, x)
        USER.check_y(y, n)
        USER.check_weights(w, y, w_required=True)
        USER.check_robust(robust, gwk)
        USER.check_spat_diag(spat_diag, w)
        name_x = USER.set_name_x(name_x, x, constant=True)
        name_y = USER.set_name_y(name_y)
        name_yend = USER.set_name_yend(name_yend, yend)
        name_q = USER.set_name_q(name_q, q)
        name_q.extend(
            USER.set_name_q_sp(name_x, w_lags, name_q, lag_q, force_all=True))
        self.name_regimes = USER.set_name_ds(name_regimes)
        self.constant_regi = constant_regi
        self.n = n
        cols2regi = REGI.check_cols2regi(constant_regi,
                                         cols2regi,
                                         x,
                                         yend=yend,
                                         add_cons=False)
        self.cols2regi = cols2regi
        self.regimes_set = REGI._get_regimes_set(regimes)
        self.regimes = regimes
        USER.check_regimes(self.regimes_set)
        self.regime_err_sep = regime_err_sep
        self.regime_lag_sep = regime_lag_sep
        if regime_lag_sep == True:
            if not regime_err_sep:
                raise Exception, "regime_err_sep must be True when regime_lag_sep=True."
            cols2regi += [True]
            w_i, regi_ids, warn = REGI.w_regimes(w,
                                                 regimes,
                                                 self.regimes_set,
                                                 transform=True,
                                                 get_ids=True,
                                                 min_n=len(cols2regi) + 1)
            set_warn(self, warn)

        else:
            cols2regi += [False]

        if regime_err_sep == True and set(cols2regi) == set(
            [True]) and constant_regi == 'many':
            self.y = y
            self.GM_Lag_Regimes_Multi(y, x, w_i, regi_ids,\
                 yend=yend, q=q, w_lags=w_lags, lag_q=lag_q, cores=cores,\
                 robust=robust, gwk=gwk, sig2n_k=sig2n_k, cols2regi=cols2regi,\
                 spat_diag=spat_diag, vm=vm, name_y=name_y, name_x=name_x,\
                 name_yend=name_yend, name_q=name_q, name_regimes=self.name_regimes,\
                 name_w=name_w, name_gwk=name_gwk, name_ds=name_ds)
        else:
            if regime_lag_sep == True:
                w = REGI.w_regimes_union(w, w_i, self.regimes_set)
            yend2, q2 = set_endog(y, x, w, yend, q, w_lags, lag_q)
            name_yend.append(USER.set_name_yend_sp(name_y))
            TSLS_Regimes.__init__(self, y=y, x=x, yend=yend2, q=q2,\
                 regimes=regimes, w=w, robust=robust, gwk=gwk,\
                 sig2n_k=sig2n_k, spat_diag=spat_diag, vm=vm,\
                 constant_regi=constant_regi, cols2regi=cols2regi, regime_err_sep=regime_err_sep,\
                 name_y=name_y, name_x=name_x, name_yend=name_yend, name_q=name_q,\
                 name_regimes=name_regimes, name_w=name_w, name_gwk=name_gwk,\
                 name_ds=name_ds,summ=False)
            if regime_lag_sep:
                self.sp_att_reg(w_i, regi_ids, yend2[:, -1].reshape(self.n, 1))
            else:
                self.predy_e, self.e_pred, warn = sp_att(w,self.y,self.predy,\
                          yend2[:,-1].reshape(self.n,1),self.betas[-1])
                set_warn(self, warn)
            self.regime_lag_sep = regime_lag_sep
            if regime_err_sep == True:
                self.title = "SPATIAL TWO STAGE LEAST SQUARES - REGIMES (Group-wise heteroskedasticity)"
            else:
                self.title = "SPATIAL TWO STAGE LEAST SQUARES - REGIMES"
            SUMMARY.GM_Lag(reg=self,
                           w=w,
                           vm=vm,
                           spat_diag=spat_diag,
                           regimes=True)
Ejemplo n.º 13
0
    def __init__(self, y, x, yend, q, regimes,
                 w=None, robust=None, gwk=None, sig2n_k=True,
                 spat_diag=False, vm=False, constant_regi='many',
                 cols2regi='all', regime_err_sep=True, name_y=None, name_x=None,
                 cores=None, name_yend=None, name_q=None, name_regimes=None,
                 name_w=None, name_gwk=None, name_ds=None, summ=True):

        n = USER.check_arrays(y, x)
        USER.check_y(y, n)
        USER.check_weights(w, y)
        USER.check_robust(robust, gwk)
        USER.check_spat_diag(spat_diag, w)
        self.constant_regi = constant_regi
        self.cols2regi = cols2regi
        self.name_ds = USER.set_name_ds(name_ds)
        self.name_regimes = USER.set_name_ds(name_regimes)
        self.name_w = USER.set_name_w(name_w, w)
        self.name_gwk = USER.set_name_w(name_gwk, gwk)
        self.name_y = USER.set_name_y(name_y)
        name_yend = USER.set_name_yend(name_yend, yend)
        name_q = USER.set_name_q(name_q, q)
        self.name_x_r = USER.set_name_x(name_x, x) + name_yend
        self.n = n
        cols2regi = REGI.check_cols2regi(
            constant_regi, cols2regi, x, yend=yend, add_cons=False)
        self.regimes_set = REGI._get_regimes_set(regimes)
        self.regimes = regimes
        USER.check_regimes(self.regimes_set, self.n, x.shape[1])
        if regime_err_sep == True and robust == 'hac':
            set_warn(
                self, "Error by regimes is incompatible with HAC estimation for 2SLS models. Hence, the error by regimes has been disabled for this model.")
            regime_err_sep = False
        self.regime_err_sep = regime_err_sep
        if regime_err_sep == True and set(cols2regi) == set([True]) and constant_regi == 'many':
            name_x = USER.set_name_x(name_x, x)
            self.y = y
            regi_ids = dict((r, list(np.where(np.array(regimes) == r)[0]))
                            for r in self.regimes_set)
            self._tsls_regimes_multi(x, yend, q, w, regi_ids, cores,
                                     gwk, sig2n_k, robust, spat_diag, vm, name_x, name_yend, name_q)
        else:
            name_x = USER.set_name_x(name_x, x, constant=True)
            q, self.name_q = REGI.Regimes_Frame.__init__(self, q,
                                                         regimes, constant_regi=None, cols2regi='all', names=name_q)
            x, self.name_x = REGI.Regimes_Frame.__init__(self, x,
                                                         regimes, constant_regi, cols2regi=cols2regi, names=name_x)
            yend, self.name_yend = REGI.Regimes_Frame.__init__(self, yend,
                                                               regimes, constant_regi=None,
                                                               cols2regi=cols2regi, yend=True, names=name_yend)
            if regime_err_sep == True and robust == None:
                robust = 'white'
            BaseTSLS.__init__(self, y=y, x=x, yend=yend, q=q,
                              robust=robust, gwk=gwk, sig2n_k=sig2n_k)
            self.title = "TWO STAGE LEAST SQUARES - REGIMES"
            if robust == 'ogmm':
                _optimal_weight(self, sig2n_k)
            self.name_z = self.name_x + self.name_yend
            self.name_h = USER.set_name_h(self.name_x, self.name_q)
            self.chow = REGI.Chow(self)
            self.robust = USER.set_robust(robust)
            if summ:
                SUMMARY.TSLS(reg=self, vm=vm, w=w,
                             spat_diag=spat_diag, regimes=True)
Ejemplo n.º 14
0
    def __init__(self, y, x, regimes, yend=None, q=None,\
                 w=None, w_lags=1, lag_q=True,\
                 robust=None, gwk=None, sig2n_k=False,\
                 spat_diag=False, constant_regi='many',\
                 cols2regi='all', regime_lag_sep=False, regime_err_sep=True,\
                 cores=None, vm=False, name_y=None, name_x=None,\
                 name_yend=None, name_q=None, name_regimes=None,\
                 name_w=None, name_gwk=None, name_ds=None):

        n = USER.check_arrays(y, x)
        USER.check_y(y, n)
        USER.check_weights(w, y, w_required=True)
        USER.check_robust(robust, gwk)
        USER.check_spat_diag(spat_diag, w)
        name_x = USER.set_name_x(name_x, x,constant=True)
        name_y = USER.set_name_y(name_y)
        name_yend = USER.set_name_yend(name_yend, yend)
        name_q = USER.set_name_q(name_q, q)
        name_q.extend(USER.set_name_q_sp(name_x, w_lags, name_q, lag_q, force_all=True))
        self.name_regimes = USER.set_name_ds(name_regimes)
        self.constant_regi=constant_regi
        self.n = n
        cols2regi = REGI.check_cols2regi(constant_regi, cols2regi, x, yend=yend, add_cons=False)    
        self.cols2regi = cols2regi
        self.regimes_set = REGI._get_regimes_set(regimes)
        self.regimes = regimes
        USER.check_regimes(self.regimes_set)
        self.regime_err_sep = regime_err_sep        
        self.regime_lag_sep = regime_lag_sep        
        if regime_lag_sep == True:
            if not regime_err_sep:
                raise Exception, "regime_err_sep must be True when regime_lag_sep=True."
            cols2regi += [True]
            w_i,regi_ids,warn = REGI.w_regimes(w, regimes, self.regimes_set, transform=True, get_ids=True, min_n=len(cols2regi)+1)
            set_warn(self,warn)

        else:
            cols2regi += [False]            

        if regime_err_sep == True and set(cols2regi) == set([True]) and constant_regi == 'many':
            self.y = y
            self.GM_Lag_Regimes_Multi(y, x, w_i, regi_ids,\
                 yend=yend, q=q, w_lags=w_lags, lag_q=lag_q, cores=cores,\
                 robust=robust, gwk=gwk, sig2n_k=sig2n_k, cols2regi=cols2regi,\
                 spat_diag=spat_diag, vm=vm, name_y=name_y, name_x=name_x,\
                 name_yend=name_yend, name_q=name_q, name_regimes=self.name_regimes,\
                 name_w=name_w, name_gwk=name_gwk, name_ds=name_ds)
        else:
            if regime_lag_sep == True:
                w = REGI.w_regimes_union(w, w_i, self.regimes_set)
            yend2, q2 = set_endog(y, x, w, yend, q, w_lags, lag_q)
            name_yend.append(USER.set_name_yend_sp(name_y))
            TSLS_Regimes.__init__(self, y=y, x=x, yend=yend2, q=q2,\
                 regimes=regimes, w=w, robust=robust, gwk=gwk,\
                 sig2n_k=sig2n_k, spat_diag=spat_diag, vm=vm,\
                 constant_regi=constant_regi, cols2regi=cols2regi, regime_err_sep=regime_err_sep,\
                 name_y=name_y, name_x=name_x, name_yend=name_yend, name_q=name_q,\
                 name_regimes=name_regimes, name_w=name_w, name_gwk=name_gwk,\
                 name_ds=name_ds,summ=False)
            if regime_lag_sep:
                self.sp_att_reg(w_i, regi_ids, yend2[:,-1].reshape(self.n,1))
            else:
                self.predy_e, self.e_pred, warn = sp_att(w,self.y,self.predy,\
                          yend2[:,-1].reshape(self.n,1),self.betas[-1])
                set_warn(self,warn)
            self.regime_lag_sep=regime_lag_sep
            if regime_err_sep == True:
                self.title = "SPATIAL TWO STAGE LEAST SQUARES - REGIMES (Group-wise heteroskedasticity)"
            else:
                self.title = "SPATIAL TWO STAGE LEAST SQUARES - REGIMES"
            SUMMARY.GM_Lag(reg=self, w=w, vm=vm, spat_diag=spat_diag, regimes=True)
Ejemplo n.º 15
0
    def __init__(self, y, x, regimes, yend=None, q=None,\
                 w=None, w_lags=1, lag_q=True,\
                 robust=None, gwk=None, sig2n_k=False,\
                 spat_diag=False, constant_regi='many',\
                 cols2regi='all', regime_lag_sep=True, regime_err_sep=True,\
                 cores=None, vm=False, name_y=None, name_x=None,\
                 name_yend=None, name_q=None, name_regimes=None,\
                 name_w=None, name_gwk=None, name_ds=None):

        n = USER.check_arrays(y, x)
        USER.check_y(y, n)
        USER.check_weights(w, y)
        USER.check_robust(robust, gwk)
        USER.check_spat_diag(spat_diag, w)
        name_x = USER.set_name_x(name_x, x,constant=True)
        name_y = USER.set_name_y(name_y)
        name_yend = USER.set_name_yend(name_yend, yend)
        name_q = USER.set_name_q(name_q, q)
        name_q.extend(USER.set_name_q_sp(name_x, w_lags, name_q, lag_q, force_all=True))
        self.name_regimes = USER.set_name_ds(name_regimes)
        self.constant_regi=constant_regi
        self.n = n
        if cols2regi == 'all':
            if yend!=None:
                cols2regi = [True] * (x.shape[1]+yend.shape[1])
            else:
                cols2regi = [True] * (x.shape[1])     
        if regime_lag_sep == True:
            cols2regi += [True]
            self.regimes_set = list(set(regimes))
            self.regimes_set.sort()
            w_i,regi_ids,warn = REGI.w_regimes(w, regimes, self.regimes_set, transform=True, get_ids=True, min_n=len(cols2regi)+1)
            set_warn(self,warn)
            if not regime_err_sep:
                w = REGI.w_regimes_union(w, w_i, self.regimes_set)
        else:
            cols2regi += [False]
            if regime_err_sep == True:
                raise Exception, "All coefficients must vary accross regimes if regime_err_sep = True."            
        self.cols2regi = cols2regi
        if regime_lag_sep == True and regime_err_sep == True:
            if set(cols2regi) == set([True]):
                self.GM_Lag_Regimes_Multi(y, x, w_i, regi_ids,\
                 yend=yend, q=q, w_lags=w_lags, lag_q=lag_q, cores=cores,\
                 robust=robust, gwk=gwk, sig2n_k=sig2n_k, cols2regi=cols2regi,\
                 spat_diag=spat_diag, vm=vm, name_y=name_y, name_x=name_x,\
                 name_yend=name_yend, name_q=name_q, name_regimes=self.name_regimes,\
                 name_w=name_w, name_gwk=name_gwk, name_ds=name_ds)
            else:
                raise Exception, "All coefficients must vary accross regimes if regime_err_sep = True."
        else:
            yend2, q2 = set_endog(y, x, w, yend, q, w_lags, lag_q)
            name_yend.append(USER.set_name_yend_sp(name_y))
            TSLS_Regimes.__init__(self, y=y, x=x, yend=yend2, q=q2,\
                 regimes=regimes, w=w, robust=robust, gwk=gwk,\
                 sig2n_k=sig2n_k, spat_diag=spat_diag, vm=vm,\
                 constant_regi=constant_regi, cols2regi=cols2regi, name_y=name_y,\
                 name_x=name_x, name_yend=name_yend, name_q=name_q,\
                 name_regimes=name_regimes, name_w=name_w, name_gwk=name_gwk,\
                 name_ds=name_ds,summ=False)
            if regime_lag_sep:
                self.sp_att_reg(w_i, regi_ids, yend2[:,-1].reshape(self.n,1))
            else:
                self.predy_e, self.e_pred = sp_att(w,self.y,self.predy,\
                          yend2[:,-1].reshape(self.n,1),self.betas[-1])
            self.regime_lag_sep=regime_lag_sep
            self.title = "SPATIAL TWO STAGE LEAST SQUARES - REGIMES"
            SUMMARY.GM_Lag(reg=self, w=w, vm=vm, spat_diag=spat_diag, regimes=True)
Ejemplo n.º 16
0
    def __init__(self, y, x, yend, q, regimes,\
             w=None, robust=None, gwk=None, sig2n_k=True,\
             spat_diag=False, vm=False, constant_regi='many',\
             cols2regi='all', regime_err_sep=True, name_y=None, name_x=None,\
             cores=None, name_yend=None, name_q=None, name_regimes=None,\
             name_w=None, name_gwk=None, name_ds=None, summ=True):
       
        n = USER.check_arrays(y, x)
        USER.check_y(y, n)
        USER.check_weights(w, y)
        USER.check_robust(robust, gwk)
        USER.check_spat_diag(spat_diag, w)
        self.constant_regi = constant_regi
        self.cols2regi = cols2regi
        self.name_ds = USER.set_name_ds(name_ds)
        self.name_regimes = USER.set_name_ds(name_regimes)
        self.name_w = USER.set_name_w(name_w, w)
        self.name_gwk = USER.set_name_w(name_gwk, gwk)
        self.name_y = USER.set_name_y(name_y)
        name_yend = USER.set_name_yend(name_yend, yend)
        name_q = USER.set_name_q(name_q, q)
        self.name_x_r = USER.set_name_x(name_x, x) + name_yend            
        self.n = n
        cols2regi = REGI.check_cols2regi(constant_regi, cols2regi, x, yend=yend, add_cons=False)
        self.regimes_set = REGI._get_regimes_set(regimes)
        self.regimes = regimes
        USER.check_regimes(self.regimes_set)
        self.regime_err_sep = regime_err_sep

        if regime_err_sep == True and set(cols2regi) == set([True]) and constant_regi == 'many':
            name_x = USER.set_name_x(name_x, x)
            self.y = y
            if w:
                w_i,regi_ids,warn = REGI.w_regimes(w, regimes, self.regimes_set, transform=True, get_ids=True, min_n=len(self.cols2regi)+1)
                set_warn(self,warn)
            else:
                regi_ids = dict((r, list(np.where(np.array(regimes) == r)[0])) for r in self.regimes_set)
                w_i = None
            self._tsls_regimes_multi(x, yend, q, w_i, regi_ids, cores,\
                 gwk, sig2n_k, robust, spat_diag, vm, name_x, name_yend, name_q)
        else:
            name_x = USER.set_name_x(name_x, x,constant=True)
            q, self.name_q = REGI.Regimes_Frame.__init__(self, q, \
                    regimes, constant_regi=None, cols2regi='all', names=name_q)
            x, self.name_x = REGI.Regimes_Frame.__init__(self, x, \
                    regimes, constant_regi, cols2regi=cols2regi, names=name_x)
            yend, self.name_yend = REGI.Regimes_Frame.__init__(self, yend, \
                    regimes, constant_regi=None, \
                    cols2regi=cols2regi, yend=True, names=name_yend)
            BaseTSLS.__init__(self, y=y, x=x, yend=yend, q=q, \
                    robust=robust, gwk=gwk, sig2n_k=sig2n_k)
            if regime_err_sep == True and robust == None:
                """
                # Weighted x, y, yend and q approach:
                y2,x2,yend2,q2 = REGI._get_weighted_var(regimes,self.regimes_set,sig2n_k,self.u,y,x,yend,q)
                tsls2 = BaseTSLS(y=y2, x=x2, yend=yend2, q=q2, sig2n_k=sig2n_k)
                # Updating S_hat to S_tilde approach:               
                betas2, predy2, resid2, vm2 = self._optimal_weight(sig2n_k)
                RegressionProps_basic(self,betas=betas2,predy=predy2,u=resid2,vm=vm2,sig2=False)
                """
                betas2, vm2 = self._optimal_weight(sig2n_k)
                RegressionProps_basic(self,betas=betas2,vm=vm2,sig2=False)
                self.title = "TWO STAGE LEAST SQUARES - REGIMES (Optimal-Weighted GMM)"
                robust = None
                set_warn(self,"Residuals treated as homoskedastic for the purpose of diagnostics.")
            else:
                self.title = "TWO STAGE LEAST SQUARES - REGIMES"
            self.name_z = self.name_x + self.name_yend
            self.name_h = USER.set_name_h(self.name_x, self.name_q)
            self.chow = REGI.Chow(self)
            self.robust = USER.set_robust(robust)
            if summ:
                SUMMARY.TSLS(reg=self, vm=vm, w=w, spat_diag=spat_diag, regimes=True)
Ejemplo n.º 17
0
    def __init__(
        self,
        y,
        x,
        regimes,
        yend=None,
        q=None,
        w=None,
        w_lags=1,
        lag_q=True,
        robust=None,
        gwk=None,
        sig2n_k=False,
        spat_diag=False,
        constant_regi="many",
        cols2regi="all",
        regime_lag_sep=False,
        regime_err_sep=True,
        cores=False,
        vm=False,
        name_y=None,
        name_x=None,
        name_yend=None,
        name_q=None,
        name_regimes=None,
        name_w=None,
        name_gwk=None,
        name_ds=None,
    ):

        n = USER.check_arrays(y, x)
        USER.check_y(y, n)
        USER.check_weights(w, y, w_required=True)
        USER.check_robust(robust, gwk)
        USER.check_spat_diag(spat_diag, w)
        name_x = USER.set_name_x(name_x, x, constant=True)
        name_y = USER.set_name_y(name_y)
        name_yend = USER.set_name_yend(name_yend, yend)
        name_q = USER.set_name_q(name_q, q)
        name_q.extend(USER.set_name_q_sp(name_x, w_lags, name_q, lag_q, force_all=True))
        self.name_regimes = USER.set_name_ds(name_regimes)
        self.constant_regi = constant_regi
        self.n = n
        cols2regi = REGI.check_cols2regi(constant_regi, cols2regi, x, yend=yend, add_cons=False)
        self.cols2regi = cols2regi
        self.regimes_set = REGI._get_regimes_set(regimes)
        self.regimes = regimes
        USER.check_regimes(self.regimes_set, self.n, x.shape[1])
        if regime_err_sep == True and robust == "hac":
            set_warn(
                self,
                "Error by regimes is incompatible with HAC estimation for Spatial Lag models. Hence, error and lag by regimes have been disabled for this model.",
            )
            regime_err_sep = False
            regime_lag_sep = False
        self.regime_err_sep = regime_err_sep
        self.regime_lag_sep = regime_lag_sep
        if regime_lag_sep == True:
            if not regime_err_sep:
                raise Exception, "regime_err_sep must be True when regime_lag_sep=True."
            cols2regi += [True]
            w_i, regi_ids, warn = REGI.w_regimes(
                w, regimes, self.regimes_set, transform=True, get_ids=True, min_n=len(cols2regi) + 1
            )
            set_warn(self, warn)

        else:
            cols2regi += [False]

        if regime_err_sep == True and set(cols2regi) == set([True]) and constant_regi == "many":
            self.y = y
            self.GM_Lag_Regimes_Multi(
                y,
                x,
                w_i,
                w,
                regi_ids,
                yend=yend,
                q=q,
                w_lags=w_lags,
                lag_q=lag_q,
                cores=cores,
                robust=robust,
                gwk=gwk,
                sig2n_k=sig2n_k,
                cols2regi=cols2regi,
                spat_diag=spat_diag,
                vm=vm,
                name_y=name_y,
                name_x=name_x,
                name_yend=name_yend,
                name_q=name_q,
                name_regimes=self.name_regimes,
                name_w=name_w,
                name_gwk=name_gwk,
                name_ds=name_ds,
            )
        else:
            if regime_lag_sep == True:
                w = REGI.w_regimes_union(w, w_i, self.regimes_set)
            yend2, q2 = set_endog(y, x, w, yend, q, w_lags, lag_q)
            name_yend.append(USER.set_name_yend_sp(name_y))
            TSLS_Regimes.__init__(
                self,
                y=y,
                x=x,
                yend=yend2,
                q=q2,
                regimes=regimes,
                w=w,
                robust=robust,
                gwk=gwk,
                sig2n_k=sig2n_k,
                spat_diag=spat_diag,
                vm=vm,
                constant_regi=constant_regi,
                cols2regi=cols2regi,
                regime_err_sep=regime_err_sep,
                name_y=name_y,
                name_x=name_x,
                name_yend=name_yend,
                name_q=name_q,
                name_regimes=name_regimes,
                name_w=name_w,
                name_gwk=name_gwk,
                name_ds=name_ds,
                summ=False,
            )
            if regime_lag_sep:
                self.sp_att_reg(w_i, regi_ids, yend2[:, -1].reshape(self.n, 1))
            else:
                self.rho = self.betas[-1]
                self.predy_e, self.e_pred, warn = sp_att(
                    w, self.y, self.predy, yend2[:, -1].reshape(self.n, 1), self.rho
                )
                set_warn(self, warn)
            self.regime_lag_sep = regime_lag_sep
            self.title = "SPATIAL " + self.title
            SUMMARY.GM_Lag(reg=self, w=w, vm=vm, spat_diag=spat_diag, regimes=True)
Ejemplo n.º 18
0
    def __init__(self,
                 y,
                 x,
                 yend,
                 q,
                 regimes,
                 w=None,
                 robust=None,
                 gwk=None,
                 sig2n_k=True,
                 spat_diag=False,
                 vm=False,
                 constant_regi='many',
                 cols2regi='all',
                 regime_err_sep=True,
                 name_y=None,
                 name_x=None,
                 cores=False,
                 name_yend=None,
                 name_q=None,
                 name_regimes=None,
                 name_w=None,
                 name_gwk=None,
                 name_ds=None,
                 summ=True):

        n = USER.check_arrays(y, x)
        USER.check_y(y, n)
        USER.check_weights(w, y)
        USER.check_robust(robust, gwk)
        USER.check_spat_diag(spat_diag, w)
        self.constant_regi = constant_regi
        self.cols2regi = cols2regi
        self.name_ds = USER.set_name_ds(name_ds)
        self.name_regimes = USER.set_name_ds(name_regimes)
        self.name_w = USER.set_name_w(name_w, w)
        self.name_gwk = USER.set_name_w(name_gwk, gwk)
        self.name_y = USER.set_name_y(name_y)
        name_yend = USER.set_name_yend(name_yend, yend)
        name_q = USER.set_name_q(name_q, q)
        self.name_x_r = USER.set_name_x(name_x, x) + name_yend
        self.n = n
        cols2regi = REGI.check_cols2regi(constant_regi,
                                         cols2regi,
                                         x,
                                         yend=yend,
                                         add_cons=False)
        self.regimes_set = REGI._get_regimes_set(regimes)
        self.regimes = regimes
        USER.check_regimes(self.regimes_set, self.n, x.shape[1])
        if regime_err_sep == True and robust == 'hac':
            set_warn(
                self,
                "Error by regimes is incompatible with HAC estimation for 2SLS models. Hence, the error by regimes has been disabled for this model."
            )
            regime_err_sep = False
        self.regime_err_sep = regime_err_sep
        if regime_err_sep == True and set(cols2regi) == set(
            [True]) and constant_regi == 'many':
            name_x = USER.set_name_x(name_x, x)
            self.y = y
            regi_ids = dict((r, list(np.where(np.array(regimes) == r)[0]))
                            for r in self.regimes_set)
            self._tsls_regimes_multi(x, yend, q, w, regi_ids, cores, gwk,
                                     sig2n_k, robust, spat_diag, vm, name_x,
                                     name_yend, name_q)
        else:
            name_x = USER.set_name_x(name_x, x, constant=True)
            q, self.name_q = REGI.Regimes_Frame.__init__(self,
                                                         q,
                                                         regimes,
                                                         constant_regi=None,
                                                         cols2regi='all',
                                                         names=name_q)
            x, self.name_x = REGI.Regimes_Frame.__init__(self,
                                                         x,
                                                         regimes,
                                                         constant_regi,
                                                         cols2regi=cols2regi,
                                                         names=name_x)
            yend, self.name_yend = REGI.Regimes_Frame.__init__(
                self,
                yend,
                regimes,
                constant_regi=None,
                cols2regi=cols2regi,
                yend=True,
                names=name_yend)
            if regime_err_sep == True and robust == None:
                robust = 'white'
            BaseTSLS.__init__(self,
                              y=y,
                              x=x,
                              yend=yend,
                              q=q,
                              robust=robust,
                              gwk=gwk,
                              sig2n_k=sig2n_k)
            self.title = "TWO STAGE LEAST SQUARES - REGIMES"
            if robust == 'ogmm':
                _optimal_weight(self, sig2n_k)
            self.name_z = self.name_x + self.name_yend
            self.name_h = USER.set_name_h(self.name_x, self.name_q)
            self.chow = REGI.Chow(self)
            self.robust = USER.set_robust(robust)
            if summ:
                SUMMARY.TSLS(reg=self,
                             vm=vm,
                             w=w,
                             spat_diag=spat_diag,
                             regimes=True)