def check_khat(): first_poor = ineq.Individual(beta = BETA, theta_bar=THETA_BAR, bequest=B_POOR_0, educ=EDU_POOR_0, type="p") first_rich = ineq.Individual(beta = BETA, theta_bar=THETA_BAR, bequest=B_RICH_0, educ=EDU_RICH_0, type="r") first_school = ineq.Education(gamma=GAMMA, tech=EDU_TECH) first_firm = ineq.CESProd(K=.03, H=1, A=10.0, epsilon=.4, sigma=1) current_economy = ineq.Economy(indiv_r=first_rich, indiv_p=first_poor, school=first_school, firm=first_firm, fraction_r=RICH_FRAC, imperfections=IMPERFECTIONS) if not round(current_economy.find_khat(), 5) == .00056: print "KHAT1", round(current_economy.find_khat(), 5)
def check_inverse_wages(): new_firm = ineq.CESProd(K=.02, H=1, A=1, epsilon=.5, sigma=1) if not round(new_firm.inverse_wages(.03), 5) == round(0.06**2, 5): print "IW1", round(new_firm.inverse_wages(.03), 5), round(0.06**2, 5) new_firm_B = ineq.CESProd(K=new_firm.inverse_wages(.03), H=new_firm._H, A=new_firm._A, epsilon=new_firm._epsilon, sigma=new_firm.get_sigma()) if not abs(new_firm_B.factor_payments()[1] - .03) < .001: print "IW2", new_firm_B.factor_payments()[1] new_firm_C = ineq.CESProd(K=0.02098525515420107, H=new_firm._H, A=new_firm._A, epsilon=new_firm._epsilon, sigma=new_firm.get_sigma()) if not new_firm_C.factor_payments()[1] > new_firm_B.factor_payments()[1]: print "IW3", new_firm_C.factor_payments()[1], new_firm_B.factor_payments()[1]
def check_regimeI_ss(): #Parameters SIGMA = 1.5 EPSILON = .7 DELTA = 1.0 EDU_TECH = 1 GAMMA = .5 BETA = .25 THETA_BAR = .01 RICH_FRAC = .001 IMPERFECTIONS = True #Starting Values A_0 = 1.0 B_RICH_0 = .001 / RICH_FRAC B_POOR_0 = 0.0 EDU_POOR_0 = 0.0 EDU_RICH_0 = 0.0 assert B_RICH_0 >= EDU_RICH_0 assert B_POOR_0 >= EDU_POOR_0 #new parameters new_krange = 1 #with these initial conditions the cutoff for regime I should be less than 1. new_kstep = 2000.0 #Initialize economy. first_poor = ineq.Individual(beta = BETA, theta_bar=THETA_BAR, bequest=B_POOR_0, educ=EDU_POOR_0, type="p") first_rich = ineq.Individual(beta = BETA, theta_bar=THETA_BAR, bequest=B_RICH_0, educ=EDU_RICH_0, type="r") first_school = ineq.Education(gamma=GAMMA, tech=EDU_TECH) K_0 = RICH_FRAC * (B_RICH_0 - EDU_RICH_0) + (1 - RICH_FRAC) * (B_POOR_0 - EDU_POOR_0) H_0 = RICH_FRAC * first_school.hc(EDU_RICH_0) + (1 - RICH_FRAC) * first_school.hc(EDU_POOR_0) first_firm = ineq.CESProd(sigma=SIGMA, epsilon=EPSILON, K=K_0, H=H_0, A=A_0, delta=DELTA) current_economy = ineq.Economy(indiv_r=first_rich, indiv_p=first_poor, school=first_school, firm=first_firm, fraction_r=RICH_FRAC, imperfections=IMPERFECTIONS) # Find regime I SS guess_ss = current_economy.find_ss_regimeI(krange=new_krange, kstep=new_kstep)[0] #Start a new economy in the regime I SS to make sure it stays there. new_K_0 = guess_ss second_rich = ineq.Individual(beta = BETA, theta_bar=THETA_BAR, bequest= guess_ss / RICH_FRAC, educ=EDU_RICH_0, type="r") second_firm = ineq.CESProd(sigma=SIGMA, epsilon=EPSILON, K=new_K_0, H=H_0, A=A_0, delta=DELTA) second_economy = ineq.Economy(indiv_r=second_rich, indiv_p=first_poor, school=first_school, firm=second_firm, fraction_r=RICH_FRAC, imperfections=IMPERFECTIONS) new_economy = second_economy for dummy_i in range(30): #iterate for 30 periods to make sure still in SS. next_economy = new_economy.start_next(krange=new_krange, kstep=new_kstep) new_economy = next_economy if not abs(new_economy.get_littlek() - guess_ss) < .01: print "RIss1", new_economy.get_littlek(), guess_ss
def check_output(): """ Check output calculations """ #Big F if not test_firm_ces.output() == 25: print "OUT1", test_firm_ces.output() if not abs(test_firm_cd.output() - 22.63) < .01: print "OUT2", test_firm_cd.output() #little F (and equality) if not test_firm_ces.littlef() == 25 / 16.0: print "OUT3", test_firm_ces.littlef(), 25 / 16 if not abs(test_firm_cd.littlef() - 22.63 / 16) < .001: print "OUT4", test_firm_cd.output() # A test (Added later) test_firm_cesB = ineq.CESProd(2, .25, 64, 16, A=2) if not test_firm_cesB.output() == test_firm_ces.output() * 2: print "OUT5", test_firm_ces.output() if not test_firm_cesB.littlef() == test_firm_ces.littlef() * 2: print "OUT6", test_firm_cesB.littlef()
__author__ = 'Greg' import InequalityClasses as ineq test_school = ineq.Education(.75, 2) def test_education(): if not test_school.hc(0) == 1: print "EDUC1", test_school.hc(0) if not round(test_school.hc(4), 2) == 6.66: print "EDUC2", test_school.hc(4) if not round(test_school.hprime(3), 2) == 1.14: print "EDU3", round(test_school.hprime(3), 2) if not round(test_school.hprime_inverse(3), 2) == .06: print "EDU4", round(test_school.hprime_inverse(3), 2) test_education()
IMPERFECTIONS = True #Starting Values A_0 = 10.0 B_RICH_0 = .001 / RICH_FRAC B_POOR_0 = 0.0 EDU_POOR_0 = 0.0 EDU_RICH_0 = 0.0 assert B_RICH_0 >= EDU_RICH_0 assert B_POOR_0 >= EDU_POOR_0 ####################################Run Model #Initialize first_poor = ineq.Individual(beta = BETA, theta_bar=THETA_BAR, bequest=B_POOR_0, educ=EDU_POOR_0, type="p") first_rich = ineq.Individual(beta = BETA, theta_bar=THETA_BAR, bequest=B_RICH_0, educ=EDU_RICH_0, type="r") first_school = ineq.Education(gamma=GAMMA, tech=EDU_TECH) K_0 = RICH_FRAC * (B_RICH_0 - EDU_RICH_0) + (1 - RICH_FRAC) * (B_POOR_0 - EDU_POOR_0) print "K_0: ", K_0 H_0 = RICH_FRAC * first_school.hc(EDU_RICH_0) + (1 - RICH_FRAC) * first_school.hc(EDU_POOR_0) print "H_0: ", H_0 first_firm = ineq.CESProd(sigma=SIGMA, epsilon=EPSILON, K=K_0, H=H_0, A=A_0, delta=DELTA) current_economy = ineq.Economy(indiv_r=first_rich, indiv_p=first_poor, school=first_school, firm=first_firm, fraction_r=RICH_FRAC, imperfections=IMPERFECTIONS)
__author__ = 'Greg' import InequalityClasses as ineq test_indiv_convex = ineq.Individual(.25, 2, 4, 2, "p") test_indiv_linear = ineq.Individual(.25, 0, 4, 2, "p") def check_indiv(): if not test_indiv_convex.income(3, 2, 3) == 12: print "IND1", test_indiv.income(3, 2, 3) if not test_indiv_linear.decisions(3) == (3 * .75, .25 * 3): print "IND2", test_indiv_convex.decisions(3) if not test_indiv_convex.decisions(3) == (3, 0): print "IND3", test_indiv_convex.decisions(3) if not test_indiv_convex.decisions(7) == (6.75, .25): print "IND4", test_indiv_convex.decisions(7) check_indiv()
def check_inverse_littlef(): new_firm = ineq.CESProd(K=.03, H=1, A=10.0, epsilon=.4, sigma=2) if not round(new_firm.inverse_wages(), 2) == 12.25: print "IF1", round(new_firm.inverse_wages(), 2)
def check_factor_payments(): """ check factor payments calculations. NOTE: delta not tested. """ # Check Calculation. bigR, wages = test_firm_ces.factor_payments() if not max([abs(bigR - .15625), abs(wages - .9375)]) < .001: print "FAC1", (bigR, wages) bigR, wages = test_firm_cd.factor_payments() if not max([abs(bigR - .088), abs(wages - 1.061)]) < .001: print "FAC2", (bigR, wages) # check A bigR, wages = test_firm_ces.factor_payments() bigR_B, wages_B = test_firm_cesB.factor_payments() if not max([abs(2.0 * bigR - bigR_B), abs(2.0 * wages - wages_B)]) < .00001: print "FAC1B", (2.0 * bigR, 2.0 * wages), (bigR_B, wages_B) # Check equality for wages with f(k) - f'(k)k bigR, wages = test_firm_ces.factor_payments() fk = test_firm_ces.littlef() littlek = test_firm_ces._K / test_firm_ces._H fprimek = test_firm_ces._epsilon * fk**( 1.0 / test_firm_ces._sigma) * littlek**(-1.0 / test_firm_ces._sigma) if not bigR - fprimek == 0.0: print "FAC3", bigR - fprimek if not wages - (fk - fprimek * littlek) == 0.0: print "FAC4", wages - (fk - fprimek * littlek) # check limits (restricted to the case of sigma >= 1) limit_test_low = ineq.CESProd( 2, .25, .00000000000000000000000000000000000000000000000000000000000000000000000001, .01) bigR, wages = limit_test_low.factor_payments() if bigR < 100000: print "FAC5", bigR limit_test_high = ineq.CESProd( 2, .25, 10000000000000000000000000000000000000000000000000000000000000000000000000, .01) bigR, wages = limit_test_high.factor_payments() if bigR != limit_test_low._epsilon**2: print "FAC6", bigR limit_test_high = ineq.CESProd( 2, .25, 1, 10000000000000000000000000000000000000000000000000000000000000000000000000 ) bigR, wages = limit_test_high.factor_payments() if wages != (1 - limit_test_low._epsilon)**2: print "FAC7", wages limit_test_high = ineq.CESProd( 2, .25, 1, .00000000000000000000000000000000000000000000000000000000000000000000000001 ) bigR, wages = limit_test_high.factor_payments() if wages < 100000000000: print "FAC8", wages
__author__ = 'Greg' import InequalityClasses as ineq test_firm_ces = ineq.CESProd(2, .25, 64, 16) test_firm_cd = ineq.CESProd(1, .25, 64, 16) test_firm_cesB = ineq.CESProd(2, .25, 64, 16, A=2) # A added later def check_output(): """ Check output calculations """ #Big F if not test_firm_ces.output() == 25: print "OUT1", test_firm_ces.output() if not abs(test_firm_cd.output() - 22.63) < .01: print "OUT2", test_firm_cd.output() #little F (and equality) if not test_firm_ces.littlef() == 25 / 16.0: print "OUT3", test_firm_ces.littlef(), 25 / 16 if not abs(test_firm_cd.littlef() - 22.63 / 16) < .001: print "OUT4", test_firm_cd.output() # A test (Added later) test_firm_cesB = ineq.CESProd(2, .25, 64, 16, A=2) if not test_firm_cesB.output() == test_firm_ces.output() * 2: print "OUT5", test_firm_ces.output() if not test_firm_cesB.littlef() == test_firm_ces.littlef() * 2: print "OUT6", test_firm_cesB.littlef()