def __init__(self, url, user, token): self.port = 8000 ## change if url.find(':') == -1: # Port not included self.url = url + ':{}'.format(self.port) else: self.url = url self.user = user self.token = token self.headers = {'Authorization': '{}'.format(self.token), 'Content-type': 'application/json', 'Accept': 'text/plain'} shockres = requests.get('http://{}/shock'.format(self.url), headers=self.headers).text self.shockurl = 'http://{}/'.format(json.loads(shockres)['shockurl']) self.shock = Shock(self.shockurl, self.user, self.token)
def initialize(self, environment): self.environment = environment self.updater = Updater(self.environment) self.shocker = Shock()
def elast_gen(bs, shocks): eta = bs[0] alphap = bs[1] alphaf = bs[2] #wage process wagep_betas = np.array([bs[3], bs[4], bs[5], bs[6], bs[7]]).reshape((5, 1)) income_male_betas = np.array([bs[8], bs[9], bs[10]]).reshape((3, 1)) c_emp_spouse = bs[11] #Production function [young[cc0,cc1],old] gamma1 = bs[12] gamma2 = bs[13] gamma3 = bs[14] tfp = bs[15] sigma2theta = 1 kappas = [bs[16], bs[17]] sigma_z = [1, bs[18]] rho_theta_epsilon = bs[19] lambdas = [1, 1] #Re-defines the instance with parameters param = util.Parameters(alphap, alphaf, mu_c, eta, gamma1, gamma2, gamma3, tfp, sigma2theta, rho_theta_epsilon, wagep_betas, income_male_betas, c_emp_spouse, marriagep_betas, kidsp_betas, eitc_list, afdc_list, snap_list, cpi, fpl_list, lambdas, kappas, pafdc, psnap, mup, sigma_z) #The estimate class output_ins = estimate.Estimate(nperiods, param, x_w, x_m, x_k, x_wmk, passign, agech0, nkids0, married0, D, dict_grid, M, N, moments_vector, var_cov, hours_p, hours_f, wr, cs, ws) hours = np.zeros(N) childcare = np.zeros(N) model_orig = util.Utility(param, N, x_w, x_m, x_k, passign, nkids0, married0, hours, childcare, agech0, hours_p, hours_f, wr, cs, ws) #Obtaining emax instance: this is fixed throughout the exercise emax_instance = output_ins.emax(param, model_orig) choices_c = {} models = [] for j in range(2): np.save( '/home/jrodriguez/NH_HC/results/model_v2/experiments/NH/shock.npy', shocks[j]) models.append( Shock(param, N, x_w, x_m, x_k, passign, nkids0, married0, hours, childcare, agech0, hours_p, hours_f, wr, cs, ws)) choices_c['Choice_' + str(j)] = output_ins.samples( param, emax_instance, models[j]) #Computing changes in % employment for control group h_sim_matrix = [] employment = [] wages = [] full = [] for j in range(2): h_sim_matrix.append(choices_c['Choice_' + str(j)]['hours_matrix']) employment.append(choices_c['Choice_' + str(j)]['hours_matrix'] > 0) full.append(choices_c['Choice_' + str(j)]['hours_matrix'] == hours_f) wages.append(choices_c['Choice_' + str(j)]['wage_matrix']) #Extensive margin elast_extensive = np.zeros(M) for j in range(M): elast_periods = np.zeros(nperiods) for t in range(nperiods): elast_periods[t] = (np.mean(employment[1][:, t, j], axis=0) - np.mean(employment[0][:, t, j], axis=0)) / ( shocks[1] * np.mean( (employment[0][:, t, j]), axis=0)) elast_extensive[j] = np.mean(elast_periods) #Intensive margin elast_intensive = np.zeros(M) for j in range(M): elast_periods = np.zeros(nperiods) for t in range(nperiods): sample = (employment[0][:, t, j] == 1) elast_periods[t] = np.mean( (h_sim_matrix[1][sample, t, j] - h_sim_matrix[0][sample, t, j]), axis=0) / (shocks[1] * np.mean(h_sim_matrix[0][sample, t, j], axis=0)) elast_intensive[j] = np.mean(elast_periods) return {'Extensive': elast_extensive, 'Intensive': elast_intensive}
def init_shock(self): if self.shock is None: shockres = self.req_get('{}/shock'.format(self.url)) self.shockurl = utils.verify_url(json.loads(shockres)['shockurl']) self.shock = Shock(self.shockurl, self.user, self.token)