Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
jdebacker committed Nov 21, 2023
1 parent 3f4a627 commit 944ebae
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
4 changes: 1 addition & 3 deletions iot/generate_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ 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: 7 additions & 17 deletions iot/inverse_optimal_tax.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ 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 @@ -191,14 +189,11 @@ 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 @@ -209,10 +204,7 @@ 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 @@ -269,9 +261,7 @@ 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 944ebae

Please sign in to comment.