def get_new_g(ws, params): np.random.seed(42) pths, shks = sample_path(ws, params, nseries=1000, nperiods=30) pth, shocks = pths[28], shks[28] # a period in steady state g = ecdf(np.sort(pth)) shocks = np.sort(shocks) return g, shocks
def get_df(pi, lambda_, ws, params): """ Give a pi, lambda pair, get the dataframe of wage choices sample from the steady state. """ pths, shocks = sample_path(ws, params, lambda_=lambda_, w0=.9, nseries=1000, nperiods=100) df = pd.DataFrame(pths) return df
def run_one(params, res_dict=None): """ Once you have the parameters, this function completes one loop to get a dictionary of results. For the first loop leave res_dict as None. """ pi = params['pi'][0] # lambda_ = params['lambda_'][0] np.random.seed(42) w_grid = params['w_grid'][0] z_grid = params['z_grid'][0] if res_dict: print("Reusing res_dict.") v = res_dict['Tv'] out = res_dict['rigid_out'] else: v = Interp(w_grid, -w_grid + 27.3, kind='linear') out = ss_output_flexible(params) # ss output w/ flexible wages # Get close with linear first. Then do a few cubic to finish up Tv, ws, rest = iter_bellman(v, tol=0.005, strict=False, log=False, params=params, pi=pi, aggL=out, kind='linear') Tvc = Interp(Tv.X, Tv.Y, kind='cubic') Tv, ws, rest = iter_bellman(Tvc, tol=0.005, strict=False, log=False, params=params, pi=pi, aggL=out) res_dict = {'Tv': Tv, 'ws': ws, 'rest': rest} flex_ws = Interp(z_grid, ss_wage_flexible(params, shock=z_grid)) #------------------------------------------------------------------------- pths, shks = sample_path(ws, params, nseries=1000, nperiods=30) pth, shocks = pths[28], shks[28] # a period in steady state g = ecdf(np.sort(pth)) shocks = np.sort(shocks) #------------------------------------------------------------------------- rigid_out = get_rigid_output(ws, params, flex_ws, g) res_dict['gp'] = g res_dict['rigid_out'] = rigid_out return res_dict
def make_panel(wses, params, pairs=None, log=False, nseries=100, nperiods=50, seed=42): """ Panel of wage choices where items : (pi, lambda) major : periods minor : series seed is an int given to np.random.set_seed(). """ if pairs is None: pairs = wses.iterkeys() dfs = {} sks = {} for key in pairs: ws = wses[key] pths, shocks = sample_path(ws, params, w0=.9, lambda_=key[1], nseries=nseries, nperiods=nperiods, seed=seed) df = pd.DataFrame(pths) shocks = pd.DataFrame(shocks) if log: dfs[key] = np.log(df) else: dfs[key] = df sks[key] = shocks df_pan = pd.Panel(dfs) sk_pan = pd.Panel(sks) df_pan.minor_axis.name = 'person' sk_pan.minor_axis.name = 'person' df_pan.items.name = 'key' sk_pan.items.name = 'key' df_pan.major_axis.name = 'period' sk_pan.major_axis.name = 'period' return df_pan, sk_pan
def get_g(pi, lambda_, period=28): """ Helper function to get to a wage distribution. Warning: Will not touch the params in your global state. If you go on the to more things make sure to adjust those params. """ import analyze_run as ar params = load_params() params['pi'] = pi, 'a' params['lambda_'] = lambda_, 'b' all_files = ar.get_all_files(params) wses = ar.read_output(all_files, kind='ws') ws = wses[(pi, lambda_)] pths, shks = sample_path(ws, params, nseries=1000, nperiods=30, seed=42) pth, shocks = pths[28], shks[28] shocks = np.sort(shocks) g = ecdf(np.sort(pth)) return g, shocks