Skip to content

Commit

Permalink
Add reweighting into main module
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilwoodruff committed Apr 17, 2024
1 parent 75e12a4 commit b76c3a3
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 606 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ format:

flat-file:
python tax_microdata_benchmarking/create_flat_file.py
python tax_microdata_benchmarking/create_summary_file.py

all: format test
31 changes: 30 additions & 1 deletion tax_microdata_benchmarking/create_flat_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from scipy.optimize import minimize
from tax_microdata_benchmarking.adjust_qbi import add_pt_w2_wages
from tax_microdata_benchmarking.reweight import reweight
from microdf import MicroDataFrame
import numpy as np

UPRATING_VARIABLES = [
"employment_income",
Expand Down Expand Up @@ -780,8 +782,31 @@ def create_stacked_flat_file(
return stacked_file


def summary_analytics(df):
df = MicroDataFrame(df.copy(), weights="s006")

variables = []
sums = []
nonzero_counts = []

for variable in df.columns:
variables.append(variable)
sums.append((df[variable].sum() / 1e9).round(1))
nonzero_counts.append(((df[variable] > 0).sum() / 1e6).round(1))

summary_df = pd.DataFrame(
{
"Variable": variables,
"Sum (bn)": sums,
"Nonzero count (m)": nonzero_counts,
}
)

return summary_df


if __name__ == "__main__":
for target_year in [2021]:
for target_year in [2015, 2021, 2026]:
stacked_file = create_stacked_flat_file(
target_year=target_year, use_puf=True
)
Expand All @@ -790,3 +815,7 @@ def create_stacked_flat_file(
index=False,
compression="gzip",
)
analytics_df = summary_analytics(stacked_file)
analytics_df.to_csv(
f"tax_microdata_{target_year}_analytics.csv", index=False
)
57 changes: 0 additions & 57 deletions tax_microdata_benchmarking/create_summary_file.py

This file was deleted.

Loading

0 comments on commit b76c3a3

Please sign in to comment.