Skip to content

Commit 16aca76

Browse files
jstacclaude
andcommitted
Improve endogenous_lake.md: Split code blocks and add descriptions
Reorganized the endogenous lake model lecture for better readability and comprehension. **Changes:** - Split large monolithic code blocks into 12 smaller, focused blocks - Added descriptive sentences before each code block explaining its purpose - Separated function definitions from their usage and plotting code - Added new subsection "Computing optimal unemployment insurance" **Code block breakdown:** 1. Wage distribution function definition 2. Wage distribution creation and visualization 3. Utility function and McCall model data structure 4. Bellman equation operator 5. Value function iteration solver 6. Lake model functions (from previous lecture) 7. Economy parameters container 8. Function to compute optimal worker quantities 9. Function to compute steady state outcomes 10. Function to find balanced budget tax rate 11. Computation loop across policy range 12. Results visualization Each block now has a clear explanation of what it does and how it fits into the overall analysis, making the lecture more pedagogically effective. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 1861646 commit 16aca76

File tree

1 file changed

+37
-11
lines changed

1 file changed

+37
-11
lines changed

lectures/endogenous_lake.md

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ $$
144144

145145
where the notation $V$ and $U$ is as defined in the {doc}`McCall search model lecture <mccall_model>`.
146146

147-
The wage offer distribution will be a discretized version of the lognormal distribution $LN(\log(20),1)$, as shown in the next figure
147+
The wage offer distribution will be a discretized version of the lognormal distribution $LN(\log(20),1)$.
148+
149+
We first define a function to create a discretized wage distribution:
148150

149151
```{code-cell} ipython3
150152
def create_wage_distribution(max_wage: float,
@@ -159,29 +161,28 @@ def create_wage_distribution(max_wage: float,
159161
p_vec = pdf / pdf.sum()
160162
w_vec = (w_vec_temp[1:] + w_vec_temp[:-1]) / 2
161163
return w_vec, p_vec
164+
```
165+
166+
Let's create a wage distribution and visualize it:
162167

168+
```{code-cell} ipython3
163169
w_vec, p_vec = create_wage_distribution(170, 200, 20)
164170
165-
# Plot the wage distribution
166171
fig, ax = plt.subplots()
167-
168172
ax.plot(w_vec, p_vec)
169173
ax.set_xlabel('wages')
170174
ax.set_ylabel('probability')
171-
172175
plt.tight_layout()
173176
plt.show()
174177
```
175178

176179
### Fiscal policy code
177180

178-
We will make use of techniques from the {doc}`McCall model lecture <mccall_model>`
181+
We will make use of techniques from the {doc}`McCall model lecture <mccall_model>`.
179182

180-
The first piece of code implements value function iteration
183+
First, we define the utility function and the McCall model data structure:
181184

182185
```{code-cell} ipython3
183-
:tags: [output_scroll]
184-
185186
@jax.jit
186187
def u(c, σ=2.0):
187188
return jnp.where(c > 0, (c**(1 - σ) - 1) / (1 - σ), -10e6)
@@ -214,8 +215,11 @@ def create_mccall_model(α=0.2, β=0.98, γ=0.7, c=6.0, σ=2.0,
214215
dist = BetaBinomial(n-1, a, b)
215216
p_vec = jnp.array(dist.pdf())
216217
return McCallModel(α=α, β=β, γ=γ, c=c, σ=σ, w_vec=w_vec, p_vec=p_vec)
218+
```
217219

220+
Next, we implement the Bellman equation operator:
218221

222+
```{code-cell} ipython3
219223
@jax.jit
220224
def bellman(mcm: McCallModel, V, U):
221225
"""
@@ -228,8 +232,11 @@ def bellman(mcm: McCallModel, V, U):
228232
U_new = u(c, σ) + β * (1 - γ) * U + β * γ * (jnp.maximum(U, V) @ p_vec)
229233
230234
return V_new, U_new
235+
```
231236

237+
Now we define the value function iteration solver:
232238

239+
```{code-cell} ipython3
233240
@jax.jit
234241
def solve_mccall_model(mcm: McCallModel, tol=1e-5, max_iter=2000):
235242
"""
@@ -260,7 +267,7 @@ def solve_mccall_model(mcm: McCallModel, tol=1e-5, max_iter=2000):
260267
return V_final, U_final
261268
```
262269

263-
We also need to import the lake model functions from the previous lecture.
270+
We also need the lake model functions from the previous lecture to compute steady state unemployment rates:
264271

265272
```{code-cell} ipython3
266273
class LakeModel(NamedTuple):
@@ -331,8 +338,11 @@ def rate_steady_state(model: LakeModel) -> jnp.ndarray:
331338
return steady_state
332339
```
333340

334-
Now let's compute and plot welfare, employment, unemployment, and tax revenue as a
335-
function of the unemployment compensation rate
341+
### Computing optimal unemployment insurance
342+
343+
Now we set up the infrastructure to compute optimal unemployment insurance levels.
344+
345+
First, we define a container for the economy's parameters:
336346

337347
```{code-cell} ipython3
338348
class EconomyParameters(NamedTuple):
@@ -359,8 +369,11 @@ def create_economy_params(α=0.013, b=0.0124, d=0.00822,
359369
log_wage_mean=log_wage_mean,
360370
wage_grid_size=wage_grid_size,
361371
max_wage=max_wage)
372+
```
362373

374+
Next, we define a function that computes optimal worker behavior given policy parameters:
363375

376+
```{code-cell} ipython3
364377
@jax.jit
365378
def compute_optimal_quantities(c, τ,
366379
params: EconomyParameters, w_vec, p_vec):
@@ -384,8 +397,11 @@ def compute_optimal_quantities(c, τ,
384397
385398
λ = params.γ * jnp.sum(p_vec * (w_vec - τ > w_bar))
386399
return w_bar, λ, V, U
400+
```
387401

402+
This function computes the steady state outcomes given unemployment insurance and tax levels:
388403

404+
```{code-cell} ipython3
389405
@jax.jit
390406
def compute_steady_state_quantities(c, τ,
391407
params: EconomyParameters, w_vec, p_vec):
@@ -407,8 +423,11 @@ def compute_steady_state_quantities(c, τ,
407423
welfare = e * w + u * U
408424
409425
return e, u, welfare
426+
```
410427

428+
We need a function to find the tax rate that balances the government budget:
411429

430+
```{code-cell} ipython3
412431
def find_balanced_budget_tax(c, params: EconomyParameters,
413432
w_vec, p_vec):
414433
"""
@@ -436,8 +455,11 @@ def find_balanced_budget_tax(c, params: EconomyParameters,
436455
t_high = t_mid
437456
438457
return t_mid
458+
```
439459

460+
Now we compute how employment, unemployment, taxes, and welfare vary with the unemployment compensation rate:
440461

462+
```{code-cell} ipython3
441463
# Create economy parameters and wage distribution
442464
params = create_economy_params()
443465
w_vec, p_vec = create_wage_distribution(params.max_wage,
@@ -460,7 +482,11 @@ for c in c_vec:
460482
unempl_vec.append(u_rate)
461483
empl_vec.append(e_rate)
462484
welfare_vec.append(welfare)
485+
```
486+
487+
Let's visualize the results:
463488

489+
```{code-cell} ipython3
464490
fig, axes = plt.subplots(2, 2, figsize=(12, 10))
465491
466492
plots = [unempl_vec, empl_vec, tax_vec, welfare_vec]

0 commit comments

Comments
 (0)