import numpy as np
def pol(age, emp):
if age < 25:
return 5000
elif age < 35 and emp == 0:
return 10000
elif age < 35 and emp == 1:
return 2000
elif age >= 35:
return 0
def get_income(age, pi, emp=None):
if emp == None:
emp = np.random.choice(np.array([0,1]), p=[0.2, 0.8])
us = np.random.randint(-5000,10000)
sal = emp * ((age-18)*1000+15000+us)
support = pi(age,emp)
return support + sal
get_income(25,pol)
import matplotlib.pyplot as plt
fig,ax = plt.subplots(1,1)
#ages = list(map(int, np.random.uniform(low=18, high=67, size=2000000)))
ages = np.random.randint(18,67,size=1000000)
incomes = [get_income(x,pol) for x in ages]
ax.scatter(ages,incomes)
tall = np.mean(incomes)
tall
t5000 = list(filter(lambda x: x<25, ages))
incomes = [get_income(x,pol) for x in t5000]
np.mean(incomes)
t10000 = list(filter(lambda x: x >= 25 and x < 35, ages))
incomes = [get_income(x,pol,emp=0) for x in t10000]
np.mean(incomes)
t2000 = list(filter(lambda x: x >= 25 and x < 35, ages))
incomes = [get_income(x,pol,emp=1) for x in t2000]
np.mean(incomes)
t0 = list(filter(lambda x: x >= 35, ages))
incomes = [get_income(x,pol) for x in t0]
np.mean(incomes)