Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
jdebacker committed Nov 22, 2023
1 parent 944ebae commit 50efedf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
4 changes: 3 additions & 1 deletion iot/generate_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ def gen_microdata(
baseline = tc.Policy.read_json_reform(s)
else:
baseline = s
pol1.implement_reform(baseline, print_warnings=False, raise_errors=False)
pol1.implement_reform(
baseline, print_warnings=False, raise_errors=False
)
else:
pol1 = tc.Policy()

Expand Down
24 changes: 17 additions & 7 deletions iot/inverse_optimal_tax.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ def compute_mtr_dist(
for each income bin
"""
bins = 1000 # number of equal-width bins
data.loc[:, ["z_bin"]] = pd.cut(data[income_measure], bins, include_lowest=True)
data.loc[:, ["z_bin"]] = pd.cut(
data[income_measure], bins, include_lowest=True
)
binned_data = pd.DataFrame(
data[["mtr", income_measure, "z_bin", weight_var]]
.groupby(["z_bin"])
Expand Down Expand Up @@ -189,11 +191,14 @@ def compute_income_dist(
# drop zero income observations
data = data[data[income_measure] > 0]
if dist_type == "log_normal":
mu = (np.log(data[income_measure]) * data[weight_var]).sum() / data[
weight_var
].sum()
mu = (
np.log(data[income_measure]) * data[weight_var]
).sum() / data[weight_var].sum()
sigmasq = (
(((np.log(data[income_measure]) - mu) ** 2) * data[weight_var]).values
(
((np.log(data[income_measure]) - mu) ** 2)
* data[weight_var]
).values
/ data[weight_var].sum()
).sum()
# F = st.lognorm.cdf(z_line, s=(sigmasq) ** 0.5, scale=np.exp(mu))
Expand All @@ -204,7 +209,10 @@ def compute_income_dist(
# analytical derivative of lognormal
sigma = np.sqrt(sigmasq)
F = (1 / 2) * (
1 + scipy.special.erf((np.log(z_line) - mu) / (np.sqrt(2) * sigma))
1
+ scipy.special.erf(
(np.log(z_line) - mu) / (np.sqrt(2) * sigma)
)
)
f = (
(1 / (sigma * np.sqrt(2 * np.pi)))
Expand Down Expand Up @@ -261,7 +269,9 @@ def sw_weights(self):
)
# use Lockwood and Weinzierl formula, which should be equivalent but using numerical differentiation
bracket_term = (
1 - self.F - (self.mtr / (1 - self.mtr)) * self.eti * self.z * self.f
1
- self.F
- (self.mtr / (1 - self.mtr)) * self.eti * self.z * self.f
)
# d_dz_bracket = np.gradient(bracket_term, edge_order=2)
d_dz_bracket = np.diff(bracket_term) / np.diff(self.z)
Expand Down

0 comments on commit 50efedf

Please sign in to comment.