{
"cells": [
{
"cell_type": "markdown",
"id": "91ed6180",
"metadata": {},
"source": [
"\n",
""
]
},
{
"cell_type": "markdown",
"id": "11182d09",
"metadata": {},
"source": [
"# Job Search IV: Modeling Career Choice\n",
"\n",
"\n",
""
]
},
{
"cell_type": "markdown",
"id": "0076cf16",
"metadata": {},
"source": [
"## Contents\n",
"\n",
"- [Job Search IV: Modeling Career Choice](#Job-Search-IV:-Modeling-Career-Choice) \n",
" - [Overview](#Overview) \n",
" - [Model](#Model) \n",
" - [Exercises](#Exercises) \n",
" - [Solutions](#Solutions) "
]
},
{
"cell_type": "markdown",
"id": "92ef7a46",
"metadata": {},
"source": [
"## Overview\n",
"\n",
"Next we study a computational problem concerning career and job choices.\n",
"\n",
"The model is originally due to Derek Neal [[Nea99](https://julia.quantecon.org/../zreferences.html#id115)].\n",
"\n",
"This exposition draws on the presentation in [[LS18](https://julia.quantecon.org/../zreferences.html#id101)], section 6.5."
]
},
{
"cell_type": "markdown",
"id": "08a35836",
"metadata": {},
"source": [
"### Model features\n",
"\n",
"- Career and job within career both chosen to maximize expected discounted wage flow. \n",
"- Infinite horizon dynamic programming with two state variables. "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "abd050d7",
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
"using LinearAlgebra, Statistics"
]
},
{
"cell_type": "markdown",
"id": "7565d553",
"metadata": {},
"source": [
"## Model\n",
"\n",
"In what follows we distinguish between a career and a job, where\n",
"\n",
"- a *career* is understood to be a general field encompassing many possible jobs, and \n",
"- a *job* is understood to be a position with a particular firm \n",
"\n",
"\n",
"For workers, wages can be decomposed into the contribution of job and career\n",
"\n",
"- $ w_t = \\theta_t + \\epsilon_t $, where \n",
" - $ \\theta_t $ is contribution of career at time $ t $ \n",
" - $ \\epsilon_t $ is contribution of job at time $ t $ \n",
"\n",
"\n",
"At the start of time $ t $, a worker has the following options\n",
"\n",
"- retain a current (career, job) pair $ (\\theta_t, \\epsilon_t) $\n",
" — referred to hereafter as “stay put” \n",
"- retain a current career $ \\theta_t $ but redraw a job $ \\epsilon_t $\n",
" — referred to hereafter as “new job” \n",
"- redraw both a career $ \\theta_t $ and a job $ \\epsilon_t $\n",
" — referred to hereafter as “new life” \n",
"\n",
"\n",
"Draws of $ \\theta $ and $ \\epsilon $ are independent of each other and\n",
"past values, with\n",
"\n",
"- $ \\theta_t \\sim F $ \n",
"- $ \\epsilon_t \\sim G $ \n",
"\n",
"\n",
"Notice that the worker does not have the option to retain a job but redraw\n",
"a career — starting a new career always requires starting a new job.\n",
"\n",
"A young worker aims to maximize the expected sum of discounted wages.\n",
"\n",
"\n",
"\n",
"$$\n",
"\\mathbb{E} \\sum_{t=0}^{\\infty} \\beta^t w_t \\tag{32.1}\n",
"$$\n",
"\n",
"subject to the choice restrictions specified above.\n",
"\n",
"Let $ V(\\theta, \\epsilon) $ denote the value function, which is the\n",
"maximum of [(32.1)](#equation-exw) over all feasible (career, job) policies, given the\n",
"initial state $ (\\theta, \\epsilon) $.\n",
"\n",
"The value function obeys\n",
"\n",
"$$\n",
"V(\\theta, \\epsilon) = \\max\\{I, II, III\\},\n",
"$$\n",
"\n",
"where\n",
"\n",
"\n",
"\n",
"$$\n",
"\\begin{aligned}\n",
"& I = \\theta + \\epsilon + \\beta V(\\theta, \\epsilon) \\\\\n",
"& II = \\theta + \\int \\epsilon' G(d \\epsilon') + \\beta \\int V(\\theta, \\epsilon') G(d \\epsilon') \\nonumber \\\\\n",
"& III = \\int \\theta' F(d \\theta') + \\int \\epsilon' G(d \\epsilon') + \\beta \\int \\int V(\\theta', \\epsilon') G(d \\epsilon') F(d \\theta') \\nonumber\n",
"\\end{aligned} \\tag{32.2}\n",
"$$\n",
"\n",
"Evidently $ I $, $ II $ and $ III $ correspond to “stay put”, “new job” and “new life”, respectively."
]
},
{
"cell_type": "markdown",
"id": "6544da3d",
"metadata": {},
"source": [
"### Parameterization\n",
"\n",
"As in [[LS18](https://julia.quantecon.org/../zreferences.html#id101)], section 6.5, we will focus on a discrete version of the model, parameterized as follows:\n",
"\n",
"- both $ \\theta $ and $ \\epsilon $ take values in the set `linspace(0, B, N)` — an even grid of $ N $ points between $ 0 $ and $ B $ inclusive \n",
"- $ N = 50 $ \n",
"- $ B = 5 $ \n",
"- $ \\beta = 0.95 $ \n",
"\n",
"\n",
"The distributions $ F $ and $ G $ are discrete distributions\n",
"generating draws from the grid points `linspace(0, B, N)`.\n",
"\n",
"A very useful family of discrete distributions is the Beta-binomial family,\n",
"with probability mass function\n",
"\n",
"$$\n",
"p(k \\,|\\, n, a, b)\n",
"= {n \\choose k} \\frac{B(k + a, n - k + b)}{B(a, b)},\n",
"\\qquad k = 0, \\ldots, n\n",
"$$\n",
"\n",
"Interpretation:\n",
"\n",
"- draw $ q $ from a $ \\beta $ distribution with shape parameters $ (a, b) $ \n",
"- run $ n $ independent binary trials, each with success probability $ q $ \n",
"- $ p(k \\,|\\, n, a, b) $ is the probability of $ k $ successes in these $ n $ trials \n",
"\n",
"\n",
"Nice properties:\n",
"\n",
"- very flexible class of distributions, including uniform, symmetric unimodal, etc. \n",
"- only three parameters \n",
"\n",
"\n",
"Here’s a figure showing the effect of different shape parameters when $ n=50 $.\n",
"\n",
"\n",
""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4295c87e",
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
"using LaTeXStrings, Plots, QuantEcon, Distributions\n",
"\n",
"n = 50\n",
"a_vals = [0.5, 1, 100]\n",
"b_vals = [0.5, 1, 100]\n",
"\n",
"plt = plot()\n",
"for (a, b) in zip(a_vals, b_vals)\n",
" ab_label = L\"$a = %$a, b = %$b$\"\n",
" dist = BetaBinomial(n, a, b)\n",
" plot!(plt, 0:n, pdf.(dist, support(dist)), label = ab_label)\n",
"end\n",
"plt"
]
},
{
"cell_type": "markdown",
"id": "724954ad",
"metadata": {},
"source": [
"Implementation:\n",
"\n",
"The code for solving the DP problem described above is found below:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "902042f8",
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
"function CareerWorkerProblem(; beta = 0.95,\n",
" B = 5.0,\n",
" N = 50,\n",
" F_a = 1.0,\n",
" F_b = 1.0,\n",
" G_a = 1.0,\n",
" G_b = 1.0)\n",
" theta = range(0, B, length = N)\n",
" epsilon = copy(theta)\n",
" dist_F = BetaBinomial(N - 1, F_a, F_b)\n",
" dist_G = BetaBinomial(N - 1, G_a, G_b)\n",
" F_probs = pdf.(dist_F, support(dist_F))\n",
" G_probs = pdf.(dist_G, support(dist_G))\n",
" F_mean = sum(theta .* F_probs)\n",
" G_mean = sum(epsilon .* G_probs)\n",
" return (; beta, N, B, theta, epsilon, F_probs, G_probs, F_mean, G_mean)\n",
"end\n",
"\n",
"function update_bellman!(cp, v, out; ret_policy = false)\n",
"\n",
" # new life. This is a function of the distribution parameters and is\n",
" # always constant. No need to recompute it in the loop\n",
" v3 = (cp.G_mean + cp.F_mean .+ cp.beta .* cp.F_probs' * v * cp.G_probs)[1] # do not need 1 element array\n",
"\n",
" for j in 1:(cp.N)\n",
" for i in 1:(cp.N)\n",
" # stay put\n",
" v1 = cp.theta[i] + cp.epsilon[j] + cp.beta * v[i, j]\n",
"\n",
" # new job\n",
" v2 = (cp.theta[i] .+ cp.G_mean .+ cp.beta .* v[i, :]' * cp.G_probs)[1] # do not need a single element array\n",
"\n",
" if ret_policy\n",
" if v1 > max(v2, v3)\n",
" action = 1\n",
" elseif v2 > max(v1, v3)\n",
" action = 2\n",
" else\n",
" action = 3\n",
" end\n",
" out[i, j] = action\n",
" else\n",
" out[i, j] = max(v1, v2, v3)\n",
" end\n",
" end\n",
" end\n",
"end\n",
"\n",
"function update_bellman(cp, v; ret_policy = false)\n",
" out = similar(v)\n",
" update_bellman!(cp, v, out, ret_policy = ret_policy)\n",
" return out\n",
"end\n",
"\n",
"function get_greedy!(cp, v, out)\n",
" update_bellman!(cp, v, out, ret_policy = true)\n",
"end\n",
"\n",
"function get_greedy(cp, v)\n",
" update_bellman(cp, v, ret_policy = true)\n",
"end"
]
},
{
"cell_type": "markdown",
"id": "3e222728",
"metadata": {},
"source": [
"The code defines\n",
"\n",
"- a named tuple `CareerWorkerProblem` that \n",
" - encapsulates all the details of a particular parameterization \n",
" - implements the Bellman operator $ T $ \n",
"\n",
"\n",
"In this model, $ T $ is defined by $ Tv(\\theta, \\epsilon) = \\max\\{I, II, III\\} $, where\n",
"$ I $, $ II $ and $ III $ are as given in [(32.2)](#equation-eyes), replacing $ V $ with $ v $.\n",
"\n",
"The default probability distributions in `CareerWorkerProblem` correspond to discrete uniform distributions (see [the Beta-binomial figure](#beta-binom)).\n",
"\n",
"In fact all our default settings correspond to the version studied in [[LS18](https://julia.quantecon.org/../zreferences.html#id101)], section 6.5.\n",
"\n",
"Hence we can reproduce figures 6.5.1 and 6.5.2 shown there, which exhibit the\n",
"value function and optimal policy respectively.\n",
"\n",
"Here’s the value function"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f3c3120b",
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
"wp = CareerWorkerProblem()\n",
"v_init = fill(100.0, wp.N, wp.N)\n",
"func(x) = update_bellman(wp, x)\n",
"v = compute_fixed_point(func, v_init, max_iter = 500, verbose = false)\n",
"\n",
"plot(linetype = :surface, wp.theta, wp.epsilon, transpose(v), xlabel = L\"\\theta\",\n",
" ylabel = L\"\\epsilon\",\n",
" seriescolor = :plasma, gridalpha = 1)"
]
},
{
"cell_type": "markdown",
"id": "77cc6eb1",
"metadata": {},
"source": [
"The optimal policy can be represented as follows (see [Exercise 3](#career-ex3) for code).\n",
"\n",
"\n",
"\n",
"![https://julia.quantecon.org/_static/figures/career_solutions_ex3_jl.png](https://julia.quantecon.org/_static/figures/career_solutions_ex3_jl.png)\n",
"\n",
" \n",
"Interpretation:\n",
"\n",
"- If both job and career are poor or mediocre, the worker will experiment with new job and new career. \n",
"- If career is sufficiently good, the worker will hold it and experiment with new jobs until a sufficiently good one is found. \n",
"- If both job and career are good, the worker will stay put. \n",
"\n",
"\n",
"Notice that the worker will always hold on to a sufficiently good career, but not necessarily hold on to even the best paying job.\n",
"\n",
"The reason is that high lifetime wages require both variables to be large, and\n",
"the worker cannot change careers without changing jobs.\n",
"\n",
"- Sometimes a good job must be sacrificed in order to change to a better career. "
]
},
{
"cell_type": "markdown",
"id": "f564c52f",
"metadata": {},
"source": [
"## Exercises\n",
"\n",
"\n",
""
]
},
{
"cell_type": "markdown",
"id": "9a44126e",
"metadata": {},
"source": [
"### Exercise 1\n",
"\n",
"Using the default parameterization in the `CareerWorkerProblem`,\n",
"generate and plot typical sample paths for $ \\theta $ and $ \\epsilon $\n",
"when the worker follows the optimal policy.\n",
"\n",
"In particular, modulo randomness, reproduce the following figure (where the horizontal axis represents time)\n",
"\n",
"![https://julia.quantecon.org/_static/figures/career_solutions_ex1_jl.png](https://julia.quantecon.org/_static/figures/career_solutions_ex1_jl.png)\n",
"\n",
" \n",
"Hint: To generate the draws from the distributions $ F $ and $ G $, use the type [DiscreteRV](https://github.com/QuantEcon/QuantEcon.jl/blob/master/src/discrete_rv.jl).\n",
"\n",
"\n",
""
]
},
{
"cell_type": "markdown",
"id": "1ffc3edb",
"metadata": {},
"source": [
"### Exercise 2\n",
"\n",
"Let’s now consider how long it takes for the worker to settle down to a\n",
"permanent job, given a starting point of $ (\\theta, \\epsilon) = (0, 0) $.\n",
"\n",
"In other words, we want to study the distribution of the random variable\n",
"\n",
"$$\n",
"T^* := \\text{the first point in time from which the worker's job no longer changes}\n",
"$$\n",
"\n",
"Evidently, the worker’s job becomes permanent if and only if $ (\\theta_t, \\epsilon_t) $ enters the\n",
"“stay put” region of $ (\\theta, \\epsilon) $ space.\n",
"\n",
"Letting $ S $ denote this region, $ T^* $ can be expressed as the\n",
"first passage time to $ S $ under the optimal policy:\n",
"\n",
"$$\n",
"T^* := \\inf\\{t \\geq 0 \\,|\\, (\\theta_t, \\epsilon_t) \\in S\\}\n",
"$$\n",
"\n",
"Collect 25,000 draws of this random variable and compute the median (which should be about 7).\n",
"\n",
"Repeat the exercise with $ \\beta=0.99 $ and interpret the change.\n",
"\n",
"\n",
""
]
},
{
"cell_type": "markdown",
"id": "e2cee8e3",
"metadata": {},
"source": [
"### Exercise 3\n",
"\n",
"As best you can, reproduce [the figure showing the optimal policy](#career-opt-pol).\n",
"\n",
"Hint: The `get_greedy()` method returns a representation of the optimal\n",
"policy where values 1, 2 and 3 correspond to “stay put”, “new job” and “new life” respectively. Use this and the plots functions (e.g., `contour, contour!`) to produce the different shadings.\n",
"\n",
"Now set `G_a = G_b = 100` and generate a new figure with these parameters. Interpret."
]
},
{
"cell_type": "markdown",
"id": "f52d66a8",
"metadata": {},
"source": [
"## Solutions"
]
},
{
"cell_type": "markdown",
"id": "0101deca",
"metadata": {},
"source": [
"### Exercise 1"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5e86fe46",
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
"wp = CareerWorkerProblem()\n",
"\n",
"function solve_wp(wp)\n",
" v_init = fill(100.0, wp.N, wp.N)\n",
" func(x) = update_bellman(wp, x)\n",
" v = compute_fixed_point(func, v_init, max_iter = 500, verbose = false)\n",
" optimal_policy = get_greedy(wp, v)\n",
" return v, optimal_policy\n",
"end\n",
"\n",
"v, optimal_policy = solve_wp(wp)\n",
"\n",
"F = DiscreteRV(wp.F_probs)\n",
"G = DiscreteRV(wp.G_probs)\n",
"\n",
"function gen_path(T = 20)\n",
" i = j = 1\n",
" theta_ind = Int[]\n",
" epsilon_ind = Int[]\n",
"\n",
" for t in 1:T\n",
" # do nothing if stay put\n",
" if optimal_policy[i, j] == 2 # new job\n",
" j = rand(G)[1]\n",
" elseif optimal_policy[i, j] == 3 # new life\n",
" i, j = rand(F)[1], rand(G)[1]\n",
" end\n",
" push!(theta_ind, i)\n",
" push!(epsilon_ind, j)\n",
" end\n",
" return wp.theta[theta_ind], wp.epsilon[epsilon_ind]\n",
"end\n",
"\n",
"plot_array = Any[]\n",
"for i in 1:2\n",
" theta_path, epsilon_path = gen_path()\n",
" plt = plot(epsilon_path, label = L\"\\epsilon\")\n",
" plot!(plt, theta_path, label = L\"\\theta\")\n",
" plot!(plt, legend = :bottomright)\n",
" push!(plot_array, plt)\n",
"end\n",
"plot(plot_array..., layout = (2, 1))"
]
},
{
"cell_type": "markdown",
"id": "92ea6883",
"metadata": {},
"source": [
"### Exercise 2\n",
"\n",
"The median for the original parameterization can be computed as follows"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "41e4f362",
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
"function gen_first_passage_time(optimal_policy)\n",
" t = 0\n",
" i = j = 1\n",
" while true\n",
" if optimal_policy[i, j] == 1 # Stay put\n",
" return t\n",
" elseif optimal_policy[i, j] == 2 # New job\n",
" j = rand(G)[1]\n",
" else # New life\n",
" i, j = rand(F)[1], rand(G)[1]\n",
" end\n",
" t += 1\n",
" end\n",
"end\n",
"\n",
"M = 25000\n",
"samples = zeros(M)\n",
"for i in 1:M\n",
" samples[i] = gen_first_passage_time(optimal_policy)\n",
"end\n",
"print(median(samples))"
]
},
{
"cell_type": "markdown",
"id": "d4220aba",
"metadata": {},
"source": [
"To compute the median with $ \\beta=0.99 $ instead of the default value $ \\beta=0.95 $, replace `wp=CareerWorkerProblem()` with `wp=CareerWorkerProblem(beta=0.99)`.\n",
"\n",
"The medians are subject to randomness, but should be about 7 and 14 respectively. Not surprisingly, more patient workers will wait longer to settle down to their final job."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5f27967c",
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
"wp2 = CareerWorkerProblem(beta = 0.99)\n",
"\n",
"v2, optimal_policy2 = solve_wp(wp2)\n",
"\n",
"samples2 = zeros(M)\n",
"for i in 1:M\n",
" samples2[i] = gen_first_passage_time(optimal_policy2)\n",
"end\n",
"print(median(samples2))"
]
},
{
"cell_type": "markdown",
"id": "04c2b0c4",
"metadata": {},
"source": [
"### Exercise 3\n",
"\n",
"Here’s the code to reproduce the original figure"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bf1fa53a",
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
"wp = CareerWorkerProblem();\n",
"v, optimal_policy = solve_wp(wp)\n",
"\n",
"lvls = [0.5, 1.5, 2.5, 3.5]\n",
"x_grid = range(0, 5, length = 50)\n",
"y_grid = range(0, 5, length = 50)\n",
"\n",
"contour(x_grid, y_grid, optimal_policy', fill = true, levels = lvls, color = :Blues,\n",
" fillalpha = 1, cbar = false)\n",
"contour!(xlabel = L\"\\theta\", ylabel = L\"\\epsilon\")\n",
"annotate!([(1.8, 2.5, text(\"new life\", 14, :white, :center))])\n",
"annotate!([(4.5, 2.5, text(\"new job\", 14, :center))])\n",
"annotate!([(4.0, 4.5, text(\"stay put\", 14, :center))])"
]
},
{
"cell_type": "markdown",
"id": "ee295c2a",
"metadata": {},
"source": [
"Now, we need only swap out for the new parameters"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "df3d8897",
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
"wp = CareerWorkerProblem(G_a = 100.0, G_b = 100.0); # use new params\n",
"v, optimal_policy = solve_wp(wp)\n",
"\n",
"lvls = [0.5, 1.5, 2.5, 3.5]\n",
"x_grid = range(0, 5, length = 50)\n",
"y_grid = range(0, 5, length = 50)\n",
"\n",
"contour(x_grid, y_grid, optimal_policy', fill = true, levels = lvls, color = :Blues,\n",
" fillalpha = 1, cbar = false)\n",
"contour!(xlabel = L\"\\theta\", ylabel = L\"\\epsilon\")\n",
"annotate!([(1.8, 2.5, text(\"new life\", 14, :white, :center))])\n",
"annotate!([(4.5, 2.5, text(\"new job\", 14, :center))])\n",
"annotate!([(4.0, 4.5, text(\"stay put\", 14, :center))])"
]
},
{
"cell_type": "markdown",
"id": "1bbcff73",
"metadata": {},
"source": [
"You will see that the region for which the worker\n",
"will stay put has grown because the distribution for $ \\epsilon $\n",
"has become more concentrated around the mean, making high-paying jobs\n",
"less realistic."
]
}
],
"metadata": {
"date": 1704478550.36261,
"filename": "career.md",
"kernelspec": {
"display_name": "Julia",
"language": "julia",
"name": "julia-1.10"
},
"title": "Job Search IV: Modeling Career Choice"
},
"nbformat": 4,
"nbformat_minor": 5
}