def analyze(self, writing_output_file=False, output_tables=False, output_graphs=False, dump_varset=None, output_dump=False, output_sqldb=False): """ Conduct tax analysis. Parameters ---------- writing_output_file: boolean whether or not to generate and write output file output_tables: boolean whether or not to generate and write distributional tables to a text file output_graphs: boolean whether or not to generate and write HTML graphs of average and marginal tax rates by income percentile dump_varset: set custom set of variables to include in dump and sqldb output; None implies include all variables in dump and sqldb output output_dump: boolean whether or not to replace standard output with all input and calculated variables using their Tax-Calculator names output_sqldb: boolean whether or not to write SQLite3 database with dump table containing same output as written by output_dump to a csv file Returns ------- Nothing """ # pylint: disable=too-many-arguments,too-many-branches,too-many-locals if self.puf_input_data and self.calc.reform_warnings: warn = 'PARAMETER VALUE WARNING(S): {}\n{}{}' # pragma: no cover print( # pragma: no cover warn.format('(read documentation for each parameter)', self.calc.reform_warnings, 'CONTINUING WITH CALCULATIONS...') ) calc_base_calculated = False if self.behavior_has_any_response: self.calc = Behavior.response(self.calc_base, self.calc) calc_base_calculated = True else: self.calc.calc_all() if output_dump or output_sqldb: # might need marginal tax rates (mtr_paytax, mtr_inctax, _) = self.calc.mtr(wrt_full_compensation=False, calc_all_already_called=True) else: # definitely do not need marginal tax rates mtr_paytax = None mtr_inctax = None # extract output if writing_output_file if writing_output_file: self.write_output_file(output_dump, dump_varset, mtr_paytax, mtr_inctax) self.write_doc_file() # optionally write --sqldb output to SQLite3 database if output_sqldb: self.write_sqldb_file(dump_varset, mtr_paytax, mtr_inctax) # optionally write --tables output to text file if output_tables: if not calc_base_calculated: self.calc_base.calc_all() calc_base_calculated = True self.write_tables_file() # optionally write --graphs output to HTML files if output_graphs: if not calc_base_calculated: self.calc_base.calc_all() calc_base_calculated = True self.write_graph_files()
def analyze(self, writing_output_file=False, output_tables=False, output_graphs=False, output_ceeu=False, dump_varset=None, output_dump=False, output_sqldb=False): """ Conduct tax analysis. Parameters ---------- writing_output_file: boolean whether or not to generate and write output file output_tables: boolean whether or not to generate and write distributional tables to a text file output_graphs: boolean whether or not to generate and write HTML graphs of average and marginal tax rates by income percentile output_ceeu: boolean whether or not to calculate and write to stdout standard certainty-equivalent expected-utility statistics dump_varset: set custom set of variables to include in dump and sqldb output; None implies include all variables in dump and sqldb output output_dump: boolean whether or not to replace standard output with all input and calculated variables using their Tax-Calculator names output_sqldb: boolean whether or not to write SQLite3 database with dump table containing same output as written by output_dump to a csv file Returns ------- Nothing """ # pylint: disable=too-many-arguments,too-many-branches # in order to use print(), pylint: disable=superfluous-parens if self.calc.policy.reform_warnings: warn = 'PARAMETER VALUE WARNING(S): {}\n{}{}' print( warn.format('(read documentation for each parameter)', self.calc.policy.reform_warnings, 'CONTINUING WITH CALCULATIONS...')) calc_clp_calculated = False if output_dump or output_sqldb: # might need marginal tax rates (mtr_paytax, mtr_inctax, _) = self.calc.mtr(wrt_full_compensation=False) else: # definitely do not need marginal tax rates mtr_paytax = None mtr_inctax = None if self.behavior_has_any_response: self.calc = Behavior.response(self.calc_clp, self.calc) calc_clp_calculated = True else: self.calc.calc_all() # optionally conduct normative welfare analysis if output_ceeu: if self.behavior_has_any_response: ceeu_results = 'SKIP --ceeu output because baseline and ' ceeu_results += 'reform cannot be sensibly compared\n ' ceeu_results += ' ' ceeu_results += 'when specifying "behavior" with --assump ' ceeu_results += 'option' elif self.calc.total_weight() <= 0.: ceeu_results = 'SKIP --ceeu output because ' ceeu_results += 'sum of weights is not positive' else: self.calc_clp.calc_all() calc_clp_calculated = True cedict = self.calc_clp.ce_aftertax_income( self.calc, custom_params=None, require_no_agg_tax_change=False) ceeu_results = TaxCalcIO.ceeu_output(cedict) else: ceeu_results = None # extract output if writing_output_file if writing_output_file: self.write_output_file(output_dump, dump_varset, mtr_paytax, mtr_inctax) self.write_doc_file() # optionally write --sqldb output to SQLite3 database if output_sqldb: self.write_sqldb_file(dump_varset, mtr_paytax, mtr_inctax) # optionally write --tables output to text file if output_tables: if not calc_clp_calculated: self.calc_clp.calc_all() calc_clp_calculated = True self.write_tables_file() # optionally write --graphs output to HTML files if output_graphs: if not calc_clp_calculated: self.calc_clp.calc_all() calc_clp_calculated = True self.write_graph_files() # optionally write --ceeu output to stdout if ceeu_results: print(ceeu_results)
def analyze(self, writing_output_file=False, output_tables=False, output_graphs=False, output_ceeu=False, output_dump=False, output_sqldb=False): """ Conduct tax analysis. Parameters ---------- writing_output_file: boolean whether or not to generate and write output file output_tables: boolean whether or not to generate and write distributional tables to a text file output_graphs: boolean whether or not to generate and write HTML graphs of average and marginal tax rates by income percentile output_ceeu: boolean whether or not to calculate and write to stdout standard certainty-equivalent expected-utility statistics output_dump: boolean whether or not to replace standard output with all input and calculated variables using their Tax-Calculator names output_sqldb: boolean whether or not to write SQLite3 database with dump table containing same output as written by output_dump to a csv file Returns ------- Nothing """ # pylint: disable=too-many-arguments,too-many-branches calc_clp_calculated = False if output_dump or output_sqldb: (mtr_paytax, mtr_inctax, _) = self.calc.mtr(wrt_full_compensation=False) else: # do not need marginal tax rates mtr_paytax = None mtr_inctax = None if self.behavior_has_any_response: self.calc = Behavior.response(self.calc_clp, self.calc) calc_clp_calculated = True else: self.calc.calc_all() # optionally conduct normative welfare analysis if output_ceeu: if self.behavior_has_any_response: ceeu_results = 'SKIP --ceeu output because baseline and ' ceeu_results += 'reform cannot be sensibly compared\n ' ceeu_results += ' ' ceeu_results += 'when specifying "behavior" with --assump ' ceeu_results += 'option' elif self.calc.records.s006.sum() <= 0.: ceeu_results = 'SKIP --ceeu output because ' ceeu_results += 'sum of weights is not positive' else: self.calc_clp.calc_all() calc_clp_calculated = True cedict = ce_aftertax_income(self.calc_clp, self.calc, require_no_agg_tax_change=False) ceeu_results = TaxCalcIO.ceeu_output(cedict) else: ceeu_results = None # extract output if writing_output_file if writing_output_file: self.write_output_file(output_dump, mtr_paytax, mtr_inctax) # optionally write --sqldb output to SQLite3 database if output_sqldb: self.write_sqldb_file(mtr_paytax, mtr_inctax) # optionally write --tables output to text file if output_tables: if not calc_clp_calculated: self.calc_clp.calc_all() calc_clp_calculated = True self.write_tables_file() # optionally write --graphs output to HTML files if output_graphs: if not calc_clp_calculated: self.calc_clp.calc_all() calc_clp_calculated = True self.write_graph_files() # optionally write --ceeu output to stdout if ceeu_results: print(ceeu_results) # pylint: disable=superfluous-parens