Пример #1
0
def calculateLorenzDifference(sim_wealth, weights, percentiles, target_levels):
    '''
    Calculates the sum of squared differences between the simulatedLorenz curve
    at the specified percentile levels and the target Lorenz levels.
    
    Parameters:
    -------------
    sim_wealth : numpy.array
        Array with simulated wealth values.
    weights : numpy.array
        List of weights for each row of sim_wealth.
    percentiles : [float]
        Points in the distribution of wealth to match.
    target_levels : np.array
        Actual U.S. Lorenz curve levels at the specified percentiles.
        
    Returns:
    -----------
    distance : float
        Sum of squared distances between simulated and target Lorenz curves.
    '''
    sim_lorenz = getLorenzPercentiles(sim_wealth,
                                      weights=weights,
                                      percentiles=percentiles)
    distance = sum((100 * sim_lorenz - 100 * target_levels)**2)
    return distance
Пример #2
0
def makeLorenzFig(real_wealth,real_weights,sim_wealth,sim_weights):
    '''
    Produces a Lorenz curve for the distribution of wealth, comparing simulated
    to actual data.  A sub-function of makeCSTWresults().
    '''
    these_percents = np.linspace(0.0001,0.9999,201)
    real_lorenz = getLorenzPercentiles(real_wealth,weights=real_weights,percentiles=these_percents)
    sim_lorenz = getLorenzPercentiles(sim_wealth,weights=sim_weights,percentiles=these_percents)
    plt.plot(100*these_percents,real_lorenz,'-k',linewidth=1.5)
    plt.plot(100*these_percents,sim_lorenz,'--k',linewidth=1.5)
    plt.xlabel('Wealth percentile',fontsize=14)
    plt.ylabel('Cumulative wealth ownership',fontsize=14)
    plt.title('Simulated vs Actual Lorenz Curves',fontsize=16)
    plt.legend(('Actual','Simulated'),loc=2,fontsize=12)
    plt.ylim(-0.01,1)
    plt.show()
    return (these_percents,real_lorenz,sim_lorenz)
Пример #3
0
def makeLorenzFig(real_wealth, real_weights, sim_wealth, sim_weights):
    '''
    Produces a Lorenz curve for the distribution of wealth, comparing simulated
    to actual data.  A sub-function of makeCSTWresults().
    '''
    these_percents = np.linspace(0.0001, 0.9999, 201)
    real_lorenz = getLorenzPercentiles(real_wealth,
                                       weights=real_weights,
                                       percentiles=these_percents)
    sim_lorenz = getLorenzPercentiles(sim_wealth,
                                      weights=sim_weights,
                                      percentiles=these_percents)
    plt.plot(100 * these_percents, real_lorenz, '-k', linewidth=1.5)
    plt.plot(100 * these_percents, sim_lorenz, '--k', linewidth=1.5)
    plt.xlabel('Wealth percentile', fontsize=14)
    plt.ylabel('Cumulative wealth ownership', fontsize=14)
    plt.title('Simulated vs Actual Lorenz Curves', fontsize=16)
    plt.legend(('Actual', 'Simulated'), loc=2, fontsize=12)
    plt.ylim(-0.01, 1)
    plt.show()
    return (these_percents, real_lorenz, sim_lorenz)
Пример #4
0
def calculateLorenzDifference(sim_wealth,weights,percentiles,target_levels):
    '''
    Calculates the sum of squared differences between the simulatedLorenz curve
    at the specified percentile levels and the target Lorenz levels.
    
    Parameters:
    -------------
    sim_wealth : numpy.array
        Array with simulated wealth values.
    weights : numpy.array
        List of weights for each row of sim_wealth.
    percentiles : [float]
        Points in the distribution of wealth to match.
    target_levels : np.array
        Actual U.S. Lorenz curve levels at the specified percentiles.
        
    Returns:
    -----------
    distance : float
        Sum of squared distances between simulated and target Lorenz curves.
    '''
    sim_lorenz = getLorenzPercentiles(sim_wealth,weights=weights,percentiles=percentiles)
    distance = sum((100*sim_lorenz-100*target_levels)**2)
    return distance
Пример #5
0
        np.tile(Params.age_weight_short / float(Params.pref_type_count),
                Params.pref_type_count))
    return kappa_all


# =================================================================
# ====== Make the list of consumer types for estimation ===========
#==================================================================

# Set target Lorenz points and K/Y ratio (MOVE THIS TO SetupParams)
if Params.do_liquid:
    lorenz_target = np.array([0.0, 0.004, 0.025, 0.117])
    KY_target = 6.60
else:  # This is hacky until I can find the liquid wealth data and import it
    lorenz_target = getLorenzPercentiles(
        Params.SCF_wealth,
        weights=Params.SCF_weights,
        percentiles=Params.percentiles_to_match)
    KY_target = 10.26

# Make a vector of initial wealth-to-permanent income ratios
w0_vector = simulateDiscreteDistribution(P=Params.w0_probs,
                                         X=Params.w0_values,
                                         N=Params.sim_pop_size,
                                         seed=Params.w0_seed)

# Make the list of types for this run, whether infinite or lifecycle
if Params.do_lifecycle:
    # Make base consumer types for each education level
    DropoutType = cstwMPCagent(**Params.init_dropout)
    DropoutType.w0 = w0_vector
    HighschoolType = deepcopy(DropoutType)
Пример #6
0
    return kappa_all
   
   

# Only run below this line if module is run rather than imported:
if __name__ == "__main__":
    # =================================================================
    # ====== Make the list of consumer types for estimation ===========
    #==================================================================
    
    # Set target Lorenz points and K/Y ratio (MOVE THIS TO SetupParams)
    if Params.do_liquid:
        lorenz_target = np.array([0.0, 0.004, 0.025,0.117])
        KY_target = 6.60
    else: # This is hacky until I can find the liquid wealth data and import it
        lorenz_target = getLorenzPercentiles(Params.SCF_wealth,weights=Params.SCF_weights,percentiles=Params.percentiles_to_match)
        #lorenz_target = np.array([-0.002, 0.01, 0.053,0.171])
        KY_target = 10.26
    
    
    # Make a vector of initial wealth-to-permanent income ratios
    w0_vector = generateDiscreteDraws(P=Params.w0_probs,
                                             X=Params.w0_values,
                                             N=Params.sim_pop_size,
                                             seed=Params.w0_seed)
                                             
    # Make the list of types for this run, whether infinite or lifecycle
    if Params.do_lifecycle:
        # Make base consumer types for each education level
        DropoutType = cstwMPCagent(**Params.init_dropout)
        DropoutType.w0 = w0_vector