def data_clean(self, data):
     """ Clean NaNs out of necessary data """
     first = lu.rank_evol_vars(react=self.react)
     second = ['TopRanked', 'BottomRanked', 'InsideRanked', 'OverallRank',
               'Ranked', 'RankedL']
     vars_keep = [first, second]
     vars_keep = [item for sublist in vars_keep for item in sublist]
     return data[vars_keep].dropna()
    def problem(self):
        """ Problem definition for separated specification """
        x_vars = lu.rank_evol_vars(tilde=0, react=self.react)
        rbar = np.max(self.data.loc[self.data['Ranked'] > 0, 'OverallRank'])
        out = {}

        ## Data subsets
        data_r = self.data[self.data['RankedL'] > 0]
        data_rr = data_r[data_r['Ranked'] == 1]
        model_t = self._r_tobit(data_rr, x_vars, rbar)
        out['beta_t'] = model_t['beta']
        out['sigma_t'] = model_t['sigma']

        return out
 def ev_tobit(self, tilde):
     """ Generate expected value for interior rank """
     period = self.data['year'][0] - 2013
     if tilde:
         beta = self.firststage['params']['rank']['beta_tilde_t']
         sigma = self.firststage['params']['rank']['sigma_tilde_t']
         shock = self.shock['ev_tilde'][self.active, period]
     else:
         beta = self.firststage['params']['rank']['beta_t']
         sigma = self.firststage['params']['rank']['sigma_t']
         shock = self.shock['ev'][self.active, period]
     x_vars = lu.rank_evol_vars(tilde=tilde, react=self.opts['reaction'],
                                sim=True)
     xbeta = sm.add_constant(self.data[x_vars][self.active])
     xbeta = np.dot(xbeta, beta)
     lambda_tobit = ((norm.pdf((1 - xbeta + shock) / sigma) -
                      norm.pdf((lc.RBAR - xbeta + shock) / sigma)) /
                     (norm.cdf((lc.RBAR - xbeta + shock) / sigma) -
                      (norm.cdf((1 - xbeta + shock) / sigma))))
     out = xbeta + shock + sigma * lambda_tobit
     return out