Skip to content

Commit

Permalink
final mods
Browse files Browse the repository at this point in the history
  • Loading branch information
alanlujan91 committed Jun 10, 2024
1 parent 4aedb8f commit 8028033
Show file tree
Hide file tree
Showing 20 changed files with 8,618 additions and 61,398 deletions.
33 changes: 24 additions & 9 deletions code/estimark/estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ def weighted_median(values, weights):
return stats.quantile(0.5, return_pandas=False)


def winsored_mean(values, weights, limits):
stats = DescrStatsW(values, weights=weights)
qs = stats.quantile(limits, return_pandas=False)

# discard values outside qs
mask = (values >= qs[0]) & (values <= qs[1])
return np.average(values[mask], weights=weights[mask])


def get_weighted_moments(
data,
variable=None,
Expand Down Expand Up @@ -238,6 +247,10 @@ def simulate_moments(params, agent=None, emp_moments=None):
agent.PermShkStd = init_subjective_labor["PermShkStd"]
agent.update_income_process()

agent.LivPrb = init_calibration["LivPrb"]

agent.update()

# Solve the model for these parameters, then simulate wealth data
agent.solve() # Solve the microeconomic model

Expand All @@ -255,6 +268,8 @@ def simulate_moments(params, agent=None, emp_moments=None):

agent.LivPrb = [1.0] * agent.T_cycle

agent.update()

max_sim_age = agent.T_cycle + 1
# Initialize the simulation by clearing histories, resetting initial values
agent.initialize_sim()
Expand Down Expand Up @@ -284,19 +299,19 @@ def simulate_moments(params, agent=None, emp_moments=None):


def calculate_weights(emp_moments):
max_w_stat = 1.0 # maximum value of wealth statistic
n_port_stats = 0 # number of portfolio statistics
for k, v in emp_moments.items():
if "_port" not in k:
max_w_stat = max(max_w_stat, v)
else:
n_port_stats += 1
n_port_stats = sum(1 for k in emp_moments if "_port" in k)
max_w_stat = max(emp_moments.values())

port_fac = (
(len(emp_moments) - n_port_stats) / n_port_stats if n_port_stats != 0 else 1.0
)

port_fac = len(emp_moments) / n_port_stats if n_port_stats != 0 else 1.0
port_fac = 1.0

# Using dictionary comprehension to create weights
weights = {
k: (1 / max_w_stat if "_port" not in k else port_fac) for k in emp_moments
k: (1 / max_w_stat if "_port" not in k else port_fac)
for k, v in emp_moments.items()
}

return weights
Expand Down
4 changes: 2 additions & 2 deletions code/estimark/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
init_WealthShift = 0.0 # Initial guess of the wealth shift parameter
bounds_WealthShift = [0.0, 100.0] # Bounds for the wealth shift parameter

init_BeqFac = 20.0 # Initial guess of the bequest factor
bounds_BeqFac = [20.0, 70.0] # Bounds for the bequest factor
init_BeqFac = 1.0 # Initial guess of the bequest factor
bounds_BeqFac = [0.0, 70.0] # Bounds for the bequest factor

init_BeqShift = 1.0 # Initial guess of the bequest shift parameter
bounds_BeqShift = [0.0, 70.0] # Bounds for the bequest shift parameter
Expand Down
2 changes: 1 addition & 1 deletion code/notebooks/IndShock.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
"version": "3.12.3"
}
},
"nbformat": 4,
Expand Down
330 changes: 330 additions & 0 deletions code/notebooks/Model_Comparisons.ipynb

Large diffs are not rendered by default.

43 changes: 22 additions & 21 deletions code/notebooks/Portfolio.ipynb

Large diffs are not rendered by default.

204 changes: 75 additions & 129 deletions code/notebooks/SCF_notebook.ipynb

Large diffs are not rendered by default.

38 changes: 5 additions & 33 deletions code/notebooks/WarmGlowPortfolio.ipynb

Large diffs are not rendered by default.

45 changes: 25 additions & 20 deletions code/notebooks/WealthPortfolio.ipynb

Large diffs are not rendered by default.

Binary file added code/notebooks/median_share.pdf
Binary file not shown.
Loading

0 comments on commit 8028033

Please sign in to comment.