Skip to content

Commit deb99b1

Browse files
jstacclaude
andcommitted
Update mccall_model_with_separation: Change utility parameter from sigma to gamma and use glue for figures
Updated the McCall model with separation lecture with the following changes: Key changes: - Changed utility function parameter from σ (sigma) to γ (gamma) - Moved γ default value from utility function to Model class (γ: float = 2.0) - Updated all functions (compute_v_e, update_h, solve_model) to pass γ parameter - Simplified model unpacking to use tuple unpacking directly (e.g., α, β, γ, c, w, q = model) - Replaced static PNG figures with myst-nb glue functionality - Added glue import and glue() calls in exercise solutions - Converted {figure} directives to {glue:figure} directives for dynamic figure generation Benefits: - More consistent parameter naming (gamma is standard for CRRA utility) - Better code organization with parameter defaults in Model class - Cleaner unpacking syntax - Dynamic figure generation eliminates need for static PNG files - Figures automatically stay in sync with code 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 2ad5d43 commit deb99b1

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

lectures/mccall_model_with_separation.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import jax
6262
import jax.numpy as jnp
6363
from typing import NamedTuple
6464
from quantecon.distributions import BetaBinomial
65+
from myst_nb import glue
6566
```
6667

6768
## The Model
@@ -347,8 +348,8 @@ This helps to tidy up the code and provides an object that's easy to pass to fun
347348
The default utility function is a CRRA utility function
348349

349350
```{code-cell} ipython3
350-
def u(c, σ=2.0):
351-
return (c**(1 - σ) - 1) / (1 - σ)
351+
def u(c, γ):
352+
return (c**(1 - γ) - 1) / (1 - γ)
352353
```
353354

354355
Also, here's a default wage distribution, based around the BetaBinomial
@@ -368,6 +369,7 @@ Here's our model class for the McCall model with separation.
368369
class Model(NamedTuple):
369370
α: float = 0.2 # job separation rate
370371
β: float = 0.98 # discount factor
372+
γ: float = 2.0 # utility parameter (CRRA)
371373
c: float = 6.0 # unemployment compensation
372374
w: jnp.ndarray = w_default # wage outcome space
373375
q: jnp.ndarray = q_default # probabilities over wage offers
@@ -382,18 +384,18 @@ First, we define a function to compute $v_e$ from $h$:
382384
```{code-cell} ipython3
383385
def compute_v_e(model, h):
384386
" Compute v_e from h using the closed-form expression. "
385-
α, β, c, w = model.α, model.β, model.c, model.w
386-
return (u(w) + α * (h - u(c))) / (1 - β * (1 - α))
387+
α, β, γ, c, w, q = model
388+
return (u(w, γ) + α * (h - u(c, γ))) / (1 - β * (1 - α))
387389
```
388390

389391
Now we implement the iteration on $h$ only:
390392

391393
```{code-cell} ipython3
392394
def update_h(model, h):
393395
" One update of the scalar h. "
394-
α, β, c, w, q = model.α, model.β, model.c, model.w, model.q
396+
α, β, γ, c, w, q = model
395397
v_e = compute_v_e(model, h)
396-
h_new = u(c) + β * (jnp.maximum(v_e, h) @ q)
398+
h_new = u(c, γ) + β * (jnp.maximum(v_e, h) @ q)
397399
return h_new
398400
```
399401

@@ -414,8 +416,8 @@ def solve_model(model, tol=1e-5, max_iter=2000):
414416
error_new = jnp.abs(h_new - h)
415417
return h_new, i + 1, error_new
416418
417-
# Initialize
418-
h_init = u(model.c) / (1 - model.β)
419+
# Initialize
420+
h_init = u(model.c, model.γ) / (1 - model.β)
419421
i_init = 0
420422
error_init = tol + 1
421423
init_state = (h_init, i_init, error_init)
@@ -494,7 +496,8 @@ First, let's look at how $\bar w$ varies with unemployment compensation.
494496
In the figure below, we use the default parameters in the `Model` class, apart from
495497
c (which takes the values given on the horizontal axis)
496498

497-
```{figure} /_static/lecture_specific/mccall_model_with_separation/mccall_resw_c.png
499+
```{glue:figure} mccall_resw_c
500+
:figwidth: 600px
498501
499502
```
500503

@@ -509,7 +512,8 @@ Next, let's investigate how $\bar w$ varies with the discount factor.
509512
The next figure plots the reservation wage associated with different values of
510513
$\beta$
511514

512-
```{figure} /_static/lecture_specific/mccall_model_with_separation/mccall_resw_beta.png
515+
```{glue:figure} mccall_resw_beta
516+
:figwidth: 600px
513517
514518
```
515519

@@ -521,7 +525,8 @@ Finally, let's look at how $\bar w$ varies with the job separation rate $\alpha$
521525

522526
Higher $\alpha$ translates to a greater chance that a worker will face termination in each period once employed.
523527

524-
```{figure} /_static/lecture_specific/mccall_model_with_separation/mccall_resw_alpha.png
528+
```{glue:figure} mccall_resw_alpha
529+
:figwidth: 600px
525530
526531
```
527532

@@ -569,6 +574,7 @@ fig, ax = plt.subplots()
569574
ax.set(xlabel='unemployment compensation', ylabel='reservation wage')
570575
ax.plot(c_vals, w_bar_vals, label=r'$\bar w$ as a function of $c$')
571576
ax.legend()
577+
glue("mccall_resw_c", fig, display=False)
572578
plt.show()
573579
```
574580

@@ -586,6 +592,7 @@ fig, ax = plt.subplots()
586592
ax.set(xlabel='discount factor', ylabel='reservation wage')
587593
ax.plot(β_vals, w_bar_vals, label=r'$\bar w$ as a function of $\beta$')
588594
ax.legend()
595+
glue("mccall_resw_beta", fig, display=False)
589596
plt.show()
590597
```
591598

@@ -603,6 +610,7 @@ fig, ax = plt.subplots()
603610
ax.set(xlabel='separation rate', ylabel='reservation wage')
604611
ax.plot(α_vals, w_bar_vals, label=r'$\bar w$ as a function of $\alpha$')
605612
ax.legend()
613+
glue("mccall_resw_alpha", fig, display=False)
606614
plt.show()
607615
```
608616

0 commit comments

Comments
 (0)