def test_get_pop_objs(): """ Test of the that omega_SS and the last period of omega_path_S are close to each other. """ E = 20 S = 80 T = int(round(4.0 * S)) start_year = 2018 (omega, g_n_ss, omega_SS, surv_rate, rho, g_n_vector, imm_rates, omega_S_preTP) = demographics.get_pop_objs(E, S, T, 1, 100, start_year, False) assert (np.allclose(omega_SS, omega[-1, :]))
def test_imm_smooth(): """ Test that population growth rates evolve smoothly. """ E = 20 S = 80 T = int(round(4.0 * S)) start_year = 2018 (omega, g_n_ss, omega_SS, surv_rate, rho, g_n_vector, imm_rates, omega_S_preTP) = demographics.get_pop_objs(E, S, T, 1, 100, start_year, False) assert (np.any(np.absolute(imm_rates[:-1, :] - imm_rates[1:, :]) < 0.0001))
def __init__(self): ''' Instantiate the parameters class with the input name paramclass_name ''' ''' Period parameters ---------------------------------------------------------------- E = integer >= 1, number of periods an individual is economically inactive (youth) S = integer >= 3, number of periods an individual lives yrs_in_per = scalar > 0, number of years in model period T1 = integer > S, number of periods until demographics hit steady state T2 = integer > T1, number of periods until economy is in steady state ---------------------------------------------------------------- ''' self.E = int(20) self.S = int(80) self.yrs_in_per = 80 / self.S self.T1 = int(round(2.0 * self.S)) self.T2 = int(round(3.0 * self.S)) ''' Household parameters ---------------------------------------------------------------- beta_an = scalar in (0,1), discount factor for one year beta = scalar in (0,1), discount factor for each model period sigma = scalar > 0, coefficient of relative risk aversion l_tilde = scalar > 0, per-period time endowment for every agent chi_n_vec = (S,) vector, values for chi_{n,s} chi_b = scalar >= 0, scalar parameter on utility of dying with positive savings (warm glow bequest motive) b_ellip_init = scalar > 0, initial guess for b upsilon_init = scalar > 1, initial guess for upsilon ellip_init = (2,) vector, initial guesses for b and upsilon Frisch_elast = scalar > 0, Frisch elasticity of labor supply for CFE disutility of labor CFE_scale = scalar > 0, scale parameter for CFE disutility of labor cfe_params = (2,) vector, values for (Frisch, CFE_scale) b_ellip = scalar > 0, fitted value of b for elliptical disutility of labor upsilon = scalar > 1, fitted value of upsilon for elliptical disutility of labor b_s0_vec = (S,) vector, initial wealth for each aged individual in the first model period ---------------------------------------------------------------- ''' self.beta_an = 0.96 self.beta = self.beta_an**self.yrs_in_per self.sigma = 2.2 self.l_tilde = 1.0 self.chi_n_vec = 1.0 * np.ones(self.S) self.chi_b = 1.0 b_ellip_init = 1.0 upsilon_init = 2.0 ellip_init = np.array([b_ellip_init, upsilon_init]) self.Frisch_elast = 0.9 self.CFE_scale = 1.0 cfe_params = np.array([self.Frisch_elast, self.CFE_scale]) b_ellip, upsilon = elp.fit_ellip_CFE(ellip_init, cfe_params, self.l_tilde) self.b_ellip = b_ellip self.upsilon = upsilon self.b_s0_vec = 0.1 * np.ones(self.S) ''' Demographic parameters ---------------------------------------------------------------- min_yr = integer > 0, minimum year represented in the data max_yr = integer > min_yr, maximum number of years represented in the data curr_year = integer >= 2020, current year represented by t=0 omega_m1 = (S,) vector, stationarized economically active population distribution in period t=-1 right before current period omega_tp = (S, T2+1) matrix, transition path of the stationarized population distribution by age for economically active ages omega_ss = (S,) vector, steady-state stationarized population distribution by age for economically active ages g_n_path = (T2,) vector, time path of the population growth rate g_n_tp = (T2 + S,) vector, time path of the population growth rate g_n_ss = scalar, steady-state population growth rate surv_rates = (S,) vector, constant per-period survival rate of particular age cohort of cohort imm_rates_mat = (T2, S) matrix, time path of immigration rates by age rho_m1 = (S,) vector, mortality rates by age in the period t=-1 before the initial period rho_st = (S, T2+S) matrix, time path of mortality rates by age rho_ss = (S,) vector, constant per-period mortality rate of particular age cohort i_st = (S, T2+1) matrix, time path of immigration rates by age i_ss = (S,) vector, steady-state immigration rates by age for economically active ages ---------------------------------------------------------------- ''' self.min_yr = 1 self.max_yr = self.E + self.S self.curr_year = 2020 (omega_tp, g_n_ss, omega_ss, surv_rates, rho_ss, g_n_path, imm_rates_mat, omega_m1) = \ demog.get_pop_objs(self.E, self.S, self.T1, self.min_yr, self.max_yr, self.curr_year, GraphDiag=False) self.rho_ss = rho_ss self.i_ss = imm_rates_mat.T[:, self.T1] self.omega_ss = omega_ss self.omega_tp = \ np.append(omega_tp.T, omega_ss.reshape((self.S, 1)), axis=1) self.rho_m1 = rho_ss self.omega_m1 = omega_m1 self.g_n_ss = g_n_ss self.g_n_tp = \ np.append(g_n_path.reshape((1, self.T1 + self.S)), g_n_ss * np.ones((1, self.T2 - self.T1)), axis=1).flatten() self.rho_st = np.tile(self.rho_ss.reshape((self.S, 1)), (1, self.T2 + self.S)) self.i_st = np.append(imm_rates_mat.T, self.i_ss.reshape((self.S, 1)), axis=1) ''' Industry parameters ---------------------------------------------------------------- A = scalar > 0, total factor productivity alpha = scalar in (0,1), capital share of income delta_an = scalar in [0,1], annual capital depreciation rate delta = scalar in [0,1], model period capital depreciation rate g_y_an = scalar, annual net growth rate of labor productivity g_y = scalar, net growth rate of labor productivity in each model period ---------------------------------------------------------------- ''' self.A = 1.0 self.alpha = 0.35 self.delta_an = 0.05 self.delta = 1 - ((1 - self.delta_an)**self.yrs_in_per) g_y_an = 0.03 self.g_y = ((1 + g_y_an)**self.yrs_in_per) - 1 ''' Set steady-state solution method parameters ---------------------------------------------------------------- SS_solve = boolean, =True if want to solve for steady-state solution, otherwise retrieve solutions from pickle SS_OutTol = scalar > 0, tolerance for outer loop iterative solution convergence criterion SS_EulTol = scalar > 0, tolerance level for steady-state inner-loop Euler equation root finder SS_graphs = boolean, =True if want graphs of steady-state objects SS_EulDif = boolean, =True if use simple differences in Euler errors. Otherwise, use percent deviation form. ---------------------------------------------------------------- ''' self.SS_solve = True self.SS_OutTol = 1e-13 self.SS_EulTol = 1e-13 self.SS_graphs = True self.SS_EulDif = True ''' Set transition path solution method parameters ---------------------------------------------------------------- TP_solve = boolean, =True if want to solve TP equilibrium TP_OutTol = scalar > 0, tolerance level for outer-loop bisection method in TPI TP_EulTol = scalar > 0, tolerance level for inner-loop root finder in each iteration of TPI TP_graphs = boolean, =True if want graphs of TPI objects TP_EulDif = boolean, =True if want difference version of Euler errors beta*(1+r)*u'(c2) - u'(c1), =False if want ratio version [beta*(1+r)*u'(c2)]/[u'(c1)] - 1 xi_TP = scalar in (0,1], TPI path updating parameter maxiter_TP = integer >= 1, Maximum number of iterations for TPI ---------------------------------------------------------------- ''' self.TP_solve = True self.TP_OutTol = 1e-7 self.TP_EulTol = 1e-10 self.TP_graphs = True self.TP_EulDif = True self.xi_TP = 0.2 self.maxiter_TP = 1000
def get_parameters(test=False, baseline=False, guid='', user_modifiable=False, metadata=False): ''' -------------------------------------------------------------------- This function returns the model parameters. -------------------------------------------------------------------- INPUTS: test = boolean, =True if run test version with smaller state space baseline = boolean, =True if baseline tax policy, =False if reform guid = string, id for reform run user_modifiable = boolean, =True if allow user modifiable parameters metadata = boolean, =True if use metadata file for parameter values (rather than what is entered in parameters below) OTHER FUNCTIONS AND FILES CALLED BY THIS FUNCTION: read_tax_func_estimate() ellip.estimation() read_parameter_metadata() OBJECTS CREATED WITHIN FUNCTION: See parameters defined above allvars = dictionary, dictionary with all parameters defined in this function RETURNS: allvars, dictionary with model parameters -------------------------------------------------------------------- ''' ''' ------------------------------------------------------------------------ Parameters ------------------------------------------------------------------------ Model Parameters: ------------------------------------------------------------------------ S = integer, number of economically active periods an individual lives J = integer, number of different ability groups T = integer, number of time periods until steady state is reached BW = integer, number of time periods in the budget window lambdas = [J,] vector, percentiles for ability groups imm_rates = [J,T+S] array, immigration rates by age and year starting_age = integer, age agents enter population ending age = integer, maximum age agents can live until E = integer, age agents become economically active beta_annual = scalar, discount factor as an annual rate beta = scalar, discount factor for model period sigma = scalar, coefficient of relative risk aversion alpha = scalar, capital share of income Z = scalar, total factor productivity parameter in firms' production function delta_annual = scalar, depreciation rate as an annual rate delta = scalar, depreciation rate for model period ltilde = scalar, measure of time each individual is endowed with each period g_y_annual = scalar, annual growth rate of technology g_y = scalar, growth rate of technology for a model period frisch = scalar, Frisch elasticity that is used to fit ellipitcal utility to constant Frisch elasticity function b_ellipse = scalar, value of b for elliptical fit of utility function k_ellipse = scalar, value of k for elliptical fit of utility function upsilon = scalar, value of omega for elliptical fit of utility function ------------------------------------------------------------------------ Small Open Economy Parameters: ------------------------------------------------------------------------ ss_firm_r = scalar, world interest rate available to firms in the steady state ss_hh_r = scalar, world interest rate available to households in the steady state tpi_firm_r = [T+S,] vector, world interest rate (firm). Must be ss_firm_r in last period. tpi_hh_r = [T+S,] vector, world interest rate (household). Must be ss_firm_r in last period. ------------------------------------------------------------------------ Fiscal imbalance Parameters: ------------------------------------------------------------------------ alpha_T = scalar, share of GDP that goes to transfers. alpha_G = scalar, share of GDP that goes to gov't spending in early years. tG1 = scalar < t_G2, period at which change government spending rule from alpha_G*Y to glide toward SS debt ratio tG2 = scalar < T, period at which change gov't spending rule with final discrete jump to achieve SS debt ratio debt_ratio_ss = scalar, steady state debt/GDP. ------------------------------------------------------------------------ Tax Parameters: ------------------------------------------------------------------------ mean_income_data = scalar, mean income from IRS data file used to calibrate income tax etr_params = [S,BW,#tax params] array, parameters for effective tax rate function mtrx_params = [S,BW,#tax params] array, parameters for marginal tax rate on labor income function mtry_params = [S,BW,#tax params] array, parameters for marginal tax rate on capital income function h_wealth = scalar, wealth tax parameter h (scalar) m_wealth = scalar, wealth tax parameter m (scalar) p_wealth = scalar, wealth tax parameter p (scalar) tau_bq = [J,] vector, bequest tax tau_payroll = scalar, payroll tax rate retire = integer, age at which individuals eligible for retirement benefits ------------------------------------------------------------------------ Simulation Parameters: ------------------------------------------------------------------------ MINIMIZER_TOL = scalar, tolerance level for the minimizer in the calibration of chi parameters MINIMIZER_OPTIONS = dictionary, dictionary for options to put into the minimizer, usually to set a max iteration PLOT_TPI = boolean, =Ture if plot the path of K as TPI iterates (for debugging purposes) maxiter = integer, maximum number of iterations that SS and TPI solution methods will undergo mindist_SS = scalar, tolerance for SS solution mindist_TPI = scalar, tolerance for TPI solution nu = scalar, contraction parameter in SS and TPI iteration process representing the weight on the new distribution flag_graphs = boolean, =True if produce graphs in demographic, income, wealth, and labor files (True=graph) chi_b_guess = [J,] vector, initial guess of \chi^{b}_{j} parameters (if no calibration occurs, these are the values that will be used for \chi^{b}_{j}) chi_n_guess_80 = (80,) vector, initial guess of chi_{n,s} parameters for 80 one-year-period ages from 21 to 100 chi_n_guess = (S,) vector, interpolated initial guess of chi^{n,s} parameters (if no calibration occurs, these are the values that will be used age_midp_80 = (80,) vector, midpoints of age bins for 80 one-year- period ages from 21 to 100 for interpolation chi_n_interp = function, interpolation function for chi_n_guess newstep = scalar > 1, duration in years of each life period age_midp_S = (S,) vector, midpoints of age bins for S one-year- period ages from 21 to 100 for interpolation ------------------------------------------------------------------------ Demographics and Ability variables: ------------------------------------------------------------------------ omega = [T+S,S] array, time path of stationary distribution of economically active population by age g_n_ss = scalar, steady state population growth rate omega_SS = [S,] vector, stationary steady state population distribution surv_rate = [S,] vector, survival rates by age rho = [S,] vector, mortality rates by age g_n_vector = [T+S,] vector, growth rate in economically active pop for each period in transition path e = [S,J] array, normalized effective labor units by age and ability type ------------------------------------------------------------------------ ''' # Model Parameters if test: # size of state space S = int(40) lambdas = np.array([0.6, 0.4]) J = lambdas.shape[0] # Simulation Parameters MINIMIZER_TOL = 1e-6 MINIMIZER_OPTIONS = {'maxiter': 1} PLOT_TPI = False maxiter = 35 mindist_SS = 1e-6 mindist_TPI = 1e-3 nu = .4 flag_graphs = False else: S = int(80) lambdas = np.array([0.25, 0.25, 0.2, 0.1, 0.1, 0.09, 0.01]) J = lambdas.shape[0] # Simulation Parameters MINIMIZER_TOL = 1e-14 MINIMIZER_OPTIONS = None PLOT_TPI = False maxiter = 250 mindist_SS = 1e-9 mindist_TPI = 1e-5 #1e-9 nu = .4 flag_graphs = False # Time parameters T = int(4 * S) BW = int(10) start_year = 2016 starting_age = 20 ending_age = 100 E = int(starting_age * (S / float(ending_age - starting_age))) beta_annual = .96 # Carroll (JME, 2009) beta = beta_annual**(float(ending_age - starting_age) / S) sigma = 1.5 # value from Attanasio, Banks, Meghir and Weber (JEBS, 1999) alpha = .35 gamma = 0.35 # many use 0.33, but many find that capitals share is increasing (e.g. Elsby, Hobijn, and Sahin (BPEA, 2013)) epsilon = 1.0 #0.6 ##Note: If note =1, then careful w calibration Z = 1.0 delta_annual = 0.05 # approximately the value from Kehoe calibration exercise: http://www.econ.umn.edu/~tkehoe/classes/calibration-04.pdf delta = 1 - ((1 - delta_annual)**(float(ending_age - starting_age) / S)) ltilde = 1.0 g_y_annual = 0.03 g_y = (1 + g_y_annual)**(float(ending_age - starting_age) / S) - 1 # Ellipse parameters frisch = 0.4 # Frisch elasticity consistent with Altonji (JPE, 1996) and Peterman (Econ Inquiry, 2016) b_ellipse, upsilon = ellip.estimation(frisch, ltilde) k_ellipse = 0 # this parameter is just a level shifter in utlitiy - irrelevant for analysis # Small Open Economy parameters. Currently these are placeholders. Can introduce a # borrow/lend spread and a time path from t=0 to t=T-1. However, from periods T through # T+S, the steady state rate should hold. ss_firm_r_annual = 0.04 ss_hh_r_annual = 0.04 ss_firm_r = (1 + ss_firm_r_annual)**(float(ending_age - starting_age) / S) - 1 ss_hh_r = (1 + ss_hh_r_annual)**(float(ending_age - starting_age) / S) - 1 tpi_firm_r = np.ones(T + S) * ss_firm_r tpi_hh_r = np.ones(T + S) * ss_hh_r # Fiscal imbalance parameters. These allow government deficits, debt, and savings. tG1 = 20 #int(T/4) # change government spending rule from alpha_G*Y to glide toward SS debt ratio tG2 = int( T * 0.8 ) # change gov't spending rule with final discrete jump to achieve SS debt ratio alpha_T = 0.09 # share of GDP that goes to transfers each period. This ratio will hold in later baseline periods & SS. alpha_G = 0.05 # share of GDP of government spending for periods t<tG1 ALPHA_T = np.ones( T + S ) * alpha_T # Periods can be assigned different %-of-GDP rates for the baseline. Assignment after tG1 is not recommended. ALPHA_G = np.ones( T ) * alpha_G # Early periods (up to tG1) can be assigned different %-of-GDP rates for the baseline # Assign any deviations from constant share of GDP in pre-tG1 ALPHA_T and ALPHA_G in the user dashboard of run_ogusa_serial. rho_G = 0.1 # 0 < rho_G < 1 is transition speed for periods [tG1, tG2-1]. Lower rho_G => slower convergence. debt_ratio_ss = 0.4 # assumed steady-state debt/GDP ratio. Savings would be a negative number. initial_debt = 0.59 # first-period debt/GDP ratio. Savings would be a negative number. # Business tax parameters tau_b = 0.20 # business income tax rate delta_tau_annual = .027 # from B-Tax delta_tau = 1 - ( (1 - delta_annual)**(float(ending_age - starting_age) / S)) if tG1 > tG2: print 'The first government spending rule change date, (', tG1, ') is after the second one (', tG2, ').' err = "Gov't spending rule dates are inconsistent" raise RuntimeError(err) if tG2 > T: print 'The second government spending rule change date, (', tG2, ') is after time T (', T, ').' err = "Gov't spending rule dates are inconsistent" raise RuntimeError(err) # Tax parameters: # Income Tax Parameters # will call tax function estimation function here... # do output such that each parameters is in a separate SxBW array # read in estimated parameters #print 'baseline is:', baseline if baseline: baseline_pckl = "TxFuncEst_baseline{}.pkl".format(guid) estimate_file = os.path.join(TAX_ESTIMATE_PATH, baseline_pckl) print 'using baseline tax parameters' dict_params = read_tax_func_estimate(estimate_file, baseline_pckl) else: policy_pckl = "TxFuncEst_policy{}.pkl".format(guid) estimate_file = os.path.join(TAX_ESTIMATE_PATH, policy_pckl) print 'using policy tax parameters' dict_params = read_tax_func_estimate(estimate_file, policy_pckl) mean_income_data = dict_params['tfunc_avginc'][0] etr_params = dict_params['tfunc_etr_params_S'][:S, :BW, :] mtrx_params = dict_params['tfunc_mtrx_params_S'][:S, :BW, :] mtry_params = dict_params['tfunc_mtry_params_S'][:S, :BW, :] # # Make all ETRs equal the average etr_params = np.zeros(etr_params.shape) etr_params[:, :, 10] = dict_params['tfunc_avg_etr'] # set shift to average rate # # Make all MTRx equal the average mtrx_params = np.zeros(mtrx_params.shape) mtrx_params[:, :, 10] = dict_params[ 'tfunc_avg_mtrx'] # set shift to average rate # # Make all MTRy equal the average mtry_params = np.zeros(mtry_params.shape) mtry_params[:, :, 10] = dict_params[ 'tfunc_avg_mtry'] # set shift to average rate # # Make MTRx depend only on labor income # mtrx_params[:, :, 11] = 1.0 # set share parameter to 1 # # Make MTRy depend only on capital income # mtry_params[:, :, 11] = 0.0 # set share parameter to 0 # # set all MTRx parameters equal to the 43-yr-old values from 2016 # mtrx_params = np.tile(mtrx_params[11, 0, :], (S, 10, 1)) # Wealth tax params # These are non-calibrated values, h and m just need # need to be nonzero to avoid errors. When p_wealth # is zero, there is no wealth tax. h_wealth = 0.1 m_wealth = 1.0 p_wealth = 0.0 # Bequest and Payroll Taxes tau_bq = np.zeros(J) tau_payroll = 0.0 #0.15 # were are inluding payroll taxes in tax functions for now retire = np.int(np.round(9.0 * S / 16.0) - 1) # Calibration parameters # These guesses are close to the calibrated values chi_b_guess = np.ones((J, )) * 80.0 #chi_b_guess = np.array([0.7, 0.7, 1.0, 1.2, 1.2, 1.2, 1.4]) #chi_b_guess = np.array([1.0, 1.0, 1.0, 1.0, 1.0, 4.0, 10.0]) #chi_b_guess = np.array([5, 10, 90, 250, 250, 250, 250]) #chi_b_guess = np.array([2, 10, 90, 350, 1700, 22000, 120000]) chi_n_guess_80 = np.array([ 38.12000874, 33.22762421, 25.3484224, 26.67954008, 24.41097278, 23.15059004, 22.46771332, 21.85495452, 21.46242013, 22.00364263, 21.57322063, 21.53371545, 21.29828515, 21.10144524, 20.8617942, 20.57282, 20.47473172, 20.31111347, 19.04137299, 18.92616951, 20.58517969, 20.48761429, 20.21744847, 19.9577682, 19.66931057, 19.6878927, 19.63107201, 19.63390543, 19.5901486, 19.58143606, 19.58005578, 19.59073213, 19.60190899, 19.60001831, 21.67763741, 21.70451784, 21.85430468, 21.97291208, 21.97017228, 22.25518398, 22.43969757, 23.21870602, 24.18334822, 24.97772026, 26.37663164, 29.65075992, 30.46944758, 31.51634777, 33.13353793, 32.89186997, 38.07083882, 39.2992811, 40.07987878, 35.19951571, 35.97943562, 37.05601334, 37.42979341, 37.91576867, 38.62775142, 39.4885405, 37.10609921, 40.03988031, 40.86564363, 41.73645892, 42.6208256, 43.37786072, 45.38166073, 46.22395387, 50.21419653, 51.05246704, 53.86896121, 53.90029708, 61.83586775, 64.87563699, 66.91207845, 68.07449767, 71.27919965, 73.57195873, 74.95045988, 76.6230815 ]) # Generate Income and Demographic parameters (omega, g_n_ss, omega_SS, surv_rate, rho, g_n_vector, imm_rates, omega_S_preTP) = dem.get_pop_objs(E, S, T, 1, 100, start_year, flag_graphs) # Interpolate chi_n_guesses and create omega_SS_80 if necessary if S == 80: chi_n_guess = chi_n_guess_80.copy() omega_SS_80 = omega_SS.copy() elif S < 80: age_midp_80 = np.linspace(20.5, 99.5, 80) chi_n_interp = si.interp1d(age_midp_80, chi_n_guess_80, kind='cubic') newstep = 80.0 / S age_midp_S = np.linspace(20 + 0.5 * newstep, 100 - 0.5 * newstep, S) chi_n_guess = chi_n_interp(age_midp_S) (_, _, omega_SS_80, _, _, _, _, _) = dem.get_pop_objs(20, 80, 320, 1, 100, start_year, False) ## To shut off demographics, uncomment the following 9 lines of code # g_n_ss = 0.0 # surv_rate1 = np.ones((S,))# prob start at age S # surv_rate1[1:] = np.cumprod(surv_rate[:-1], dtype=float) # omega_SS = np.ones(S)*surv_rate1# number of each age alive at any time # omega_SS = omega_SS/omega_SS.sum() # imm_rates = np.zeros((T+S,S)) # omega = np.tile(np.reshape(omega_SS,(1,S)),(T+S,1)) # omega_S_preTP = omega_SS # g_n_vector = np.tile(g_n_ss,(T+S,)) e = inc.get_e_interp(S, omega_SS, omega_SS_80, lambdas, plot=False) # e_hetero = get_e(S, J, starting_age, ending_age, lambdas, omega_SS, flag_graphs) # e = np.tile(((e_hetero*lambdas).sum(axis=1)).reshape(S,1),(1,J)) # e = np.tile(e[:,0].reshape(S,1),(1,J)) # e /= (e * omega_SS.reshape(S, 1)* lambdas.reshape(1, J)).sum() # print 'g_y: ', g_y # print 'e: ', e # print 'chi_n_guess: ', chi_n_guess # print 'chi_b_guess: ', chi_b_guess # print 'delta, beta: ', delta, beta # quit() allvars = dict(locals()) if user_modifiable: allvars = {k: allvars[k] for k in USER_MODIFIABLE_PARAMS} if metadata: params_meta = read_parameter_metadata() for k, v in allvars.iteritems(): params_meta[k]["value"] = v allvars = params_meta return allvars
b_ellip, upsilon = elliptical_u_est.estimation(theta, l_tilde) # Firm A = 1.0 annual_delta = 0.05 delta = 1 - ((1 - annual_delta)**(40 / S)) alpha = 0.5 # Population min_age = 1 max_age = 100 start_year = 2013 pop_graphs = False # Get the immigration rates for every period imm_rates_SS = demog.get_imm_resid(E + S, min_age, max_age, pop_graphs) # Get population objects (omega_path_S, g_n_SS, omega_SS, surv_rates_S, mort_rates_S, g_n_path, imm_rates_mat, omega_S_preTP) = demog.get_pop_objs(E, S, T, min_age, max_age, start_year, pop_graphs) # imm_rates_SS = imm_rates_path[-1, :] # Solve the SS r_init = 1 / beta - 1 xi = 0.1 ss_params = (beta, sigma, alpha, A, delta, xi, omega_SS, imm_rates_SS, S) r_ss, b_sp1_ss, euler_errors_ss = SS.solve_ss(r_init, ss_params) # Economic growth g_y = 0.02
def get_parameters(baseline, reform, guid, user_modifiable): ''' -------------------------------------------------------------------- This function sets the parameters for the full model. -------------------------------------------------------------------- INPUTS: baseline = boolean, =True if baseline tax policy, =False if reform guid = string, id for reform run user_modifiable = boolean, =True if allow user modifiable parameters metadata = boolean, =True if use metadata file for parameter values (rather than what is entered in parameters below) OTHER FUNCTIONS AND FILES CALLED BY THIS FUNCTION: read_tax_func_estimate() elliptical_u_est.estimation() read_parameter_metadata() OBJECTS CREATED WITHIN FUNCTION: See parameters defined above allvars = dictionary, dictionary with all parameters defined in this function RETURNS: allvars OUTPUT: None -------------------------------------------------------------------- ''' # Model Parameters S = int(80) #S<30 won't meet necessary tolerances J = int(7) T = int(3 * S) BW = int(10) lambdas = np.array([.25, .25, .2, .1, .1, .09, .01]) start_year = 2016 starting_age = 20 ending_age = 100 E = int(starting_age * (S / float(ending_age - starting_age))) beta_annual = .96 # Carroll (JME, 2009) beta = beta_annual ** (float(ending_age - starting_age) / S) sigma = 2.0 alpha = .35 # many use 0.33, but many find that capitals share is # increasing (e.g. Elsby, Hobijn, and Sahin (BPEA, 2013)) Z = 1.0 delta_annual = .05 # approximately the value from Kehoe calibration # exercise: http://www.econ.umn.edu/~tkehoe/classes/calibration-04.pdf delta = 1 - ((1 - delta_annual) ** (float(ending_age - starting_age) / S)) ltilde = 1.0 g_y_annual = 0.03 g_y = (1 + g_y_annual)**(float(ending_age - starting_age) / S) - 1 # Ellipse parameters frisch = 1.5 # Frisch elasticity consistent with Peterman (Econ Inquiry, 2016) b_ellipse, upsilon = ellip.estimation(frisch,ltilde) k_ellipse = 0 # this parameter is just a level shifter in utlitiy - irrelevant for analysis # Tax parameters: mean_income_data = 84377.0 etr_params = np.zeros((S,BW,10)) mtrx_params = np.zeros((S,BW,10)) mtry_params = np.zeros((S,BW,10)) #baseline values - reform values determined in execute.py a_tax_income = 3.03452713268985e-06 b_tax_income = .222 c_tax_income = 133261.0 d_tax_income = 0.219 etr_params[:,:,0] = a_tax_income etr_params[:,:,1] = b_tax_income etr_params[:,:,2] = c_tax_income etr_params[:,:,3] = d_tax_income mtrx_params = etr_params mtry_params = etr_params # Wealth tax params # These are non-calibrated values, h and m just need # need to be nonzero to avoid errors. When p_wealth # is zero, there is no wealth tax. if reform == 2: # wealth tax reform values p_wealth = 0.025 h_wealth = 0.305509008443123 m_wealth = 2.16050687852062 else: #baseline values h_wealth = 0.1 m_wealth = 1.0 p_wealth = 0.0 # Bequest and Payroll Taxes tau_bq = np.zeros(J) tau_payroll = 0.15 retire = int(np.round(9.0 * S / 16.0) - 1) # Simulation Parameters MINIMIZER_TOL = 1e-14 MINIMIZER_OPTIONS = None PLOT_TPI = False maxiter = 250 mindist_SS = 1e-9 mindist_TPI = 2e-5 nu = 0.01 flag_graphs = False # Calibration parameters chi_b_guess = np.array([0.3, 0.3, 2., 14., 12.5, 98., 2150.]) * 13.0 # this hits about 5% interest and very close on wealth moments for # Frisch 1.5 and sigma 2.0 chi_n_raw = np.array([50.35115078, 35.47310428, 23.63926049, 22.90508485, 22.63035262, 20.35906224, 19.65935099, 19.03392052, 19.62478355, 19.13535233, 17.69560359, 16.64146739, 16.64146739, 16.64146739, 16.64146739, 16.64146739, 15.64146739, 14.64146739, 14.64146739, 14.98558476, 14.60688512, 14.50078038, 14.2256643, 14.95992287, 14.6673207, 13.6776809, 13.6120645, 13.60992325, 13.56024565, 13.54786468, 13.54453725, 13.55393179, 13.5669215, 13.56866264, 14.63426928, 15.66758321, 15.82479238, 15.94810588, 16.95270906, 18.24409932, 19.43579108, 19.22300316, 19.19041652, 20.98193805, 20.98193805, 20.98193805, 21.98193805, 22.0, 22.0, 22.0, 21.0, 21.0, 21.0, 21.0, 21.0, 21.0, 21.0, 20.0, 20.0, 19.0, 19.0, 19.0, 18.0, 18.0, 18.0, 18.0, 18.0, 18.0, 18.0, 17.0, 17.0, 17.0, 17.0, 17.0, 17.0, 17.0, 16.0, 16.0, 16.0, 16.0]) # smooth out the series of chi_n_guess_80 chi_n_guess_80 = utils.masmooth(chi_n_raw, 3, 3) # Generate Income and Demographic parameters (omega, g_n_ss, omega_SS, surv_rate, rho, g_n_vector, imm_rates, omega_S_preTP) = dem.get_pop_objs(E, S, T, 1, 100, start_year, flag_graphs) # Interpolate chi_n_guesses and create omega_SS_80 if necessary if S == 80: chi_n_guess = chi_n_guess_80 omega_SS_80 = omega_SS elif S < 80: age_midp_80 = np.linspace(20.5, 99.5, 80) chi_n_interp = si.interp1d(age_midp_80, chi_n_guess_80, kind='cubic') newstep = 80.0 / S age_midp_S = np.linspace(20 + 0.5 * newstep, 100 - 0.5 * newstep, S) chi_n_guess = chi_n_interp(age_midp_S) (_, _, omega_SS_80, _, _, _, _,_) = dem.get_pop_objs(20, 80, 320, 1, 100, start_year, False) # make pop constant # omega = np.tile(omega_SS.reshape(1,S),(T+S,1)) # g_n_vector[:] = g_n_ss # imm_rates = np.tile(imm_rates[-1,:].reshape(1,S),(T+S,1)) # omega_S_preTP = omega_SS e = inc.get_e_interp(S, omega_SS, omega_SS_80, lambdas, plot=False) allvars = dict(locals()) return allvars
def get_parameters(test=False, baseline=False, guid='', user_modifiable=False, metadata=False): ''' -------------------------------------------------------------------- This function returns the model parameters. -------------------------------------------------------------------- INPUTS: test = boolean, =True if run test version with smaller state space baseline = boolean, =True if baseline tax policy, =False if reform guid = string, id for reform run user_modifiable = boolean, =True if allow user modifiable parameters metadata = boolean, =True if use metadata file for parameter values (rather than what is entered in parameters below) OTHER FUNCTIONS AND FILES CALLED BY THIS FUNCTION: read_tax_func_estimate() ellip.estimation() read_parameter_metadata() OBJECTS CREATED WITHIN FUNCTION: See parameters defined above allvars = dictionary, dictionary with all parameters defined in this function RETURNS: allvars, dictionary with model parameters -------------------------------------------------------------------- ''' ''' ------------------------------------------------------------------------ Parameters ------------------------------------------------------------------------ Model Parameters: ------------------------------------------------------------------------ S = integer, number of economically active periods an individual lives J = integer, number of different ability groups T = integer, number of time periods until steady state is reached BW = integer, number of time periods in the budget window lambdas = [J,] vector, percentiles for ability groups imm_rates = [J,T+S] array, immigration rates by age and year starting_age = integer, age agents enter population ending age = integer, maximum age agents can live until E = integer, age agents become economically active beta_annual = scalar, discount factor as an annual rate beta = scalar, discount factor for model period sigma = scalar, coefficient of relative risk aversion alpha = scalar, capital share of income Z = scalar, total factor productivity parameter in firms' production function delta_annual = scalar, depreciation rate as an annual rate delta = scalar, depreciation rate for model period ltilde = scalar, measure of time each individual is endowed with each period g_y_annual = scalar, annual growth rate of technology g_y = scalar, growth rate of technology for a model period frisch = scalar, Frisch elasticity that is used to fit ellipitcal utility to constant Frisch elasticity function b_ellipse = scalar, value of b for elliptical fit of utility function k_ellipse = scalar, value of k for elliptical fit of utility function upsilon = scalar, value of omega for elliptical fit of utility function ------------------------------------------------------------------------ Small Open Economy Parameters: ------------------------------------------------------------------------ ss_firm_r = scalar, world interest rate available to firms in the steady state ss_hh_r = scalar, world interest rate available to households in the steady state tpi_firm_r = [T+S,] vector, world interest rate (firm). Must be ss_firm_r in last period. tpi_hh_r = [T+S,] vector, world interest rate (household). Must be ss_firm_r in last period. ------------------------------------------------------------------------ Fiscal imbalance Parameters: ------------------------------------------------------------------------ alpha_T = scalar, share of GDP that goes to transfers. alpha_G = scalar, share of GDP that goes to gov't spending in early years. tG1 = scalar < t_G2, period at which change government spending rule from alpha_G*Y to glide toward SS debt ratio tG2 = scalar < T, period at which change gov't spending rule with final discrete jump to achieve SS debt ratio debt_ratio_ss = scalar, steady state debt/GDP. ------------------------------------------------------------------------ Tax Parameters: ------------------------------------------------------------------------ mean_income_data = scalar, mean income from IRS data file used to calibrate income tax etr_params = [S,BW,#tax params] array, parameters for effective tax rate function mtrx_params = [S,BW,#tax params] array, parameters for marginal tax rate on labor income function mtry_params = [S,BW,#tax params] array, parameters for marginal tax rate on capital income function h_wealth = scalar, wealth tax parameter h (scalar) m_wealth = scalar, wealth tax parameter m (scalar) p_wealth = scalar, wealth tax parameter p (scalar) tau_bq = [J,] vector, bequest tax tau_payroll = scalar, payroll tax rate retire = integer, age at which individuals eligible for retirement benefits ------------------------------------------------------------------------ Simulation Parameters: ------------------------------------------------------------------------ MINIMIZER_TOL = scalar, tolerance level for the minimizer in the calibration of chi parameters MINIMIZER_OPTIONS = dictionary, dictionary for options to put into the minimizer, usually to set a max iteration PLOT_TPI = boolean, =Ture if plot the path of K as TPI iterates (for debugging purposes) maxiter = integer, maximum number of iterations that SS and TPI solution methods will undergo mindist_SS = scalar, tolerance for SS solution mindist_TPI = scalar, tolerance for TPI solution nu = scalar, contraction parameter in SS and TPI iteration process representing the weight on the new distribution flag_graphs = boolean, =True if produce graphs in demographic, income, wealth, and labor files (True=graph) chi_b_guess = [J,] vector, initial guess of \chi^{b}_{j} parameters (if no calibration occurs, these are the values that will be used for \chi^{b}_{j}) chi_n_guess_80 = (80,) vector, initial guess of chi_{n,s} parameters for 80 one-year-period ages from 21 to 100 chi_n_guess = (S,) vector, interpolated initial guess of chi^{n,s} parameters (if no calibration occurs, these are the values that will be used age_midp_80 = (80,) vector, midpoints of age bins for 80 one-year- period ages from 21 to 100 for interpolation chi_n_interp = function, interpolation function for chi_n_guess newstep = scalar > 1, duration in years of each life period age_midp_S = (S,) vector, midpoints of age bins for S one-year- period ages from 21 to 100 for interpolation ------------------------------------------------------------------------ Demographics and Ability variables: ------------------------------------------------------------------------ omega = [T+S,S] array, time path of stationary distribution of economically active population by age g_n_ss = scalar, steady state population growth rate omega_SS = [S,] vector, stationary steady state population distribution surv_rate = [S,] vector, survival rates by age rho = [S,] vector, mortality rates by age g_n_vector = [T+S,] vector, growth rate in economically active pop for each period in transition path e = [S,J] array, normalized effective labor units by age and ability type ------------------------------------------------------------------------ ''' # Model Parameters if test: # size of state space S = int(40) lambdas = np.array([0.6,0.4]) J = lambdas.shape[0] # Simulation Parameters MINIMIZER_TOL = 1e-6 MINIMIZER_OPTIONS = {'maxiter': 1} PLOT_TPI = False maxiter = 35 mindist_SS = 1e-6 mindist_TPI = 1e-3 nu = .4 flag_graphs = False else: S = int(80) lambdas = np.array([0.25, 0.25, 0.2, 0.1, 0.1, 0.09, 0.01]) J = lambdas.shape[0] # Simulation Parameters MINIMIZER_TOL = 1e-14 MINIMIZER_OPTIONS = None PLOT_TPI = False maxiter = 250 mindist_SS = 1e-9 mindist_TPI = 1e-5#1e-9 nu = .4 flag_graphs = False # Time parameters T = int(4 * S) BW = int(10) start_year = 2016 starting_age = 20 ending_age = 100 E = int(starting_age * (S / float(ending_age - starting_age))) beta_annual = .96 # Carroll (JME, 2009) beta = beta_annual ** (float(ending_age - starting_age) / S) sigma = 1.5 # value from Attanasio, Banks, Meghir and Weber (JEBS, 1999) alpha = .35 gamma = 0.35 # many use 0.33, but many find that capitals share is increasing (e.g. Elsby, Hobijn, and Sahin (BPEA, 2013)) epsilon = 1.0#0.6 ##Note: If note =1, then careful w calibration Z = 1.0 delta_annual = 0.05 # approximately the value from Kehoe calibration exercise: http://www.econ.umn.edu/~tkehoe/classes/calibration-04.pdf delta = 1 - ((1 - delta_annual) ** (float(ending_age - starting_age) / S)) ltilde = 1.0 g_y_annual = 0.03 g_y = (1 + g_y_annual)**(float(ending_age - starting_age) / S) - 1 # Ellipse parameters frisch = 0.4 # Frisch elasticity consistent with Altonji (JPE, 1996) and Peterman (Econ Inquiry, 2016) b_ellipse, upsilon = ellip.estimation(frisch,ltilde) k_ellipse = 0 # this parameter is just a level shifter in utlitiy - irrelevant for analysis # Small Open Economy parameters. Currently these are placeholders. Can introduce a # borrow/lend spread and a time path from t=0 to t=T-1. However, from periods T through # T+S, the steady state rate should hold. ss_firm_r_annual = 0.04 ss_hh_r_annual = 0.04 ss_firm_r = (1 + ss_firm_r_annual) ** (float(ending_age - starting_age) / S) - 1 ss_hh_r = (1 + ss_hh_r_annual) ** (float(ending_age - starting_age) / S) - 1 tpi_firm_r = np.ones(T+S)*ss_firm_r tpi_hh_r = np.ones(T+S)*ss_hh_r # Fiscal imbalance parameters. These allow government deficits, debt, and savings. tG1 = 20#int(T/4) # change government spending rule from alpha_G*Y to glide toward SS debt ratio tG2 = int(T*0.8) # change gov't spending rule with final discrete jump to achieve SS debt ratio alpha_T = 0.09 # share of GDP that goes to transfers each period. This ratio will hold in later baseline periods & SS. alpha_G = 0.05 # share of GDP of government spending for periods t<tG1 ALPHA_T = np.ones(T+S)*alpha_T # Periods can be assigned different %-of-GDP rates for the baseline. Assignment after tG1 is not recommended. ALPHA_G = np.ones(T)*alpha_G # Early periods (up to tG1) can be assigned different %-of-GDP rates for the baseline # Assign any deviations from constant share of GDP in pre-tG1 ALPHA_T and ALPHA_G in the user dashboard of run_ogusa_serial. rho_G = 0.1 # 0 < rho_G < 1 is transition speed for periods [tG1, tG2-1]. Lower rho_G => slower convergence. debt_ratio_ss = 0.4 # assumed steady-state debt/GDP ratio. Savings would be a negative number. initial_debt = 0.59 # first-period debt/GDP ratio. Savings would be a negative number. # Business tax parameters tau_b = 0.20 # business income tax rate delta_tau_annual = .027# from B-Tax delta_tau = 1 - ((1 - delta_annual) ** (float(ending_age - starting_age) / S)) if tG1 > tG2: print 'The first government spending rule change date, (', tG1, ') is after the second one (', tG2, ').' err = "Gov't spending rule dates are inconsistent" raise RuntimeError(err) if tG2 > T: print 'The second government spending rule change date, (', tG2, ') is after time T (', T, ').' err = "Gov't spending rule dates are inconsistent" raise RuntimeError(err) # Tax parameters: # Income Tax Parameters # will call tax function estimation function here... # do output such that each parameters is in a separate SxBW array # read in estimated parameters #print 'baseline is:', baseline if baseline: baseline_pckl = "TxFuncEst_baseline{}.pkl".format(guid) estimate_file = os.path.join(TAX_ESTIMATE_PATH, baseline_pckl) print 'using baseline tax parameters' dict_params = read_tax_func_estimate(estimate_file, baseline_pckl) else: policy_pckl = "TxFuncEst_policy{}.pkl".format(guid) estimate_file = os.path.join(TAX_ESTIMATE_PATH, policy_pckl) print 'using policy tax parameters' dict_params = read_tax_func_estimate(estimate_file, policy_pckl) mean_income_data = dict_params['tfunc_avginc'][0] etr_params = dict_params['tfunc_etr_params_S'][:S,:BW,:] mtrx_params = dict_params['tfunc_mtrx_params_S'][:S,:BW,:] mtry_params = dict_params['tfunc_mtry_params_S'][:S,:BW,:] # # Make all ETRs equal the average etr_params = np.zeros(etr_params.shape) etr_params[:, :, 10] = dict_params['tfunc_avg_etr'] # set shift to average rate # # Make all MTRx equal the average mtrx_params = np.zeros(mtrx_params.shape) mtrx_params[:, :, 10] = dict_params['tfunc_avg_mtrx'] # set shift to average rate # # Make all MTRy equal the average mtry_params = np.zeros(mtry_params.shape) mtry_params[:, :, 10] = dict_params['tfunc_avg_mtry'] # set shift to average rate # # Make MTRx depend only on labor income # mtrx_params[:, :, 11] = 1.0 # set share parameter to 1 # # Make MTRy depend only on capital income # mtry_params[:, :, 11] = 0.0 # set share parameter to 0 # # set all MTRx parameters equal to the 43-yr-old values from 2016 # mtrx_params = np.tile(mtrx_params[11, 0, :], (S, 10, 1)) # Wealth tax params # These are non-calibrated values, h and m just need # need to be nonzero to avoid errors. When p_wealth # is zero, there is no wealth tax. h_wealth = 0.1 m_wealth = 1.0 p_wealth = 0.0 # Bequest and Payroll Taxes tau_bq = np.zeros(J) tau_payroll = 0.0 #0.15 # were are inluding payroll taxes in tax functions for now retire = np.int(np.round(9.0 * S / 16.0) - 1) # Calibration parameters # These guesses are close to the calibrated values chi_b_guess = np.ones((J,)) * 80.0 #chi_b_guess = np.array([0.7, 0.7, 1.0, 1.2, 1.2, 1.2, 1.4]) #chi_b_guess = np.array([1.0, 1.0, 1.0, 1.0, 1.0, 4.0, 10.0]) #chi_b_guess = np.array([5, 10, 90, 250, 250, 250, 250]) #chi_b_guess = np.array([2, 10, 90, 350, 1700, 22000, 120000]) chi_n_guess_80 = np.array( [38.12000874, 33.22762421, 25.3484224, 26.67954008, 24.41097278, 23.15059004, 22.46771332, 21.85495452, 21.46242013, 22.00364263, 21.57322063, 21.53371545, 21.29828515, 21.10144524, 20.8617942, 20.57282, 20.47473172, 20.31111347, 19.04137299, 18.92616951, 20.58517969, 20.48761429, 20.21744847, 19.9577682, 19.66931057, 19.6878927, 19.63107201, 19.63390543, 19.5901486, 19.58143606, 19.58005578, 19.59073213, 19.60190899, 19.60001831, 21.67763741, 21.70451784, 21.85430468, 21.97291208, 21.97017228, 22.25518398, 22.43969757, 23.21870602, 24.18334822, 24.97772026, 26.37663164, 29.65075992, 30.46944758, 31.51634777, 33.13353793, 32.89186997, 38.07083882, 39.2992811, 40.07987878, 35.19951571, 35.97943562, 37.05601334, 37.42979341, 37.91576867, 38.62775142, 39.4885405, 37.10609921, 40.03988031, 40.86564363, 41.73645892, 42.6208256, 43.37786072, 45.38166073, 46.22395387, 50.21419653, 51.05246704, 53.86896121, 53.90029708, 61.83586775, 64.87563699, 66.91207845, 68.07449767, 71.27919965, 73.57195873, 74.95045988, 76.6230815]) # Generate Income and Demographic parameters (omega, g_n_ss, omega_SS, surv_rate, rho, g_n_vector, imm_rates, omega_S_preTP) = dem.get_pop_objs(E, S, T, 1, 100, start_year, flag_graphs) # Interpolate chi_n_guesses and create omega_SS_80 if necessary if S == 80: chi_n_guess = chi_n_guess_80.copy() omega_SS_80 = omega_SS.copy() elif S < 80: age_midp_80 = np.linspace(20.5, 99.5, 80) chi_n_interp = si.interp1d(age_midp_80, chi_n_guess_80, kind='cubic') newstep = 80.0 / S age_midp_S = np.linspace(20 + 0.5 * newstep, 100 - 0.5 * newstep, S) chi_n_guess = chi_n_interp(age_midp_S) (_, _, omega_SS_80, _, _, _, _,_) = dem.get_pop_objs(20, 80, 320, 1, 100, start_year, False) ## To shut off demographics, uncomment the following 9 lines of code # g_n_ss = 0.0 # surv_rate1 = np.ones((S,))# prob start at age S # surv_rate1[1:] = np.cumprod(surv_rate[:-1], dtype=float) # omega_SS = np.ones(S)*surv_rate1# number of each age alive at any time # omega_SS = omega_SS/omega_SS.sum() # imm_rates = np.zeros((T+S,S)) # omega = np.tile(np.reshape(omega_SS,(1,S)),(T+S,1)) # omega_S_preTP = omega_SS # g_n_vector = np.tile(g_n_ss,(T+S,)) e = inc.get_e_interp(S, omega_SS, omega_SS_80, lambdas, plot=False) # e_hetero = get_e(S, J, starting_age, ending_age, lambdas, omega_SS, flag_graphs) # e = np.tile(((e_hetero*lambdas).sum(axis=1)).reshape(S,1),(1,J)) # e = np.tile(e[:,0].reshape(S,1),(1,J)) # e /= (e * omega_SS.reshape(S, 1)* lambdas.reshape(1, J)).sum() # print 'g_y: ', g_y # print 'e: ', e # print 'chi_n_guess: ', chi_n_guess # print 'chi_b_guess: ', chi_b_guess # print 'delta, beta: ', delta, beta # quit() allvars = dict(locals()) if user_modifiable: allvars = {k:allvars[k] for k in USER_MODIFIABLE_PARAMS} if metadata: params_meta = read_parameter_metadata() for k,v in allvars.iteritems(): params_meta[k]["value"] = v allvars = params_meta return allvars