-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a71425
commit 7d4f061
Showing
5 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
**/*.h5 | ||
**/*.pyc | ||
**/*.csv.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,6 @@ test: | |
|
||
format: | ||
black . -l 79 | ||
|
||
flat_file: | ||
python initial_flat_file/create_flat_file.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,57 @@ | ||
# This file should create tax_microdata.csv.gz in the root of the repo. | ||
|
||
import taxcalc as tc | ||
from policyengine_us import Microsimulation | ||
from policyengine_us.model_api import * | ||
import numpy as np | ||
import pandas as pd | ||
|
||
|
||
class TaxCalcVariableAlias(Variable): | ||
label = "TaxCalc Variable Alias" | ||
definition_period = YEAR | ||
entity = TaxUnit | ||
value_type = float | ||
|
||
|
||
class tc_RECID(TaxCalcVariableAlias): | ||
def formula(tax_unit, period, parameters): | ||
return tax_unit("tax_unit_id", period) | ||
|
||
|
||
class tc_MARS(TaxCalcVariableAlias): | ||
def formula(tax_unit, period, parameters): | ||
filing_status = tax_unit("filing_status", period).decode_to_str() | ||
CODE_MAP = { | ||
"SINGLE": 1, | ||
"JOINT": 2, | ||
"SEPARATE": 3, | ||
"HEAD_OF_HOUSEHOLD": 4, | ||
"WIDOW": 5, | ||
} | ||
return pd.Series(filing_status).map(CODE_MAP) | ||
|
||
|
||
class taxcalc_extension(Reform): | ||
def apply(self): | ||
self.add_variables( | ||
tc_RECID, | ||
tc_MARS, | ||
) | ||
|
||
|
||
def create_flat_file(): | ||
sim = Microsimulation( | ||
reform=taxcalc_extension, dataset="enhanced_cps_2023" | ||
) | ||
df = pd.DataFrame() | ||
|
||
for variable in sim.tax_benefit_system.variables: | ||
if variable.startswith("tc_"): | ||
df[variable[3:]] = sim.calculate(variable) | ||
|
||
df.to_csv("tax_microdata.csv.gz", index=False, compression="gzip") | ||
|
||
|
||
if __name__ == "__main__": | ||
create_flat_file() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ policyengine_us | |
taxcalc | ||
pytest | ||
black | ||
paramtools |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters