Example #1
0
    def _make_calculators(self):
        """
        This function creates the baseline and reform calculators used when
        the `run()` method is called
        """
        # Create two microsimulation calculators
        gd_base = tc.GrowDiff()
        gf_base = tc.GrowFactors()
        # apply user specified growdiff
        if self.params["growdiff_baseline"]:
            gd_base.update_growdiff(self.params["growdiff_baseline"])
            gd_base.apply_to(gf_base)
        # Baseline calculator
        if self.use_cps:
            records = tc.Records.cps_constructor(data=self.microdata,
                                                 gfactors=gf_base)
        else:
            records = tc.Records(self.microdata, gfactors=gf_base)
        policy = tc.Policy(gf_base)
        if self.params["base_policy"]:
            update_policy(policy, self.params["base_policy"])
        base_calc = tc.Calculator(policy=policy,
                                  records=records,
                                  verbose=self.verbose)

        # Reform calculator
        # Initialize a policy object
        gd_reform = tc.GrowDiff()
        gf_reform = tc.GrowFactors()
        if self.params["growdiff_response"]:
            gd_reform.update_growdiff(self.params["growdiff_response"])
            gd_reform.apply_to(gf_reform)
        if self.use_cps:
            records = tc.Records.cps_constructor(data=self.microdata,
                                                 gfactors=gf_reform)
        else:
            records = tc.Records(self.microdata, gfactors=gf_reform)
        policy = tc.Policy(gf_reform)
        if self.params["base_policy"]:
            update_policy(policy, self.params["base_policy"])
        update_policy(policy, self.params["policy"])

        # Initialize Calculator
        reform_calc = tc.Calculator(policy=policy,
                                    records=records,
                                    verbose=self.verbose)
        # delete all unneeded variables
        del gd_base, gd_reform, records, gf_base, gf_reform, policy
        return base_calc, reform_calc
Example #2
0
    def _make_stacked_objects(self):
        """
        This method makes the base calculator and policy and records objects
        for stacked reforms. The difference between this and the standard
        _make_calcuators method is that this method
        only fully creates the baseline calculator. For the reform, it creates
        policy and records objects and implements any growth assumptions
        provided by the user.
        """
        # Create two microsimulation calculators
        gd_base = tc.GrowDiff()
        gf_base = tc.GrowFactors()
        # apply user specified growdiff
        if self.params["growdiff_baseline"]:
            gd_base.update_growdiff(self.params["growdiff_baseline"])
            gd_base.apply_to(gf_base)
        # Baseline calculator
        if self.use_cps:
            records = tc.Records.cps_constructor(data=self.microdata,
                                                 gfactors=gf_base)
        else:
            records = tc.Records(self.microdata, gfactors=gf_base)
        policy = tc.Policy(gf_base)
        if self.params["base_policy"]:
            update_policy(policy, self.params["base_policy"])
        base_calc = tc.Calculator(policy=policy,
                                  records=records,
                                  verbose=self.verbose)

        # Reform calculator
        # Initialize a policy object
        gd_reform = tc.GrowDiff()
        gf_reform = tc.GrowFactors()
        if self.params["growdiff_response"]:
            gd_reform.update_growdiff(self.params["growdiff_response"])
            gd_reform.apply_to(gf_reform)
        if self.use_cps:
            records = tc.Records.cps_constructor(data=self.microdata,
                                                 gfactors=gf_reform)
        else:
            records = tc.Records(self.microdata, gfactors=gf_reform)
        policy = tc.Policy(gf_reform)
        return base_calc, policy, records
Example #3
0
    def set_rates(self):
        """Initialize taxcalc indexing data."""
        cpi_vals = [vo["value"] for vo in self._data["CPI_offset"]["value"]]
        # extend cpi_offset values through budget window if they
        # have not been extended already.
        cpi_vals = cpi_vals + cpi_vals[-1:] * (2030 - 2013 + 1 - len(cpi_vals))
        cpi_offset = {(2013 + ix): val for ix, val in enumerate(cpi_vals)}

        if not self._gfactors:
            self._gfactors = taxcalc.GrowFactors()

        self._inflation_rates = [
            np.round(rate + cpi_offset[2013 + ix], 4)
            for ix, rate in enumerate(
                self._gfactors.price_inflation_rates(2013, 2030))
        ]

        self._wage_growth_rates = self._gfactors.wage_growth_rates(2013, 2030)
Example #4
0
    def __init__(self,
                 start_year,
                 end_year=LAST_BUDGET_YEAR,
                 microdata=None,
                 use_cps=False,
                 reform=None,
                 behavior=None,
                 assump=None,
                 verbose=False):
        """
        Constructor for the TaxBrain class
        Parameters
        ----------
        start_year: First year in the analysis. Must be no earlier than the
                    first year allowed in Tax-Calculator.
        end_year: Last year in the analysis. Must be no later than the last
                  year allowed in Tax-Calculator.
        microdata: Either a path to a micro-data file or a Pandas DataFrame
                   containing micro-data.
        use_cps: A boolean value to indicate whether or not the analysis should
                 be run using the CPS file included in Tax-Calculator.
                 Note: use_cps cannot be True if a file was also specified with
                 the microdata parameter.
        reform: Individual income tax policy reform. Can be either a string
                pointing to a JSON reform file, or the contents of a JSON file.
        behavior: Individual behavior assumptions use by the Behavior-Response
                  package.
        assump: A string pointing to a JSON file containing user specified
                economic assumptions.
        verbose: A boolean value indicated whether or not to write model
                 progress reports.
        """
        if not use_cps and microdata is None:
            raise ValueError("Must specify microdata or set 'use_cps' to True")
        assert isinstance(start_year, int) & isinstance(end_year, int), (
            "Start and end years must be integers")
        assert start_year <= end_year, (
            f"Specified end year, {end_year}, is before specified start year, "
            f"{start_year}.")
        assert TaxBrain.FIRST_BUDGET_YEAR <= start_year, (
            f"Specified start_year, {start_year}, comes before first known "
            f"budget year, {TaxBrain.FIRST_BUDGET_YEAR}.")
        assert end_year <= TaxBrain.LAST_BUDGET_YEAR, (
            f"Specified end_year, {end_year}, comes after last known "
            f"budget year, {TaxBrain.LAST_BUDGET_YEAR}.")
        self.use_cps = use_cps
        self.start_year = start_year
        self.end_year = end_year
        self.base_data = {yr: {} for yr in range(start_year, end_year + 1)}
        self.reform_data = {yr: {} for yr in range(start_year, end_year + 1)}
        self.verbose = verbose

        # Process user inputs early to throw any errors quickly
        self.params = self._process_user_mods(reform, assump)
        self.params["behavior"] = behavior

        # Create two microsimulation calculators
        gd_base = tc.GrowDiff()
        gf_base = tc.GrowFactors()
        # apply user specified growdiff
        if self.params["growdiff_baseline"]:
            gd_base.update_growdiff(self.params["growdiff_baseline"])
            gd_base.apply_to(gf_base)
        # Baseline calculator
        if use_cps:
            records = tc.Records.cps_constructor(data=microdata,
                                                 gfactors=gf_base)
        else:
            records = tc.Records(microdata, gfactors=gf_base)
        self.base_calc = tc.Calculator(policy=tc.Policy(gf_base),
                                       records=records,
                                       verbose=self.verbose)

        # Reform calculator
        # Initialize a policy object
        gd_reform = tc.GrowDiff()
        gf_reform = tc.GrowFactors()
        if self.params["growdiff_response"]:
            gd_reform.update_growdiff(self.params["growdiff_response"])
            gd_reform.apply_to(gf_reform)
        if use_cps:
            records = tc.Records.cps_constructor(data=microdata,
                                                 gfactors=gf_reform)
        else:
            records = tc.Records(microdata, gfactors=gf_reform)
        policy = tc.Policy(gf_reform)
        policy.implement_reform(self.params['policy'])
        # Initialize Calculator
        self.reform_calc = tc.Calculator(policy=policy,
                                         records=records,
                                         verbose=self.verbose)
# latest official puf per peter:
PUF_NAME = r'C:\Users\donbo\Dropbox (Personal)\PUF files\files_based_on_puf2011\2020-08-20\puf.csv'



# agi stubs
# AGI groups to target separately
IRS_AGI_STUBS = [-9e99, 1.0, 5e3, 10e3, 15e3, 20e3, 25e3, 30e3, 40e3, 50e3,
                 75e3, 100e3, 200e3, 500e3, 1e6, 1.5e6, 2e6, 5e6, 10e6, 9e99]
HT2_AGI_STUBS = [-9e99, 1.0, 10e3, 25e3, 50e3, 75e3, 100e3,
                 200e3, 500e3, 1e6, 9e99]


# %% create objects
gfactor = tc.GrowFactors(GF_NAME)
dir(gfactor)

puf = pd.read_csv(PUF_NAME)

recs = tc.Records(data=puf,
                  start_year=2011,
                  gfactors=gfactor,
                  weights=WEIGHTS_NAME,
                  adjust_ratios=None)  # don't use puf_ratios

# recs = tc.Records(data=mypuf,
#                   start_year=2011,
#                   gfactors=gfactor,
#                   weights=WEIGHTS_NAME)  # apply built-in puf_ratios.csv
Example #6
0
def growth_assumptions(tb):
    """
    Create a table with all of the growth assumptions used in the analysis

    Parameters
    ----------
    tb: TaxBrain object
        instance of TaxBrain object for analysis

    Returns
    -------
    md_tables: str
        table of growth assumptions for report
    """
    growth_vars_map = {
        "ABOOK": "General Business and Foreign Tax Credit Growth Rate",
        "ACGNS": "Capital Gains Growth Rate",
        "ACPIM": "CPI - Medical",
        "ACPIU": "CPI - Urban Consumer",
        "ADIV": "Dividend Income Growth Rate",
        "AINTS": "Interest Income Growth Rate",
        "AIPD": "Interest Paid Deduction Growth Rate",
        "ASCHCI": "Schedule C Income Growth Rate",
        "ASCHCL": "Schedule C Losses Growth Rate",
        "ASCHEI": "Schedule E Income Growth Rate",
        "ASCHEL": "Schedule E Losses Growth Rate",
        "ASCHFI": "Schedule F Income Growth Rate",
        "ASCHFL": "Schedule F Losses Growth Rate",
        "ASOCSEC": "Social Security Benefit Growth Rate",
        "ATXPY": "Personal Income Growth Rate",
        "AUCOMP": "Unemployment Compensation Growth Rate",
        "AWAGE": "Wage Income Growth Rate",
        "ABENOTHER": "Other Benefits Growth Rate",
        "ABENMCARE": "Medicare Benefits Growth Rate",
        "ABENMCAID": "Medicaid Benfits Growth Rate",
        "ABENSSI": "SSI Benefits Growth Rate",
        "ABENSNAP": "SNAP Benefits Growth Rate",
        "ABENWIC": "WIC Benfits Growth Rate",
        "ABENHOUSING": "Housing Benefits Growth Rate",
        "ABENTANF": "TANF Benfits Growth Rates",
        "ABENVET": "Veteran's Benfits Growth Rates"
    }
    if tb.params["growdiff_response"]:
        params = tb.params["growdiff_response"]
        growdiff_years = set()
        growdiff_by_year = defaultdict(lambda: deque())

        # base GrowFactor object to pull default values
        base_gf = tc.GrowFactors()
        # create GrowDiff and GrowFactors for the new assumptions
        reform_gd = tc.GrowDiff()
        reform_gd.update_growdiff(params)
        reform_gf = tc.GrowFactors()
        reform_gd.apply_to(reform_gf)
        # loop through all of the reforms
        for param, meta in params.items():
            # find all years a new value is specified
            years = set(meta.keys())
            growdiff_years = growdiff_years.union(years)
            name = growth_vars_map[param]
            for yr in years:
                # find default and new values
                default_val = base_gf.factor_value(param, yr)
                new_val = reform_gf.factor_value(param, yr)
                growdiff_by_year.append([name, default_val, new_val])

        # create tables
        md_tables = {}
        for yr in growdiff_years:
            content = growdiff_by_year[yr]
            content.appendleft(["", "Default Value", "New Value"])
            md_tables[yr] = convert_table(content)

        return md_tables

    else:
        return {"": "No new growth assumptions specified."}