import pandas as pd import taxcalc as tc import microdf as mdf import matplotlib as mpl import matplotlib.pyplot as plt import seaborn as sns Chart options. mdf.set_plot_style() ## Generate data base = mdf.calc_df(group_vars=['expanded_income', 'MARS'], metric_vars=['aftertax_income', 'XTOT']) base.columns Define a reform that treats capital gains as ordinary income and sets the top marginal rate to 70%. CG_REFORM = { 'CG_nodiff': {2019: True}, 'II_rt7': {2019: 0.7} } reform = mdf.calc_df(reform=CG_REFORM, group_vars=['MARS'], group_n65=True, metric_vars=['aftertax_income', 'XTOT']) reform.columns
This example requires `taxcalc` to be installed. ## Setup import numpy as np import pandas as pd import matplotlib.pyplot as plt import microdf as mdf mdf.set_plot_style() ## Prepare data base = mdf.calc_df(group_vars=['expanded_income', 'MARS'], metric_vars=['aftertax_income', 'XTOT']) reform = base.copy(deep=True) UBI_PP = 10000 reform['ubi'] = reform.XTOT * UBI_PP reform['aftertax_income'] = reform.aftertax_income + reform.ubi mdf.add_weighted_metrics(reform, 'aftertax_income') ## Charts ### Change to income percentiles ax = mdf.quantile_chg_plot(base.aftertax_income, reform.aftertax_income, base.XTOT_m, reform.XTOT_m) plt.show()
def test_calc_df(): if not _HAVE_TAXCALC: pytest.skip("taxcalc is not installed") df = mdf.calc_df()
# Income measures ## Setup import numpy as np import pandas as pd import taxcalc as tc import microdf as mdf tc.__version__ ## Load data Start with a `DataFrame` with `expanded_income` and the variables in `expanded_income` excluded from `tpc_eci`. df = mdf.calc_df(group_vars=['expanded_income', 'wic_ben', 'housing_ben', 'vet_ben', 'mcare_ben', 'mcaid_ben'], metric_vars=['XTOT']) Calculate `tpc_eci`. df['tpc_eci'] = mdf.tpc_eci(df) df.head()