<jupyter_start><jupyter_text>Keane and Wolpin (1997)*Note that most of the code cells are hidden from this notebook for a better reading flow. Check out the notebook in the documentation folder in the Github repository for more details.*In the following, we will replicate the base and extended model from Keane and Wolpin (1997) and present occupational choice of agents from the age of sixteen to 65.<jupyter_code>%matplotlib agg
%load_ext nb_black

import respy as rp
import pandas as pd
import matplotlib.pyplot as plt
plt.style.use("../_static/respy.mplstyle")
params, options = rp.get_example_model("kw_97_basic", with_data=False)

simulate = rp.get_simulate_func(params, options)
df = simulate(params)
fig, ax = plt.subplots()

shares = (
    df.groupby("Period")
    .Choice.value_counts(normalize=True)
    .unstack()[["home", "school", "white_collar", "blue_collar", "military"]]
)

shares.plot.bar(stacked=True, ax=ax, width=0.8)

ax.legend(
    labels=["Home", "School", "White-Collar", "Blue-Collar", "Military"],
    loc="upper center",
    bbox_to_anchor=(0.5, -0.15),
    ncol=3,
)

ax.set_ylim(0, 1)

ax.set_xticks(range(0, options["n_periods"], 5))
ax.set_xticklabels(range(0, options["n_periods"], 5), rotation="horizontal")

ax.set_ylabel("Share of population")
fig
params, options = rp.get_example_model("kw_97_extended", with_data=False)

simulate = rp.get_simulate_func(params, options)
df = simulate(params)
fig, ax = plt.subplots()

shares = (
    df.groupby("Period")
    .Choice.value_counts(normalize=True)
    .unstack()[["home", "school", "white_collar", "blue_collar", "military"]]
)

shares.plot.bar(stacked=True, ax=ax, width=0.8)

ax.legend(
    labels=["Home", "School", "White-Collar", "Blue-Collar", "Military"],
    loc="upper center",
    bbox_to_anchor=(0.5, -0.15),
    ncol=3,
)

ax.set_ylim(0, 1)

ax.set_xticks(range(0, options["n_periods"], 5))
ax.set_xticklabels(range(0, options["n_periods"], 5), rotation="horizontal")

ax.set_ylabel("Share of population")
fig<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1521099116781158, 'fraction_numerical': 0.020608439646712464, 'mean_word_length': 5.556270096463023, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '466747', 'license': 'MIT', 'n_tokens_mistral': 777, 'n_tokens_neox': 743, 'n_words': 173, 'path': 'docs/replications/keane-and-wolpin-1997.ipynb', 'repo_name': 'structRobustness/respy', 'size': '2038'}