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)
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)
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)
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)