Example #1
0
def SS_TPI_firstdoughnutring(guesses, winit, rinit, BQinit, T_H_init, initial_b, factor_ss, j, tax_params, parameters, theta, tau_bq):
    '''
    Solves the first entries of the upper triangle of the twist doughnut.  This is
    separate from the main TPI function because the the values of b and n are scalars,
    so it is easier to just have a separate function for these cases.
    Inputs:
        guesses = guess for b and n (2x1 list)
        winit = initial wage rate (scalar)
        rinit = initial rental rate (scalar)
        BQinit = initial aggregate bequest (scalar)
        T_H_init = initial lump sum tax (scalar)
        initial_b = initial distribution of capital (SxJ array)
        factor_ss = steady state scaling factor (scalar)
        j = which ability type is being solved for (scalar)
        parameters = list of parameters (list)
        theta = replacement rates (Jx1 array)
        tau_bq = bequest tax rates (Jx1 array)
    Output:
        euler errors (2x1 list)
    '''

    J, S, T, BW, beta, sigma, alpha, Z, delta, ltilde, nu, g_y,\
                  g_n_ss, tau_payroll, retire, mean_income_data,\
                  h_wealth, p_wealth, m_wealth, b_ellipse, upsilon = parameters


    analytical_mtrs, etr_params, mtrx_params, mtry_params = tax_params

    b2 = float(guesses[0])
    n1 = float(guesses[1])
    b1 = float(initial_b[-2, j])
    # Euler 1 equations
    tax1_params = (J, S, retire, etr_params[-1,0,:], h_wealth, p_wealth, m_wealth, tau_payroll)
    tax1 = tax.total_taxes(rinit, b1, winit, e[-1, j], n1, BQinit, lambdas[
                           j], factor_ss, T_H_init, j, 'TPI_scalar', False, tax1_params, theta, tau_bq)
    cons1 = household.get_cons(
        rinit, b1, winit, e[-1, j], n1, BQinit, lambdas[j], b2, parameters, tax1)
    bequest_ut = rho[-1] * np.exp(-sigma * g_y) * chi_b[-1, j] * b2 ** (-sigma)
    error1 = household.marg_ut_cons(cons1, parameters) - bequest_ut
    # Euler 2 equations
    income2 = (rinit * b1 + winit * e[-1, j] * n1) * factor_ss
    deriv2 = 1 - tau_payroll - tax.MTR_labor(rinit, b1, winit, e[-1, j], n1, factor_ss, analytical_mtrs, etr_params[-1,0,:], mtrx_params[-1,0,:])
    error2 = household.marg_ut_cons(cons1, parameters) * winit * \
        e[-1, j] * deriv2 - household.marg_ut_labor(n1, chi_n[-1], parameters)
    
    if n1 <= 0 or n1 >= 1:
        error2 += 1e12
    if b2 <= 0:
        error1 += 1e12
    if cons1 <= 0:
        error1 += 1e12
    return [error1] + [error2]
Example #2
0
def SS_TPI_firstdoughnutring(guesses, winit, rinit, BQinit, T_H_init,
                             initial_b, factor_ss, j, parameters, theta,
                             tau_bq):
    '''
    Solves the first entries of the upper triangle of the twist doughnut.  This is
    separate from the main TPI function because the the values of b and n are scalars,
    so it is easier to just have a separate function for these cases.
    Inputs:
        guesses = guess for b and n (2x1 list)
        winit = initial wage rate (scalar)
        rinit = initial rental rate (scalar)
        BQinit = initial aggregate bequest (scalar)
        T_H_init = initial lump sum tax (scalar)
        initial_b = initial distribution of capital (SxJ array)
        factor_ss = steady state scaling factor (scalar)
        j = which ability type is being solved for (scalar)
        parameters = list of parameters (list)
        theta = replacement rates (Jx1 array)
        tau_bq = bequest tax rates (Jx1 array)
    Output:
        euler errors (2x1 list)
    '''
    b2 = float(guesses[0])
    n1 = float(guesses[1])
    b1 = float(initial_b[-2, j])
    # Euler 1 equations
    tax1 = tax.total_taxes(rinit, b1, winit, e[-1, j], n1, BQinit, lambdas[j],
                           factor_ss, T_H_init, j, 'TPI_scalar', False,
                           parameters, theta, tau_bq)
    cons1 = household.get_cons(rinit, b1, winit, e[-1, j], n1, BQinit,
                               lambdas[j], b2, parameters, tax1)
    bequest_ut = rho[-1] * np.exp(-sigma * g_y) * chi_b[-1, j] * b2**(-sigma)
    error1 = household.marg_ut_cons(cons1, parameters) - bequest_ut
    # Euler 2 equations
    income2 = (rinit * b1 + winit * e[-1, j] * n1) * factor_ss
    deriv2 = 1 - tau_payroll - tax.tau_income(
        rinit, b1, winit, e[-1, j],
        n1, factor_ss, parameters) - tax.tau_income_deriv(
            rinit, b1, winit, e[-1, j], n1, factor_ss, parameters) * income2
    error2 = household.marg_ut_cons(cons1, parameters) * winit * \
        e[-1, j] * deriv2 - household.marg_ut_labor(n1, chi_n[-1], parameters)
    if n1 <= 0 or n1 >= 1:
        error2 += 1e12
    if b2 <= 0:
        error1 += 1e12
    if cons1 <= 0:
        error1 += 1e12
    return [error1] + [error2]
Example #3
0
def twist_doughnut(guesses, r, w, BQ, T_H, j, s, t, params):
    '''
    Parameters:
        guesses = distribution of capital and labor (various length list)
        w   = wage rate ((T+S)x1 array)
        r   = rental rate ((T+S)x1 array)
        BQ = aggregate bequests ((T+S)x1 array)
        T_H = lump sum tax over time ((T+S)x1 array)
        factor = scaling factor (scalar)
        j = which ability type is being solved for (scalar)
        s = which upper triangle loop is being solved for (scalar)
        t = which diagonal is being solved for (scalar)
        params = list of parameters (list)
        theta = replacement rates (Jx1 array)
        tau_bq = bequest tax rate (Jx1 array)
        rho = mortality rate (Sx1 array)
        lambdas = ability weights (Jx1 array)
        e = ability type (SxJ array)
        initial_b = capital stock distribution in period 0 (SxJ array)
        chi_b = chi^b_j (Jx1 array)
        chi_n = chi^n_s (Sx1 array)
    Output:
        Value of Euler error (various length list)
    '''

    income_tax_params, tpi_params, initial_b = params
    analytical_mtrs, etr_params, mtrx_params, mtry_params = income_tax_params
    J, S, T, BQ_dist, BW, beta, sigma, alpha, Z, delta, ltilde, nu, g_y,\
                  g_n_vector, tau_payroll, tau_bq, rho, omega, N_tilde, lambdas, e, retire, mean_income_data,\
                  factor, h_wealth, p_wealth, m_wealth, b_ellipse, upsilon, chi_b, chi_n = tpi_params

    length = len(guesses) / 2
    b_guess = np.array(guesses[:length])
    n_guess = np.array(guesses[length:])

    if length == S:
        b_s = np.array([0] + list(b_guess[:-1]))
    else:
        b_s = np.array([(initial_b[-(s + 3), j])] + list(b_guess[:-1]))

    b_splus1 = b_guess
    b_splus2 = np.array(list(b_guess[1:]) + [0])
    w_s = w[t:t + length]
    w_splus1 = w[t + 1:t + length + 1]
    r_s = r[t:t + length]
    r_splus1 = r[t + 1:t + length + 1]
    n_s = n_guess
    n_extended = np.array(list(n_guess[1:]) + [0])
    e_s = e[-length:, j]
    e_extended = np.array(list(e[-length + 1:, j]) + [0])
    BQ_s = BQ[t:t + length]
    BQ_splus1 = BQ[t + 1:t + length + 1]
    T_H_s = T_H[t:t + length]
    T_H_splus1 = T_H[t + 1:t + length + 1]
    omega = omega[t, -length:]
    BQ_dist = BQ_dist[-length:, j]
    # Savings euler equations

    # theta_params = (e[-1, j], 1, omega[0].reshape(S, 1), lambdas[j])
    # theta = tax.replacement_rate_vals(n, w, factor, theta_params)
    theta = np.zeros((J,)) 

    tax_s_params = (e_s, BQ_dist, lambdas[j], 'TPI', retire, etr_params, h_wealth, p_wealth, m_wealth, tau_payroll, theta, tau_bq, J, S)
    tax_s = tax.total_taxes(r_s, w_s, b_s, n_s, BQ_s, factor, T_H_s, j, False, tax_s_params) 

    etr_params_sp1 = np.append(etr_params,np.reshape(etr_params[-1,:],(1,etr_params.shape[1])),axis=0)[1:,:]
    taxsp1_params = (e_extended, BQ_dist, lambdas[j], 'TPI', retire, etr_params_sp1, h_wealth, p_wealth, m_wealth, tau_payroll, theta, tau_bq, J, S)
    tax_splus1 = tax.total_taxes(r_splus1, w_splus1, b_splus1, n_extended, BQ_splus1, factor, T_H_splus1, j, True, taxsp1_params) 


    cons_s_params = (e_s, BQ_dist, lambdas[j], g_y)
    cons_s = household.get_cons(omega, r_s, w_s, b_s, b_splus1, n_s, 
                   BQ_s, tax_s, cons_s_params)

    cons_sp1_params = (e_extended, BQ_dist, lambdas[j], g_y)
    cons_splus1 = household.get_cons(omega, r_splus1, w_splus1, b_splus1, b_splus2, n_extended, 
                   BQ_splus1, tax_splus1, cons_sp1_params)

    income_splus1 = (r_splus1 * b_splus1 + w_splus1 *
                     e_extended * n_extended) * factor
    savings_ut = rho[-(length):] * np.exp(-sigma * g_y) * \
        chi_b[j] * b_splus1 ** (-sigma)

    mtry_params_sp1 = np.append(mtry_params,np.reshape(mtry_params[-1,:],(1,mtry_params.shape[1])),axis=0)[1:,:]
    mtr_capital_params = (e_extended, etr_params_sp1, mtry_params_sp1, analytical_mtrs)
    deriv_savings = 1 + r_splus1 * (1 - tax.MTR_capital(r_splus1, w_splus1, b_splus1, n_extended, factor, mtr_capital_params))

    error1 = household.marg_ut_cons(cons_s, sigma) - beta * (1 - rho[-(length):]) * np.exp(-sigma * g_y) * deriv_savings * household.marg_ut_cons(
        cons_splus1, sigma) - savings_ut
    # Labor leisure euler equations
    income_s = (r_s * b_s + w_s * e_s * n_s) * factor
    

    mtr_labor_params = (e_s, etr_params, mtrx_params, analytical_mtrs)
    deriv_laborleisure = 1 - tau_payroll - tax.MTR_labor(r_s, w_s, b_s, n_s, factor, mtr_labor_params)

    mu_labor_params = (b_ellipse, upsilon, ltilde, chi_n[-length:])
    error2 = household.marg_ut_cons(cons_s, sigma) * w_s * e[-(
        length):, j] * deriv_laborleisure - household.marg_ut_labor(n_s, mu_labor_params)
    # Check and punish constraint violations
    mask1 = n_guess < 0
    error2[mask1] += 1e12
    mask2 = n_guess > ltilde
    error2[mask2] += 1e12
    mask3 = cons_s < 0
    error2[mask3] += 1e12
    mask4 = b_guess <= 0
    error2[mask4] += 1e12
    mask5 = cons_splus1 < 0
    error2[mask5] += 1e12
    return list(error1.flatten()) + list(error2.flatten())
Example #4
0
def firstdoughnutring(guesses, r, w, b, BQ, T_H, j, params):
    '''
    Solves the first entries of the upper triangle of the twist doughnut.  This is
    separate from the main TPI function because the the values of b and n are scalars,
    so it is easier to just have a separate function for these cases.
    Inputs:
        guesses = guess for b and n (2x1 list)
        winit = initial wage rate (scalar)
        rinit = initial rental rate (scalar)
        BQinit = initial aggregate bequest (scalar)
        T_H_init = initial lump sum tax (scalar)
        initial_b = initial distribution of capital (SxJ array)
        factor = steady state scaling factor (scalar)
        j = which ability type is being solved for (scalar)
        parameters = list of parameters (list)
        theta = replacement rates (Jx1 array)
        tau_bq = bequest tax rates (Jx1 array)
    Output:
        euler errors (2x1 list)
    '''

    # unpack tuples of parameters
    income_tax_params, tpi_params, initial_b = params
    analytical_mtrs, etr_params, mtrx_params, mtry_params = income_tax_params
    J, S, T, BQ_dist, BW, beta, sigma, alpha, Z, delta, ltilde, nu, g_y,\
                  g_n_vector, tau_payroll, tau_bq, rho, omega, N_tilde, lambdas, e, retire, mean_income_data,\
                  factor, h_wealth, p_wealth, m_wealth, b_ellipse, upsilon, chi_b, chi_n = tpi_params


    b_splus1 = float(guesses[0])
    n = float(guesses[1])
    b_s = float(initial_b[-2, j])
    # Euler 1 equations

    # theta_params = (e[-1, j], 1, omega[0].reshape(S, 1), lambdas[j])
    # theta = tax.replacement_rate_vals(n, w, factor, theta_params)
    theta = np.zeros((J,))

    tax1_params = (e[-1, j], BQ_dist[-1, j], lambdas[j], 'TPI_scalar', retire, etr_params[-1,0,:], h_wealth, p_wealth, m_wealth, tau_payroll, theta, tau_bq, J, S)
    tax1 = tax.total_taxes(r, w, b_s, n, BQ, factor, T_H, j, False, tax1_params) 

    cons_params = (e[-1, j], BQ_dist[-1, j], lambdas[j], g_y)
    cons = household.get_cons(omega[0,-1], r, w, b_s, b_splus1, n, BQ, tax1, cons_params)

    bequest_ut = rho[-1] * np.exp(-sigma * g_y) * chi_b[j] * b_splus1 ** (-sigma)
    error1 = household.marg_ut_cons(cons, sigma) - bequest_ut
    # Euler 2 equations
    income2 = (r * b_s + w * e[-1, j] * n) * factor

    mtr_labor_params = (e[-1, j], etr_params[-1,0,:], mtrx_params[-1,0,:], analytical_mtrs)
    deriv2 = 1 - tau_payroll - tax.MTR_labor(r, w, b_s, n, factor, mtr_labor_params)

    mu_labor_params = (b_ellipse, upsilon, ltilde, chi_n[-1])
    error2 = household.marg_ut_cons(cons, sigma) * w * \
        e[-1, j] * deriv2 - household.marg_ut_labor(n, mu_labor_params)

    #### TEST THESE FUNCS BELOW TO BE SURE GET SAME OUTPUT, but should use if so *** 
    # foc_save_params = (e[-1, j], sigma, beta, g_y, chi_b, theta, tau_bq, rho, lambdas, J, S, 
    #     analytical_mtrs, etr_params[-1,0,:], mtry_params[-1,0,:], h_wealth, p_wealth, m_wealth, tau_payroll, retire, 'TPI')   
    # error3 = household.FOC_savings(r, w, b_s, b_splus1, 0., n, BQ, factor, T_H, foc_save_params)  

    # foc_labor_params = (e[-1, j], sigma, g_y, theta, b_ellipse, upsilon, chi_n, ltilde, tau_bq, lambdas, J, S, 
    #     analytical_mtrs, etr_params[-1,0,:], mtrx_params[-1,0,:], h_wealth, p_wealth, m_wealth, tau_payroll, retire, 'TPI')   
    # error4 = household.FOC_labor(r, w, b, b_splus1, n, BQ, factor, T_H, foc_labor_params) 
    # print 'check1:', error2-error4
    # print 'check2:', error1-error3  
    if n <= 0 or n >= 1:
        error2 += 1e12
    if b_splus1 <= 0:
        error1 += 1e12
    if cons <= 0:
        error1 += 1e12
    return [error1] + [error2]
Example #5
0
def Steady_state_TPI_solver(guesses, winit, rinit, BQinit, T_H_init, factor, j,
                            s, t, params, theta, tau_bq, rho, lambdas, e,
                            initial_b, chi_b, chi_n):
    '''
    Parameters:
        guesses = distribution of capital and labor (various length list)
        winit   = wage rate ((T+S)x1 array)
        rinit   = rental rate ((T+S)x1 array)
        BQinit = aggregate bequests ((T+S)x1 array)
        T_H_init = lump sum tax over time ((T+S)x1 array)
        factor = scaling factor (scalar)
        j = which ability type is being solved for (scalar)
        s = which upper triangle loop is being solved for (scalar)
        t = which diagonal is being solved for (scalar)
        params = list of parameters (list)
        theta = replacement rates (Jx1 array)
        tau_bq = bequest tax rate (Jx1 array)
        rho = mortalit rate (Sx1 array)
        lambdas = ability weights (Jx1 array)
        e = ability type (SxJ array)
        initial_b = capital stock distribution in period 0 (SxJ array)
        chi_b = chi^b_j (Jx1 array)
        chi_n = chi^n_s (Sx1 array)
    Output:
        Value of Euler error (various length list)
    '''

    J, S, T, beta, sigma, alpha, Z, delta, ltilde, nu, g_y, g_n_ss, tau_payroll, retire, mean_income_data, \
        a_tax_income, b_tax_income, c_tax_income, d_tax_income, h_wealth, p_wealth, m_wealth, b_ellipse, upsilon = params
    length = len(guesses) / 2
    b_guess = np.array(guesses[:length])
    n_guess = np.array(guesses[length:])

    if length == S:
        b_s = np.array([0] + list(b_guess[:-1]))
    else:
        b_s = np.array([(initial_b[-(s + 3), j])] + list(b_guess[:-1]))
    b_splus1 = b_guess
    b_splus2 = np.array(list(b_guess[1:]) + [0])
    w_s = winit[t:t + length]
    w_splus1 = winit[t + 1:t + length + 1]
    r_s = rinit[t:t + length]
    r_splus1 = rinit[t + 1:t + length + 1]
    n_s = n_guess
    n_extended = np.array(list(n_guess[1:]) + [0])
    e_s = e[-length:, j]
    e_extended = np.array(list(e[-length + 1:, j]) + [0])
    BQ_s = BQinit[t:t + length]
    BQ_splus1 = BQinit[t + 1:t + length + 1]
    T_H_s = T_H_init[t:t + length]
    T_H_splus1 = T_H_init[t + 1:t + length + 1]
    # Savings euler equations
    tax_s = tax.total_taxes(r_s, b_s, w_s, e_s, n_s, BQ_s, lambdas[j], factor,
                            T_H_s, j, 'TPI', False, params, theta, tau_bq)
    tax_splus1 = tax.total_taxes(r_splus1, b_splus1, w_splus1, e_extended,
                                 n_extended, BQ_splus1, lambdas[j], factor,
                                 T_H_splus1, j, 'TPI', True, params, theta,
                                 tau_bq)
    cons_s = household.get_cons(r_s, b_s, w_s, e_s, n_s, BQ_s, lambdas[j],
                                b_splus1, params, tax_s)
    cons_splus1 = household.get_cons(r_splus1, b_splus1, w_splus1, e_extended,
                                     n_extended, BQ_splus1, lambdas[j],
                                     b_splus2, params, tax_splus1)
    income_splus1 = (r_splus1 * b_splus1 +
                     w_splus1 * e_extended * n_extended) * factor
    savings_ut = rho[-(length):] * np.exp(-sigma * g_y) * \
        chi_b[-(length):, j] * b_splus1 ** (-sigma)
    deriv_savings = 1 + r_splus1 * (
        1 - tax.tau_income(r_splus1, b_splus1, w_splus1, e_extended,
                           n_extended, factor, params) -
        tax.tau_income_deriv(r_splus1, b_splus1, w_splus1, e_extended,
                             n_extended, factor, params) * income_splus1
    ) - tax.tau_w_prime(b_splus1, params) * b_splus1 - tax.tau_wealth(
        b_splus1, params)
    error1 = household.marg_ut_cons(
        cons_s, params) - beta * (1 - rho[-(length):]) * np.exp(
            -sigma * g_y) * deriv_savings * household.marg_ut_cons(
                cons_splus1, params) - savings_ut
    # Labor leisure euler equations
    income_s = (r_s * b_s + w_s * e_s * n_s) * factor
    deriv_laborleisure = 1 - tau_payroll - tax.tau_income(
        r_s, b_s, w_s, e_s, n_s, factor, params) - tax.tau_income_deriv(
            r_s, b_s, w_s, e_s, n_s, factor, params) * income_s
    error2 = household.marg_ut_cons(cons_s, params) * w_s * e[
        -(length):, j] * deriv_laborleisure - household.marg_ut_labor(
            n_s, chi_n[-length:], params)
    # Check and punish constraint violations
    mask1 = n_guess < 0
    error2[mask1] += 1e12
    mask2 = n_guess > ltilde
    error2[mask2] += 1e12
    mask3 = cons_s < 0
    error2[mask3] += 1e12
    mask4 = b_guess <= 0
    error2[mask4] += 1e12
    mask5 = cons_splus1 < 0
    error2[mask5] += 1e12
    return list(error1.flatten()) + list(error2.flatten())
Example #6
0
def twist_doughnut(guesses, r, w, BQ, T_H, j, s, t, params):
    '''
    Parameters:
        guesses = distribution of capital and labor (various length list)
        w   = wage rate ((T+S)x1 array)
        r   = rental rate ((T+S)x1 array)
        BQ = aggregate bequests ((T+S)x1 array)
        T_H = lump sum tax over time ((T+S)x1 array)
        factor = scaling factor (scalar)
        j = which ability type is being solved for (scalar)
        s = which upper triangle loop is being solved for (scalar)
        t = which diagonal is being solved for (scalar)
        params = list of parameters (list)
        theta = replacement rates (Jx1 array)
        tau_bq = bequest tax rate (Jx1 array)
        rho = mortalit rate (Sx1 array)
        lambdas = ability weights (Jx1 array)
        e = ability type (SxJ array)
        initial_b = capital stock distribution in period 0 (SxJ array)
        chi_b = chi^b_j (Jx1 array)
        chi_n = chi^n_s (Sx1 array)
    Output:
        Value of Euler error (various length list)
    '''

    income_tax_params, tpi_params, initial_b = params
    analytical_mtrs, etr_params, mtrx_params, mtry_params = income_tax_params
    J, S, T, BW, beta, sigma, alpha, Z, delta, ltilde, nu, g_y,\
                  g_n_vector, tau_payroll, tau_bq, rho, omega, N_tilde, lambdas, e, retire, mean_income_data,\
                  factor, h_wealth, p_wealth, m_wealth, b_ellipse, upsilon, chi_b, chi_n = tpi_params

    length = len(guesses) / 2
    b_guess = np.array(guesses[:length])
    n_guess = np.array(guesses[length:])

    if length == S:
        b_s = np.array([0] + list(b_guess[:-1]))
    else:
        b_s = np.array([(initial_b[-(s + 3), j])] + list(b_guess[:-1]))

    b_splus1 = b_guess
    b_splus2 = np.array(list(b_guess[1:]) + [0])
    w_s = w[t:t + length]
    w_splus1 = w[t + 1:t + length + 1]
    r_s = r[t:t + length]
    r_splus1 = r[t + 1:t + length + 1]
    n_s = n_guess
    n_extended = np.array(list(n_guess[1:]) + [0])
    e_s = e[-length:, j]
    e_extended = np.array(list(e[-length + 1:, j]) + [0])
    BQ_s = BQ[t:t + length]
    BQ_splus1 = BQ[t + 1:t + length + 1]
    T_H_s = T_H[t:t + length]
    T_H_splus1 = T_H[t + 1:t + length + 1]
    # Savings euler equations

    # theta_params = (e[-1, j], 1, omega[0].reshape(S, 1), lambdas[j])
    # theta = tax.replacement_rate_vals(n, w, factor, theta_params)
    theta = np.zeros((J, ))

    tax_s_params = (e_s, lambdas[j], 'TPI', retire, etr_params, h_wealth,
                    p_wealth, m_wealth, tau_payroll, theta, tau_bq, J, S)
    tax_s = tax.total_taxes(r_s, w_s, b_s, n_s, BQ_s, factor, T_H_s, j, False,
                            tax_s_params)

    etr_params_sp1 = np.append(etr_params,
                               np.reshape(etr_params[-1, :],
                                          (1, etr_params.shape[1])),
                               axis=0)[1:, :]
    taxsp1_params = (e_extended, lambdas[j], 'TPI', retire, etr_params_sp1,
                     h_wealth, p_wealth, m_wealth, tau_payroll, theta, tau_bq,
                     J, S)
    tax_splus1 = tax.total_taxes(r_splus1, w_splus1, b_splus1, n_extended,
                                 BQ_splus1, factor, T_H_splus1, j, True,
                                 taxsp1_params)

    cons_s_params = (e_s, lambdas[j], g_y)
    cons_s = household.get_cons(r_s, w_s, b_s, b_splus1, n_s, BQ_s, tax_s,
                                cons_s_params)

    cons_sp1_params = (e_extended, lambdas[j], g_y)
    cons_splus1 = household.get_cons(r_splus1, w_splus1, b_splus1, b_splus2,
                                     n_extended, BQ_splus1, tax_splus1,
                                     cons_sp1_params)

    income_splus1 = (r_splus1 * b_splus1 +
                     w_splus1 * e_extended * n_extended) * factor
    savings_ut = rho[-(length):] * np.exp(-sigma * g_y) * \
        chi_b[j] * b_splus1 ** (-sigma)

    mtry_params_sp1 = np.append(mtry_params,
                                np.reshape(mtry_params[-1, :],
                                           (1, mtry_params.shape[1])),
                                axis=0)[1:, :]
    mtr_capital_params = (e_extended, etr_params_sp1, mtry_params_sp1,
                          analytical_mtrs)
    deriv_savings = 1 + r_splus1 * (1 - tax.MTR_capital(
        r_splus1, w_splus1, b_splus1, n_extended, factor, mtr_capital_params))

    error1 = household.marg_ut_cons(
        cons_s, sigma) - beta * (1 - rho[-(length):]) * np.exp(
            -sigma * g_y) * deriv_savings * household.marg_ut_cons(
                cons_splus1, sigma) - savings_ut
    # Labor leisure euler equations
    income_s = (r_s * b_s + w_s * e_s * n_s) * factor

    mtr_labor_params = (e_s, etr_params, mtrx_params, analytical_mtrs)
    deriv_laborleisure = 1 - tau_payroll - tax.MTR_labor(
        r_s, w_s, b_s, n_s, factor, mtr_labor_params)

    mu_labor_params = (b_ellipse, upsilon, ltilde, chi_n[-length:])
    error2 = household.marg_ut_cons(cons_s, sigma) * w_s * e[
        -(length):, j] * deriv_laborleisure - household.marg_ut_labor(
            n_s, mu_labor_params)
    # Check and punish constraint violations
    mask1 = n_guess < 0
    error2[mask1] += 1e12
    mask2 = n_guess > ltilde
    error2[mask2] += 1e12
    mask3 = cons_s < 0
    error2[mask3] += 1e12
    mask4 = b_guess <= 0
    error2[mask4] += 1e12
    mask5 = cons_splus1 < 0
    error2[mask5] += 1e12
    return list(error1.flatten()) + list(error2.flatten())
Example #7
0
def firstdoughnutring(guesses, r, w, b, BQ, T_H, j, params):
    '''
    Solves the first entries of the upper triangle of the twist doughnut.  This is
    separate from the main TPI function because the the values of b and n are scalars,
    so it is easier to just have a separate function for these cases.
    Inputs:
        guesses = guess for b and n (2x1 list)
        winit = initial wage rate (scalar)
        rinit = initial rental rate (scalar)
        BQinit = initial aggregate bequest (scalar)
        T_H_init = initial lump sum tax (scalar)
        initial_b = initial distribution of capital (SxJ array)
        factor = steady state scaling factor (scalar)
        j = which ability type is being solved for (scalar)
        parameters = list of parameters (list)
        theta = replacement rates (Jx1 array)
        tau_bq = bequest tax rates (Jx1 array)
    Output:
        euler errors (2x1 list)
    '''

    # unpack tuples of parameters
    income_tax_params, tpi_params, initial_b = params
    analytical_mtrs, etr_params, mtrx_params, mtry_params = income_tax_params
    J, S, T, BW, beta, sigma, alpha, Z, delta, ltilde, nu, g_y,\
                  g_n_vector, tau_payroll, tau_bq, rho, omega, N_tilde, lambdas, e, retire, mean_income_data,\
                  factor, h_wealth, p_wealth, m_wealth, b_ellipse, upsilon, chi_b, chi_n = tpi_params

    b_splus1 = float(guesses[0])
    n = float(guesses[1])
    b_s = float(initial_b[-2, j])
    # Euler 1 equations

    # theta_params = (e[-1, j], 1, omega[0].reshape(S, 1), lambdas[j])
    # theta = tax.replacement_rate_vals(n, w, factor, theta_params)
    theta = np.zeros((J, ))

    tax1_params = (e[-1, j], lambdas[j], 'TPI_scalar', retire,
                   etr_params[-1, 0, :], h_wealth, p_wealth, m_wealth,
                   tau_payroll, theta, tau_bq, J, S)
    tax1 = tax.total_taxes(r, w, b_s, n, BQ, factor, T_H, j, False,
                           tax1_params)

    cons_params = (e[-1, j], lambdas[j], g_y)
    cons = household.get_cons(r, w, b_s, b_splus1, n, BQ, tax1, cons_params)

    bequest_ut = rho[-1] * np.exp(-sigma * g_y) * chi_b[j] * b_splus1**(-sigma)
    error1 = household.marg_ut_cons(cons, sigma) - bequest_ut
    # Euler 2 equations
    income2 = (r * b_s + w * e[-1, j] * n) * factor

    mtr_labor_params = (e[-1, j], etr_params[-1, 0, :], mtrx_params[-1, 0, :],
                        analytical_mtrs)
    deriv2 = 1 - tau_payroll - tax.MTR_labor(r, w, b_s, n, factor,
                                             mtr_labor_params)

    mu_labor_params = (b_ellipse, upsilon, ltilde, chi_n[-1])
    error2 = household.marg_ut_cons(cons, sigma) * w * \
        e[-1, j] * deriv2 - household.marg_ut_labor(n, mu_labor_params)

    #### TEST THESE FUNCS BELOW TO BE SURE GET SAME OUTPUT, but should use if so ***
    # foc_save_params = (e[-1, j], sigma, beta, g_y, chi_b, theta, tau_bq, rho, lambdas, J, S,
    #     analytical_mtrs, etr_params[-1,0,:], mtry_params[-1,0,:], h_wealth, p_wealth, m_wealth, tau_payroll, retire, 'TPI')
    # error3 = household.FOC_savings(r, w, b_s, b_splus1, 0., n, BQ, factor, T_H, foc_save_params)

    # foc_labor_params = (e[-1, j], sigma, g_y, theta, b_ellipse, upsilon, chi_n, ltilde, tau_bq, lambdas, J, S,
    #     analytical_mtrs, etr_params[-1,0,:], mtrx_params[-1,0,:], h_wealth, p_wealth, m_wealth, tau_payroll, retire, 'TPI')
    # error4 = household.FOC_labor(r, w, b, b_splus1, n, BQ, factor, T_H, foc_labor_params)
    # print 'check1:', error2-error4
    # print 'check2:', error1-error3

    if n <= 0 or n >= 1:
        error2 += 1e12
    if b_splus1 <= 0:
        error1 += 1e12
    if cons <= 0:
        error1 += 1e12
    return [error1] + [error2]
Example #8
0
def Steady_state_TPI_solver(guesses, winit, rinit, BQinit, T_H_init, factor, j, s, t, params, theta, tau_bq, rho, lambdas, e, initial_b, chi_b, chi_n):
    '''
    Parameters:
        guesses = distribution of capital and labor (various length list)
        winit   = wage rate ((T+S)x1 array)
        rinit   = rental rate ((T+S)x1 array)
        BQinit = aggregate bequests ((T+S)x1 array)
        T_H_init = lump sum tax over time ((T+S)x1 array)
        factor = scaling factor (scalar)
        j = which ability type is being solved for (scalar)
        s = which upper triangle loop is being solved for (scalar)
        t = which diagonal is being solved for (scalar)
        params = list of parameters (list)
        theta = replacement rates (Jx1 array)
        tau_bq = bequest tax rate (Jx1 array)
        rho = mortalit rate (Sx1 array)
        lambdas = ability weights (Jx1 array)
        e = ability type (SxJ array)
        initial_b = capital stock distribution in period 0 (SxJ array)
        chi_b = chi^b_j (Jx1 array)
        chi_n = chi^n_s (Sx1 array)
    Output:
        Value of Euler error (various length list)
    '''

    J, S, T, beta, sigma, alpha, Z, delta, ltilde, nu, g_y, g_n_ss, tau_payroll, retire, mean_income_data, \
        a_tax_income, b_tax_income, c_tax_income, d_tax_income, h_wealth, p_wealth, m_wealth, b_ellipse, upsilon = params
    length = len(guesses) / 2
    b_guess = np.array(guesses[:length])
    n_guess = np.array(guesses[length:])

    if length == S:
        b_s = np.array([0] + list(b_guess[:-1]))
    else:
        b_s = np.array([(initial_b[-(s + 3), j])] + list(b_guess[:-1]))
    b_splus1 = b_guess
    b_splus2 = np.array(list(b_guess[1:]) + [0])
    w_s = winit[t:t + length]
    w_splus1 = winit[t + 1:t + length + 1]
    r_s = rinit[t:t + length]
    r_splus1 = rinit[t + 1:t + length + 1]
    n_s = n_guess
    n_extended = np.array(list(n_guess[1:]) + [0])
    e_s = e[-length:, j]
    e_extended = np.array(list(e[-length + 1:, j]) + [0])
    BQ_s = BQinit[t:t + length]
    BQ_splus1 = BQinit[t + 1:t + length + 1]
    T_H_s = T_H_init[t:t + length]
    T_H_splus1 = T_H_init[t + 1:t + length + 1]
    # Savings euler equations
    tax_s = tax.total_taxes(r_s, b_s, w_s, e_s, n_s, BQ_s, lambdas[
                            j], factor, T_H_s, j, 'TPI', False, params, theta, tau_bq)
    tax_splus1 = tax.total_taxes(r_splus1, b_splus1, w_splus1, e_extended, n_extended, BQ_splus1, lambdas[
                                 j], factor, T_H_splus1, j, 'TPI', True, params, theta, tau_bq)
    cons_s = household.get_cons(r_s, b_s, w_s, e_s, n_s, BQ_s, lambdas[
                                j], b_splus1, params, tax_s)
    cons_splus1 = household.get_cons(r_splus1, b_splus1, w_splus1, e_extended, n_extended, BQ_splus1, lambdas[
                                     j], b_splus2, params, tax_splus1)
    income_splus1 = (r_splus1 * b_splus1 + w_splus1 *
                     e_extended * n_extended) * factor
    savings_ut = rho[-(length):] * np.exp(-sigma * g_y) * \
        chi_b[-(length):, j] * b_splus1 ** (-sigma)
    deriv_savings = 1 + r_splus1 * (1 - tax.tau_income(
        r_splus1, b_splus1, w_splus1, e_extended, n_extended, factor, params) - tax.tau_income_deriv(
        r_splus1, b_splus1, w_splus1, e_extended, n_extended, factor, params) * income_splus1) - tax.tau_w_prime(
        b_splus1, params) * b_splus1 - tax.tau_wealth(b_splus1, params)
    error1 = household.marg_ut_cons(cons_s, params) - beta * (1 - rho[-(length):]) * np.exp(-sigma * g_y) * deriv_savings * household.marg_ut_cons(
        cons_splus1, params) - savings_ut
    # Labor leisure euler equations
    income_s = (r_s * b_s + w_s * e_s * n_s) * factor
    deriv_laborleisure = 1 - tau_payroll - tax.tau_income(r_s, b_s, w_s, e_s, n_s, factor, params) - tax.tau_income_deriv(
        r_s, b_s, w_s, e_s, n_s, factor, params) * income_s
    error2 = household.marg_ut_cons(cons_s, params) * w_s * e[-(
        length):, j] * deriv_laborleisure - household.marg_ut_labor(n_s, chi_n[-length:], params)
    # Check and punish constraint violations
    mask1 = n_guess < 0
    error2[mask1] += 1e12
    mask2 = n_guess > ltilde
    error2[mask2] += 1e12
    mask3 = cons_s < 0
    error2[mask3] += 1e12
    mask4 = b_guess <= 0
    error2[mask4] += 1e12
    mask5 = cons_splus1 < 0
    error2[mask5] += 1e12
    return list(error1.flatten()) + list(error2.flatten())