diff --git a/lectures/_static/quant-econ.bib b/lectures/_static/quant-econ.bib
index aa6536d31..68f0414b9 100644
--- a/lectures/_static/quant-econ.bib
+++ b/lectures/_static/quant-econ.bib
@@ -5445,3 +5445,130 @@ @article{Geweke1982
pages = {304--313},
year = {1982}
}
+
+@article{Blackwell1965,
+ author = {Blackwell, David},
+ title = {Discounted Dynamic Programming},
+ journal = {Annals of Mathematical Statistics},
+ volume = {36},
+ number = {1},
+ pages = {226--235},
+ year = {1965}
+}
+
+@article{BrockMirman1972,
+ author = {Brock, William A. and Mirman, Leonard J.},
+ title = {Optimal Economic Growth and Uncertainty: The Discounted Case},
+ journal = {Journal of Economic Theory},
+ volume = {4},
+ number = {3},
+ pages = {479--513},
+ year = {1972}
+}
+
+@article{Sargent1980q,
+ author = {Sargent, Thomas J.},
+ title = {``{T}obin's q'' and the Rate of Investment in General Equilibrium},
+ journal = {Carnegie-Rochester Conference Series on Public Policy},
+ volume = {12},
+ pages = {107--154},
+ year = {1980}
+}
+
+@techreport{AlvarezArgente2026,
+ author = {Alvarez, Fernando and Argente, David},
+ title = {Strategic Complementarity and Persistence in Linear-Quadratic
+ Mean Field Games},
+ institution = {University of Chicago and Yale University},
+ year = {2026}
+}
+
+@article{LasryLions2007,
+ author = {Lasry, Jean-Michel and Lions, Pierre-Louis},
+ title = {Mean Field Games},
+ journal = {Japanese Journal of Mathematics},
+ volume = {2},
+ number = {1},
+ pages = {229--260},
+ year = {2007}
+}
+
+@article{HuangMalhameCaines2006,
+ author = {Huang, Minyi and Malham{\'e}, Roland P. and Caines, Peter E.},
+ title = {Large Population Stochastic Dynamic Games: Closed-Loop
+ {McKean-Vlasov} Systems and the Nash Certainty Equivalence
+ Principle},
+ journal = {Communications in Information and Systems},
+ volume = {6},
+ number = {3},
+ pages = {221--252},
+ year = {2006}
+}
+
+@article{AchdouEtAl2022,
+ author = {Achdou, Yves and Han, Jiequn and Lasry, Jean-Michel and
+ Lions, Pierre-Louis and Moll, Benjamin},
+ title = {Income and Wealth Distribution in Macroeconomics: A
+ Continuous-Time Approach},
+ journal = {Review of Economic Studies},
+ volume = {89},
+ number = {1},
+ pages = {45--86},
+ year = {2022}
+}
+
+@book{CarmonaDelarue2018,
+ author = {Carmona, Ren{\'e} and Delarue, Fran{\c c}ois},
+ title = {Probabilistic Theory of Mean Field Games with Applications},
+ publisher = {Springer},
+ address = {Cham},
+ year = {2018}
+}
+
+@book{LancasterRodman1995,
+ author = {Lancaster, Peter and Rodman, Leiba},
+ title = {Algebraic {R}iccati Equations},
+ publisher = {Oxford University Press},
+ address = {Oxford},
+ year = {1995}
+}
+
+@article{Kimball1995,
+ author = {Kimball, Miles S.},
+ title = {The Quantitative Analytics of the Basic Neomonetarist Model},
+ journal = {Journal of Money, Credit and Banking},
+ volume = {27},
+ number = {4},
+ pages = {1241--1277},
+ year = {1995}
+}
+
+@article{KlenowWillis2016,
+ author = {Klenow, Peter J. and Willis, Jonathan L.},
+ title = {Real Rigidities and Nominal Price Changes},
+ journal = {Economica},
+ volume = {83},
+ number = {331},
+ pages = {443--472},
+ year = {2016}
+}
+
+@article{Midrigan2011,
+ author = {Midrigan, Virgiliu},
+ title = {Menu Costs, Multiproduct Firms, and Aggregate Fluctuations},
+ journal = {Econometrica},
+ volume = {79},
+ number = {4},
+ pages = {1139--1180},
+ year = {2011}
+}
+
+@article{AlvarezLippi2014,
+ author = {Alvarez, Fernando and Lippi, Francesco},
+ title = {Price Setting with Menu Cost for Multiproduct Firms},
+ journal = {Econometrica},
+ volume = {82},
+ number = {1},
+ pages = {89--135},
+ year = {2014}
+}
diff --git a/lectures/_toc.yml b/lectures/_toc.yml
index 8fce349a0..953297f68 100644
--- a/lectures/_toc.yml
+++ b/lectures/_toc.yml
@@ -159,6 +159,8 @@ parts:
- file: lake_model
- file: endogenous_lake
- file: rational_expectations
+ - file: lucas_prescott_investment
+ - file: optimal_growth_uncertainty
- file: re_with_feedback
- file: markov_perf
- file: uncertainty_traps
@@ -167,6 +169,7 @@ parts:
- file: ak2
- file: ak_aiyagari
- file: two_computation
+ - file: lq_mean_field_games
- caption: Asset Pricing and Finance
numbered: true
chapters:
diff --git a/lectures/lq_mean_field_games.md b/lectures/lq_mean_field_games.md
new file mode 100644
index 000000000..e20a7c41f
--- /dev/null
+++ b/lectures/lq_mean_field_games.md
@@ -0,0 +1,1664 @@
+---
+jupytext:
+ text_representation:
+ extension: .md
+ format_name: myst
+ format_version: 0.13
+kernelspec:
+ display_name: Python 3
+ language: python
+ name: python3
+---
+
+(lq_mean_field_games)=
+```{raw} jupyter
+
+```
+
+# Linear Quadratic Mean Field Games
+
+```{contents} Contents
+:depth: 2
+```
+
+## Overview
+
+A **mean field game** describes a continuum of small agents, each of whom solves a dynamic optimization problem whose payoff depends on what everybody else is doing, summarized by the cross-sectional distribution of states.
+
+The framework was introduced by {cite:t}`LasryLions2007` and, independently, by {cite:t}`HuangMalhameCaines2006`.
+
+It pairs two partial differential equations:
+
+* a **Hamilton-Jacobi-Bellman** equation that runs backward in time and describes an individual's optimal choice, given paths for the aggregates
+* a **Kolmogorov forward** equation that runs forward in time and describes how the distribution of individual states evolves, given those choices
+
+An equilibrium requires that the aggregates that agents take as given are the ones that their own decisions generate.
+
+The same pair of equations is the workhorse of continuous-time heterogeneous-agent macroeconomics; see {cite:t}`AchdouEtAl2022`.
+
+Readers of {doc}`rational_expectations` will recognize that requirement.
+
+It is the "Big $Y$, little $y$" idea, now applied to an entire distribution rather than to a single number.
+
+This lecture studies a tractable special case in which the payoff is quadratic and the state evolves linearly, following {cite:t}`AlvarezArgente2026`.
+
+Two kinds of interaction appear:
+
+* agents care about the cross-sectional average *state* $X$, through a matrix $\Theta_X$
+* agents care about the cross-sectional average *action* $\mathcal A$, through a matrix $\Theta_{\mathcal A}$
+
+The main result is a striking simplification:
+
+```{note}
+The equilibrium of the mean field game solves the algebraic Riccati equation of a *single-agent* linear quadratic regulator problem, in which the curvature matrices $Q$ and $\Gamma$ are replaced by
+
+$$
+Q + \Theta_X \qquad\text{and}\qquad \Gamma + \Theta_{\mathcal A} .
+$$
+```
+
+Everything we know about the linear regulator can therefore be brought to bear on the equilibrium: existence conditions, uniqueness, comparative statics, and numerical methods.
+
+We then put the framework to work on two economic examples from {cite:t}`AlvarezArgente2026`: an industry equilibrium with capital accumulation, and a multiproduct pricing problem with Kimball demand.
+
+Riccati equations appear in several other QuantEcon lectures:
+
+* {doc}`lqcontrol` introduces the linear regulator and its Riccati equation
+* {doc}`lagrangian_lqdp` studies the state-costate system and its stable invariant subspace, which is exactly the structure we meet below
+* {doc}`markov_perf` studies dynamic games with *finitely many* players, where each player has a Riccati equation and the equations are coupled
+* {doc}`kalman` presents the Riccati equation that is dual to the control problem
+
+Let's start with some imports:
+
+```{code-cell} ipython3
+import numpy as np
+import matplotlib.pyplot as plt
+from scipy.linalg import solve_continuous_are, expm
+```
+
+## The environment
+
+There is a continuum of agents.
+
+An individual has state $x \in \mathbb R^n$ and takes an action $\alpha \in \mathbb R^k$.
+
+The cross-sectional average state and action are
+
+$$
+X = \int x \, m(x) dx , \qquad
+\mathcal A = \int \alpha_*(x) \, m(x) dx ,
+$$
+
+where $m$ is the density of the state across agents.
+
+The period return is quadratic in all four objects:
+
+```{math}
+:label: mfg_return
+F(x,X) + R(\alpha, \mathcal A)
+= -\tfrac12 x^\top Q x - X^\top\Theta_X x
+ -\tfrac12 \alpha^\top \Gamma \alpha - \mathcal A^\top \Theta_{\mathcal A}\alpha .
+```
+
+The individual state follows
+
+```{math}
+:label: mfg_state
+dx = (B\alpha - Ax) dt + \Sigma^{1/2} dW ,
+```
+
+where $W$ is an $n$-dimensional Brownian motion and shocks are purely idiosyncratic for now.
+
+Agents discount at rate $\rho > 0$.
+
+We assume that $Q$ and $\Gamma$ are positive definite, that $\Sigma$ is positive semi-definite, that $B$ has full row rank, and that $\Theta_X$ and $\Theta_{\mathcal A}$ are symmetric.
+
+### Complements and substitutes
+
+From {eq}`mfg_return`, the cross derivative between an agent's own state and the average state is $-\Theta_X$, and between her own action and the average action it is $-\Theta_{\mathcal A}$.
+
+So
+
+* states are **strategic complements** when $-\Theta_X$ is positive definite, i.e. when $\Theta_X$ is negative definite
+* states are **strategic substitutes** when $\Theta_X$ is positive definite
+
+and similarly for actions.
+
+In the Loewner ordering, *smaller* $\Theta$ means *more* complementarity.
+
+```{note}
+The monotonicity condition that {cite:t}`LasryLions2007` impose to obtain uniqueness corresponds here to $-\Theta_X$ being negative semi-definite, that is, to strategic *substitutability* in states.
+
+We will not need it: in this linear quadratic setting there is at most one equilibrium whether interactions are complements or substitutes.
+```
+
+### Equilibrium
+
+Taking the paths $\{X(t), \mathcal A(t)\}$ as given, an agent's value function satisfies the HJB equation
+
+```{math}
+:label: mfg_hjb
+\rho u(x,t) = -\tfrac12 x^\top Qx - X(t)^\top\Theta_X x
+ + H(u_x(x,t), x, \mathcal A(t))
+ + \tfrac12 \operatorname{tr}(\Sigma u_{xx}(x,t)) + u_t(x,t) ,
+```
+
+where the Hamiltonian is
+
+$$
+H(p, x, \mathcal A) = \max_{\alpha}
+\left\{ -\tfrac12\alpha^\top\Gamma\alpha - \mathcal A^\top\Theta_{\mathcal A}\alpha
++ p^\top(B\alpha - Ax) \right\} ,
+$$
+
+with maximizer $\alpha_*(p,\mathcal A) = \Gamma^{-1}(B^\top p - \Theta_{\mathcal A}\mathcal A)$.
+
+The density evolves according to the Kolmogorov forward equation
+
+```{math}
+:label: mfg_kfe
+m_t(x,t) = -\operatorname{div}\left( H_p(u_x(x,t),x,\mathcal A(t)) m(x,t)\right)
++ \tfrac12 \operatorname{tr}(\Sigma m_{xx}(x,t)) ,
+```
+
+and an **equilibrium** is a value function, a density, and paths for $X$ and $\mathcal A$ that satisfy {eq}`mfg_hjb`, {eq}`mfg_kfe`, and the consistency requirements that $X$ and $\mathcal A$ really are the cross-sectional averages implied by $m$ and by the optimal policy.
+
+## Solving the individual problem
+
+Given the aggregate paths, an individual faces a time-varying linear quadratic regulator problem, so her value function is quadratic:
+
+$$
+u(x,t) = \beta_0(t) + \beta_1(t)^\top x + \tfrac12 x^\top\beta_2(t)x .
+$$
+
+Substituting into {eq}`mfg_hjb` and matching terms of each order gives three differential equations.
+
+The one for $\beta_2$ is
+
+```{math}
+:label: mfg_beta2_ode
+\dot\beta_2 = Q - \beta_2 B\Gamma^{-1}B^\top\beta_2 + \beta_2 A + A^\top\beta_2 + \rho\beta_2 .
+```
+
+Notice what is *absent* from {eq}`mfg_beta2_ode`: neither interaction matrix appears.
+
+The curvature of an individual's value function is therefore the same as it would be if she were alone in the world.
+
+Because the individual problem is concave and stationary, $\beta_2(t)$ equals the constant $\bar\beta_2$, the negative definite solution of
+
+```{math}
+:label: mfg_beta2
+\bar\beta_2 B\Gamma^{-1}B^\top\bar\beta_2 = Q + \rho\bar\beta_2 + \bar\beta_2 A + A^\top\bar\beta_2 .
+```
+
+This is the familiar algebraic Riccati equation of {doc}`lqcontrol`, written in continuous time.
+
+The optimal action is
+
+$$
+\alpha_*(x,t) = \Gamma^{-1}\left[B^\top(\beta_1(t) + \bar\beta_2 x) - \Theta_{\mathcal A}\mathcal A(t)\right] .
+$$
+
+Averaging across agents and solving the resulting fixed point in $\mathcal A$ gives
+
+```{math}
+:label: mfg_aggregate_action
+\mathcal A(t) = (\Gamma + \Theta_{\mathcal A})^{-1} B^\top \left(\beta_1(t) + \bar\beta_2 X(t)\right) .
+```
+
+Equation {eq}`mfg_aggregate_action` is where the action interaction first bites: each agent responds to the average action, and solving for the average that is consistent with everyone doing so replaces $\Gamma$ by $\Gamma + \Theta_{\mathcal A}$.
+
+## A state-costate system
+
+Two objects now remain: the linear coefficient $\beta_1(t)$ of the value function, and the aggregate state $X(t)$.
+
+Differentiating and aggregating gives a pair of linear differential equations,
+
+```{math}
+:label: mfg_hamiltonian_system
+\begin{bmatrix} \dot\beta_1 \\ \dot X \end{bmatrix}
+= \mathcal H \begin{bmatrix} \beta_1 \\ X\end{bmatrix},
+\qquad
+\mathcal H =
+\begin{bmatrix}
+\rho I + A^\top - \bar\beta_2 \Lambda & \Theta_X + \bar\beta_2(B\Gamma^{-1}B^\top - \Lambda)\bar\beta_2 \\
+\Lambda & -A + \Lambda\bar\beta_2
+\end{bmatrix},
+```
+
+where we abbreviate
+
+$$
+\Lambda \equiv B(\Gamma + \Theta_{\mathcal A})^{-1}B^\top .
+$$
+
+This is a **state-costate** system of exactly the kind studied in {doc}`lagrangian_lqdp`.
+
+The aggregate state $X$ has an initial condition, namely the mean of the initial distribution.
+
+The costate $\beta_1$ does not: it must be chosen so that the solution does not violate the agent's transversality condition, which here requires the eigenvalues governing the path to have real parts below $\rho/2$.
+
+Because $\Theta_X$, $B\Gamma^{-1}B^\top$ and $\Lambda$ are symmetric, $\mathcal H - \tfrac\rho2 I$ is a Hamiltonian matrix, so its eigenvalues are symmetric about the origin.
+
+Equivalently:
+
+```{prf:proposition}
+:label: mfg_prop_roots
+
+If $\lambda$ is an eigenvalue of $\mathcal H$, then so are $\rho - \lambda$, $\bar\lambda$, and $\rho - \bar\lambda$.
+```
+
+Exactly $n$ eigenvalues can therefore have real parts below $\rho/2$, which pins down a unique stable invariant subspace and hence at most one equilibrium.
+
+This is the standard connection between algebraic Riccati equations and invariant subspaces of Hamiltonian matrices, treated at length by {cite:t}`LancasterRodman1995`.
+
+## The equilibrium Riccati equation
+
+We look for a saddle path along which the costate is a linear function of the state, $\beta_1(t) = S X(t)$.
+
+Substituting into {eq}`mfg_hamiltonian_system` gives a quadratic matrix equation for $S$ whose coefficients involve $\bar\beta_2$.
+
+That equation looks forbidding, but a change of variable transforms it.
+
+Define
+
+$$
+P \equiv S + \bar\beta_2 .
+$$
+
+```{prf:proposition}
+:label: mfg_prop_riccati
+
+An equilibrium is characterized by a matrix $P$ solving
+
+$$
+P \, B(\Gamma+\Theta_{\mathcal A})^{-1}B^\top \, P
+= Q + \Theta_X + \rho P + PA + A^\top P ,
+$$
+
+with aggregate dynamics
+
+$$
+\dot X = \left(B(\Gamma+\Theta_{\mathcal A})^{-1}B^\top P - A\right) X .
+$$
+
+The equilibrium requires all eigenvalues of the closed-loop matrix to have real parts below $\rho/2$.
+```
+
+Compare this with the single-agent equation {eq}`mfg_beta2`.
+
+They have *the same form*.
+
+The only difference is that $Q$ has become $Q + \Theta_X$ and $\Gamma$ has become $\Gamma + \Theta_{\mathcal A}$.
+
+```{prf:proposition}
+:label: mfg_prop_equivalence
+
+The equilibrium of a linear quadratic mean field game with interaction matrices $\Theta_X$ and $\Theta_{\mathcal A}$, and its aggregate law of motion, coincide with the solution of a single-agent linear quadratic control problem whose state curvature is $Q+\Theta_X$ and whose action curvature is $\Gamma+\Theta_{\mathcal A}$.
+```
+
+This is the organizing result of the lecture.
+
+It says that strategic interaction does not change the *form* of the problem that determines aggregate dynamics; it changes the *curvatures* that enter it.
+
+An immediate economic implication is that two models with very different strategic interactions can generate identical aggregate dynamics, provided the effective curvatures agree.
+
+### Existence and uniqueness
+
+Since $P$ solves a standard Riccati equation, standard conditions apply.
+
+Define
+
+```{math}
+:label: mfg_E
+E \equiv Q + \Theta_X + \left(A^\top + \tfrac\rho2 I\right)
+\left[B(\Gamma+\Theta_{\mathcal A})^{-1}B^\top\right]^{-1}
+\left(A + \tfrac\rho2 I\right) .
+```
+
+```{prf:proposition}
+:label: mfg_prop_existence
+
+Suppose $B(\Gamma+\Theta_{\mathcal A})^{-1}B^\top$ is invertible.
+
+1. A necessary condition for an equilibrium is that $E$ be positive semi-definite.
+1. If $Q + \Theta_X$ and $\Gamma + \Theta_{\mathcal A}$ are positive definite, an equilibrium exists and is unique.
+1. There is at most one equilibrium.
+```
+
+The sufficient condition has a clean reading: *effective* curvature must remain positive in both states and actions.
+
+Complementarity is therefore permissible, but only up to a point.
+
+Notice also that the two interactions enter $E$ additively, so substitutability in actions can offset complementarity in states.
+
+## Computing equilibria
+
+`scipy.linalg.solve_continuous_are(A, B, Q, R)` returns the stabilizing solution $\tilde P$ of
+
+$$
+A^\top \tilde P + \tilde P A - \tilde P B R^{-1} B^\top \tilde P + Q = 0 .
+$$
+
+Our equation differs in two ways: our $P$ is negative definite, and we discount.
+
+Writing $P = -\tilde P$ and collecting terms shows that our equation is the standard one with $A$ replaced by $-(A + \tfrac\rho2 I)$.
+
+The discount rate enters exactly as it does in the "$\rho/2$ shift" familiar from continuous-time control.
+
+```{code-cell} ipython3
+def mfg_riccati(A, B, Q, Γ, ρ):
+ """
+ Solve P B Γ^{-1} B' P = Q + ρ P + P A + A' P for the negative
+ definite stabilizing solution P.
+
+ Passing Q + Θ_X and Γ + Θ_A gives the equilibrium of the mean field game;
+ passing Q and Γ gives the single agent's value function curvature.
+ """
+ n = A.shape[0]
+ return -solve_continuous_are(-(A + ρ/2 * np.eye(n)), B, Q, Γ)
+
+def closed_loop(A, B, Γ_eff, P):
+ "The matrix governing aggregate dynamics, Ẋ = (B Γ_eff^{-1} B' P - A) X."
+ return B @ np.linalg.solve(Γ_eff, B.T) @ P - A
+```
+
+Let's set up a two-dimensional example with complementarity in states and substitutability in actions, the configuration that {cite:t}`AlvarezArgente2026` obtain from an industry equilibrium with capital accumulation.
+
+```{code-cell} ipython3
+ρ = 0.05
+A = np.array([[0.4, 0.1],
+ [0.0, 0.3]])
+B = np.eye(2)
+Q = np.array([[1.0, 0.2],
+ [0.2, 0.8]])
+Γ = np.array([[1.0, 0.1],
+ [0.1, 1.2]])
+Θ_X = np.array([[-0.3, 0.05], # negative definite: complements in states
+ [0.05, -0.2]])
+Θ_A = np.array([[0.2, 0.0], # positive definite: substitutes in actions
+ [0.0, 0.1]])
+
+β2 = mfg_riccati(A, B, Q, Γ, ρ) # single agent
+P = mfg_riccati(A, B, Q + Θ_X, Γ + Θ_A, ρ) # equilibrium
+
+print("individual curvature β̄₂ =\n", β2.round(4))
+print("\nequilibrium matrix P =\n", P.round(4))
+```
+
+Let's verify that $P$ really does solve the equilibrium Riccati equation, and compare the aggregate dynamics with what a lone agent would choose.
+
+```{code-cell} ipython3
+Λ = B @ np.linalg.solve(Γ + Θ_A, B.T)
+residual = P @ Λ @ P - (Q + Θ_X + ρ*P + P @ A + A.T @ P)
+print(f"Riccati residual: {np.abs(residual).max():.2e}")
+
+G = closed_loop(A, B, Γ, β2) # dynamics without any interaction
+JG = closed_loop(A, B, Γ + Θ_A, P) # equilibrium dynamics
+
+print("\neigenvalues without interactions:", np.linalg.eigvals(G).round(4))
+print("eigenvalues in equilibrium: ", np.linalg.eigvals(JG).round(4))
+```
+
+The equilibrium eigenvalues are closer to zero, so aggregate adjustment is slower than it would be if each agent ignored everyone else.
+
+### Checking the Hamiltonian structure
+
+{prf:ref}`mfg_prop_roots` says the eigenvalues of $\mathcal H$ come in pairs $\{\lambda, \rho - \lambda\}$, and that the $n$ eigenvalues with real parts below $\rho/2$ are the ones that govern equilibrium dynamics.
+
+Let's check both claims.
+
+```{code-cell} ipython3
+BΓB = B @ np.linalg.solve(Γ, B.T)
+n = A.shape[0]
+
+H = np.block([[ρ*np.eye(n) + A.T - β2 @ Λ, Θ_X + β2 @ (BΓB - Λ) @ β2],
+ [Λ, -A + Λ @ β2]])
+
+ev = np.linalg.eigvals(H)
+print("eigenvalues of ℋ:", np.sort(ev.real).round(4))
+print("paired as λ and ρ - λ:",
+ np.allclose(np.sort(ev.real), np.sort(ρ - ev.real)))
+
+stable = np.sort(ev.real[ev.real < ρ/2])
+print("\nstable half of ℋ: ", stable.round(4))
+print("closed-loop eigenvalues:", np.sort(np.linalg.eigvals(JG).real).round(4))
+```
+
+The saddle path is the stable invariant subspace of $\mathcal H$, exactly as in {doc}`lagrangian_lqdp`.
+
+## The scalar case
+
+With $n = k = 1$ everything is explicit.
+
+Write $q, a, b, \gamma, \theta_X, \theta_{\mathcal A}$ for the scalars.
+
+The Riccati equation becomes a quadratic, and the admissible root gives the aggregate eigenvalue
+
+```{math}
+:label: mfg_scalar_lambda
+\lambda = \frac\rho2 - \sqrt{\left(\frac\rho2 + a\right)^2
++ \frac{b^2(q + \theta_X)}{\gamma + \theta_{\mathcal A}}} .
+```
+
+An equilibrium exists if and only if the term under the square root is positive,
+
+```{math}
+:label: mfg_scalar_existence
+q + \theta_X + \left(\frac\rho2+a\right)^2\frac{\gamma+\theta_{\mathcal A}}{b^2} > 0 ,
+```
+
+and the equilibrium is stable, meaning $\lambda<0$, if and only if
+
+```{math}
+:label: mfg_scalar_stability
+q + \theta_X + a(a+\rho)\frac{\gamma+\theta_{\mathcal A}}{b^2} > 0 .
+```
+
+Formula {eq}`mfg_scalar_lambda` displays the two comparative statics at a glance.
+
+More complementarity in *states* (a smaller $\theta_X$) raises $\lambda$ and makes aggregate dynamics *more* persistent: when others stay away from the steady state, each agent has less reason to return to it.
+
+More complementarity in *actions* (a smaller $\theta_{\mathcal A}$) lowers $\lambda$ and makes dynamics *less* persistent: when others adjust, each agent wants to adjust too.
+
+Let's confirm that our solver reproduces {eq}`mfg_scalar_lambda`.
+
+```{code-cell} ipython3
+def scalar_lambda(ρ, a, b, q, γ, θ_X, θ_A):
+ "Closed-form aggregate eigenvalue in the scalar case."
+ return ρ/2 - np.sqrt((ρ/2 + a)**2 + b**2*(q + θ_X)/(γ + θ_A))
+
+ρ_s, a, b, q, γ = 0.05, 0.3, 1.0, 1.0, 1.0
+
+print(f"{'θ_X':>6}{'θ_A':>6}{'solver':>12}{'closed form':>14}")
+for θ_X, θ_A in ((0.0, 0.0), (-0.5, 0.0), (0.0, 0.5), (-0.5, 0.5)):
+ P_s = mfg_riccati(np.array([[a]]), np.array([[b]]),
+ np.array([[q + θ_X]]), np.array([[γ + θ_A]]), ρ_s)
+ λ_num = closed_loop(np.array([[a]]), np.array([[b]]),
+ np.array([[γ + θ_A]]), P_s)[0, 0]
+ print(f"{θ_X:>6}{θ_A:>6}{λ_num:>12.6f}{scalar_lambda(ρ_s,a,b,q,γ,θ_X,θ_A):>14.6f}")
+```
+
+## An industry equilibrium with capital accumulation
+
+The scalar model is not a toy.
+
+{cite:t}`AlvarezArgente2026` show that it describes an industry equilibrium with capital accumulation in which *both* kinds of interaction appear, with opposite signs.
+
+There is a continuum of monopolistically competitive firms.
+
+A firm with capital $k$ produces $y = k^\nu$ with $0 < \nu < 1$, and a constant returns sector aggregates the differentiated goods with elasticity of substitution $\eta > 1$.
+
+With the final good as numeraire, a firm that produces $y$ when industry output is $Y$ earns revenue proportional to $y^{1-1/\eta}Y^{1/\eta}$.
+
+So if all other firms hold capital $K$, operating profit is proportional to
+
+```{math}
+:label: mfg_capital_profit
+\Pi(k,K) = k^{\nu(1 - 1/\eta)} K^{\nu/\eta} .
+```
+
+Capital evolves according to
+
+$$
+dk = (i - \delta k)dt + k \sigma dW ,
+$$
+
+the firm buys investment goods at price $\mathcal P(I)$, where $I$ is aggregate investment, and it pays a convex adjustment cost $\psi(i)$.
+
+Let $\bar i = \delta \bar k$ be steady-state investment, normalize $\mathcal P(\bar i) = 1$ and $\psi'(\bar i) = 0$, and write percentage deviations from the deterministic steady state as
+
+$$
+x = \frac{k - \bar k}{\bar k}, \qquad
+X = \frac{K - \bar k}{\bar k}, \qquad
+\alpha = \frac{i - \bar i}{\bar i}, \qquad
+\mathcal A = \frac{I - \bar i}{\bar i} .
+$$
+
+A second-order expansion of the return around the steady state, with the objective normalized by $\bar\Pi \equiv \Pi(\bar k, \bar k)$, delivers exactly {eq}`mfg_return` with
+
+$$
+q = -\frac{\bar k^2 \Pi_{kk}}{\bar\Pi}, \qquad
+\theta_X = -\frac{\bar k^2 \Pi_{kK}}{\bar\Pi}, \qquad
+\gamma = \frac{\delta^2\bar k^2 \psi''(\bar i)}{\bar\Pi}, \qquad
+\theta_{\mathcal A} = \frac{\delta^2\bar k^2 \mathcal P'(\bar i)}{\bar\Pi} ,
+$$
+
+while the state equation becomes $dx = \delta(\alpha - x)dt + \sigma dW$ to first order, so that
+
+$$
+a = b = \delta .
+$$
+
+Differentiating {eq}`mfg_capital_profit` gives closed forms:
+
+```{math}
+:label: mfg_capital_coeffs
+\begin{aligned}
+q &= \nu\frac{\eta-1}{\eta^2}\left[\eta(1-\nu) + \nu\right] > 0 , \\
+\theta_X &= -\frac{\eta-1}{\eta}\frac{\nu^2}{\eta} < 0 , \\
+q + \theta_X &= \frac{\eta-1}{\eta}\nu(1-\nu) > 0 .
+\end{aligned}
+```
+
+Three features of {eq}`mfg_capital_coeffs` deserve emphasis.
+
+First, $\theta_X < 0$: capital stocks are strategic *complements*, because a larger industry capital stock raises the demand shifter $Y^{1/\eta}$ and hence the marginal profitability of a firm's own capital.
+
+Second, if the supply of investment goods slopes upward then $\mathcal P'(\bar i) > 0$ and so $\theta_{\mathcal A} > 0$: investment rates are strategic *substitutes*, because everyone investing at once bids up the price of capital goods.
+
+Third, $q + \theta_X > 0$ for every $\eta > 1$ and every $\nu \in (0,1)$, so by {prf:ref}`mfg_prop_existence` an equilibrium exists and is unique no matter how strong market power is and no matter how close returns to scale come to constant.
+
+Let's put these formulas into code, and check them against numerical derivatives of the profit function itself.
+
+```{code-cell} ipython3
+def cap_q(η, ν):
+ "Own-state curvature in the capital accumulation example."
+ return ν*(η - 1)/η**2*(η*(1 - ν) + ν)
+
+def cap_θ_X(η, ν):
+ "State interaction in the capital accumulation example."
+ return -(η - 1)/η*ν**2/η
+
+η_c, ν_c = 4.0, 0.7
+
+Π = lambda k, K: k**(ν_c*(1 - 1/η_c))*K**(ν_c/η_c)
+
+h = 1e-5
+Π_kk = (Π(1+h, 1) - 2*Π(1, 1) + Π(1-h, 1))/h**2
+Π_kK = (Π(1+h, 1+h) - Π(1+h, 1-h) - Π(1-h, 1+h) + Π(1-h, 1-h))/(4*h**2)
+
+print(f"{'':>10}{'finite difference':>20}{'closed form':>15}")
+print(f"{'q':>10}{-Π_kk/Π(1, 1):>20.6f}{cap_q(η_c, ν_c):>15.6f}")
+print(f"{'θ_X':>10}{-Π_kK/Π(1, 1):>20.6f}{cap_θ_X(η_c, ν_c):>15.6f}")
+print(f"{'q + θ_X':>10}{-(Π_kk + Π_kK)/Π(1, 1):>20.6f}"
+ f"{(η_c - 1)/η_c*ν_c*(1 - ν_c):>15.6f}")
+```
+
+### Calibration
+
+Take annual units, $\delta = 0.10$, $\rho = 0.05$, an elasticity of substitution $\eta = 4$, and returns to scale $\nu = 0.7$.
+
+For the two curvatures that the technology does not pin down we set $\gamma = 0.05$, which makes a firm that ignores the industry close half of a capital gap in three years, and $\theta_{\mathcal A} = 0.09$.
+
+{ref}`mfg_ex5` derives both numbers from an adjustment cost function and an investment supply curve.
+
+```{code-cell} ipython3
+ρ_c, δ_c = 0.05, 0.10
+γ_c, θ_A_c = 0.05, 0.09
+
+q_c, θ_X_c = cap_q(η_c, ν_c), cap_θ_X(η_c, ν_c)
+
+def half_life(λ):
+ "Time for the aggregate state to close half of a gap."
+ return np.log(2)/(-λ)
+
+λ_c = scalar_lambda(ρ_c, δ_c, δ_c, q_c, γ_c, θ_X_c, θ_A_c)
+
+P_c = mfg_riccati(np.array([[δ_c]]), np.array([[δ_c]]),
+ np.array([[q_c + θ_X_c]]), np.array([[γ_c + θ_A_c]]), ρ_c)
+λ_c_solver = closed_loop(np.array([[δ_c]]), np.array([[δ_c]]),
+ np.array([[γ_c + θ_A_c]]), P_c)[0, 0]
+
+print(f"q = {q_c:.4f}, θ_X = {θ_X_c:.4f}, q + θ_X = {q_c + θ_X_c:.4f}")
+print(f"λ from the solver = {λ_c_solver:.6f}")
+print(f"λ from the closed form = {λ_c:.6f}")
+print(f"half-life of aggregate capital = {half_life(λ_c):.2f} years")
+```
+
+### How much do the interactions matter?
+
+Because {eq}`mfg_scalar_lambda` depends on $\theta_X$ and $\theta_{\mathcal A}$ separately, we can switch each interaction off and read the answer.
+
+```{code-cell} ipython3
+cases = {'no interactions': (0.0, 0.0),
+ 'state complementarity only': (θ_X_c, 0.0),
+ 'action substitutability only': (0.0, θ_A_c),
+ 'equilibrium': (θ_X_c, θ_A_c),
+ 'planner (both doubled)': (2*θ_X_c, 2*θ_A_c)}
+
+print(f"{'':>30}{'λ':>10}{'half-life':>12}")
+for label, (tx, ta) in cases.items():
+ λ_case = scalar_lambda(ρ_c, δ_c, δ_c, q_c, γ_c, tx, ta)
+ print(f"{label:>30}{λ_case:>10.4f}{half_life(λ_case):>12.2f}")
+```
+
+Both interactions slow aggregate capital adjustment, and they do so for different reasons.
+
+Complementarity in states means that a firm has less reason to rebuild its capital while the rest of the industry is still below its steady state.
+
+Substitutability in actions means that a burst of industry investment is expensive, so firms spread their investment over time.
+
+Together they stretch the half-life of the industry's capital stock from three years to five.
+
+The planner, who internalizes both externalities, is slower still.
+
+### Micro and macro adjustment speeds
+
+A distinctive prediction of the model is that individual capital reverts to the mean faster than aggregate capital does, because {eq}`mfg_beta2` contains no interaction matrix.
+
+```{code-cell} ipython3
+β2_c = mfg_riccati(np.array([[δ_c]]), np.array([[δ_c]]),
+ np.array([[q_c]]), np.array([[γ_c]]), ρ_c)
+λ_micro = closed_loop(np.array([[δ_c]]), np.array([[δ_c]]),
+ np.array([[γ_c]]), β2_c)[0, 0]
+
+print(f"individual half-life = {half_life(λ_micro):.2f} years")
+print(f"aggregate half-life = {half_life(λ_c):.2f} years")
+print(f"ratio = {half_life(λ_c)/half_life(λ_micro):.2f}")
+```
+
+A researcher who estimated the speed of capital adjustment from firm-level data, and then used it to predict how quickly the industry responds to an industry-wide shock, would be too fast by two thirds.
+
+The gap is a pure interaction effect: the same technology and the same adjustment costs generate both numbers.
+
+### Market power and returns to scale
+
+How does the industry's adjustment speed depend on the two technological parameters?
+
+Both enter only through $q + \theta_X = \frac{\eta-1}{\eta}\nu(1-\nu)$, which rises with $\eta$ and is maximized at $\nu = 1/2$.
+
+```{code-cell} ipython3
+---
+mystnb:
+ figure:
+ caption: Half-lives of industry and firm capital
+ name: fig-mfg-half-lives
+---
+η_grid = np.linspace(1.2, 12, 200)
+ν_grid = np.linspace(0.05, 0.995, 200)
+
+def macro_micro(η, ν):
+ "Aggregate and individual half-lives as functions of (η, ν)."
+ q, θ_X = cap_q(η, ν), cap_θ_X(η, ν)
+ λ_agg = scalar_lambda(ρ_c, δ_c, δ_c, q, γ_c, θ_X, θ_A_c)
+ λ_ind = scalar_lambda(ρ_c, δ_c, δ_c, q, γ_c, 0.0, 0.0)
+ return half_life(λ_agg), half_life(λ_ind)
+
+fig, axes = plt.subplots(1, 2, figsize=(11, 4.2))
+
+hl_agg, hl_ind = np.array([macro_micro(η, ν_c) for η in η_grid]).T
+axes[0].plot(η_grid, hl_agg, lw=2, label='industry')
+axes[0].plot(η_grid, hl_ind, lw=2, ls='--', label='single firm')
+axes[0].set_xlabel('elasticity of substitution $\\eta$')
+
+hl_agg, hl_ind = np.array([macro_micro(η_c, ν) for ν in ν_grid]).T
+axes[1].plot(ν_grid, hl_agg, lw=2, label='industry')
+axes[1].plot(ν_grid, hl_ind, lw=2, ls='--', label='single firm')
+axes[1].axhline(np.log(2)/δ_c, color='k', lw=1, alpha=0.6)
+axes[1].set_xlabel('returns to scale $\\nu$')
+axes[1].annotate('$\\ln 2/\\delta$', (0.12, np.log(2)/δ_c - 0.45))
+
+for ax in axes:
+ ax.set_ylabel('half-life in years')
+ ax.legend()
+plt.tight_layout()
+plt.show()
+```
+
+More market power, meaning a smaller $\eta$, makes the industry slower: it weakens the own-capital curvature relative to the interaction, and the left panel shows the industry half-life rising as $\eta$ falls.
+
+The right panel contains a sharper result.
+
+As $\nu \to 1$ the effective curvature $q + \theta_X$ vanishes, and {eq}`mfg_scalar_lambda` collapses to $\lambda \to -\delta$: the industry's capital stock then returns to its steady state only through depreciation, with aggregate investment not responding at all.
+
+{ref}`mfg_ex6` asks you to verify this limit and to explain it.
+
+### Where are we in the four regions?
+
+{ref}`mfg_ex1` divides the scalar model into four regions using the thresholds $-\theta^{*}$ and $-\theta^{**}$.
+
+Since the technology delivers $q + \theta_X > 0$ and an upward sloping investment supply delivers $\theta_{\mathcal A} > 0$, this example is always in the first region.
+
+The thresholds show how much room there is to spare.
+
+```{code-cell} ipython3
+mθ_star = q_c + δ_c*(δ_c + ρ_c)*(γ_c + θ_A_c)/δ_c**2
+mθ_2star = q_c + (ρ_c/2 + δ_c)**2*(γ_c + θ_A_c)/δ_c**2
+
+print(f"complementarity in the calibration, -θ_X = {-θ_X_c:.4f}")
+print(f"instability threshold, -θ* = {mθ_star:.4f}")
+print(f"nonexistence threshold, -θ** = {mθ_2star:.4f}")
+```
+
+Complementarity would have to be five times stronger than the technology implies before the industry's capital stock stopped converging.
+
+### Transition paths
+
+Finally, let's trace out the industry's response to a capital stock that starts ten percent above its steady state.
+
+Aggregate investment follows from {eq}`mfg_aggregate_action`, which in the scalar case gives $\mathcal A(t) = \frac{\lambda + \delta}{\delta}X(t)$.
+
+```{code-cell} ipython3
+---
+mystnb:
+ figure:
+ caption: Transition paths of capital and investment
+ name: fig-mfg-transition
+---
+t_c = np.linspace(0, 25, 300)
+X0_c = 0.10
+
+fig, axes = plt.subplots(1, 2, figsize=(11, 4.2))
+for label in ('no interactions', 'equilibrium', 'planner (both doubled)'):
+ tx, ta = cases[label]
+ λ_case = scalar_lambda(ρ_c, δ_c, δ_c, q_c, γ_c, tx, ta)
+ path = X0_c*np.exp(λ_case*t_c)
+ axes[0].plot(t_c, 100*path, lw=2, label=label)
+ axes[1].plot(t_c, 100*(λ_case + δ_c)/δ_c*path, lw=2, label=label)
+
+axes[0].set_ylabel('capital, % above steady state')
+axes[1].set_ylabel('investment, % above steady state')
+for ax in axes:
+ ax.set_xlabel('years')
+ ax.axhline(0, color='k', lw=0.8)
+axes[0].legend()
+plt.tight_layout()
+plt.show()
+```
+
+The right panel is the industry's investment response, and it is where the two interactions show up most clearly.
+
+A firm that ignored the industry would cut investment on impact by thirteen percent of its steady-state level; in equilibrium the cut is under four percent, and it is undone much more slowly.
+
+The costate $\beta_1(t) + \bar\beta_2 x$ that supports these paths is the marginal value of installed capital, that is, Tobin's $q$.
+
+{doc}`optimal_growth_uncertainty` studies that object in a setting where the constraint $i \geq 0$ binds and the value function is not differentiable everywhere, which is exactly the nonlinearity that the quadratic approximation here sets aside.
+
+
+## Persistence
+
+How do the interactions change aggregate adjustment when $n > 1$?
+
+Stronger complementarity of either kind makes the stabilizing solution $P$ less negative definite.
+
+That ordering is not enough to sign the change in every eigenvalue of the closed-loop matrix, but it does sign the change in their *sum*.
+
+Stronger complementarity in states raises the trace of the closed-loop matrix, while stronger complementarity in actions lowers it.
+
+The trace measures the rate at which a set of initial aggregate states contracts in volume as each point follows its equilibrium path, so in a stable equilibrium the first force slows the collapse toward the steady state and the second speeds it up.
+
+```{code-cell} ipython3
+print(f"{'scale on Θ_X':>14}{'trace':>10} eigenvalues")
+for scale in (0.0, 0.5, 1.0, 1.5):
+ P_s = mfg_riccati(A, B, Q + scale*Θ_X, Γ + Θ_A, ρ)
+ JG_s = closed_loop(A, B, Γ + Θ_A, P_s)
+ print(f"{scale:>14}{np.trace(JG_s):>10.4f} {np.linalg.eigvals(JG_s).real.round(4)}")
+```
+
+Raising the scale makes $\Theta_X$ more negative, that is, complementarity stronger, and the trace rises as claimed.
+
+{ref}`mfg_ex2` asks you to investigate whether *each* eigenvalue must move in the same direction.
+
+## The planner
+
+A utilitarian planner internalizes the effect of each agent's state and action on the corresponding cross-sectional averages.
+
+When $\Theta_X$ and $\Theta_{\mathcal A}$ are symmetric, differentiating the planner's objective doubles each interaction term.
+
+```{prf:proposition}
+:label: mfg_prop_planner
+
+The planner's allocation coincides with the decentralized equilibrium of an economy whose interaction matrices are $2\Theta_X$ and $2\Theta_{\mathcal A}$, so the planner's Riccati equation is
+
+$$
+P^{*} B(\Gamma + 2\Theta_{\mathcal A})^{-1}B^\top P^{*}
+= Q + 2\Theta_X + \rho P^{*} + P^{*}A + A^\top P^{*} .
+$$
+```
+
+Internalizing state complementarity makes the allocation *more* persistent, while internalizing action complementarity makes it *less* persistent.
+
+When both are present the comparison is ambiguous, as {ref}`mfg_ex3` explores.
+
+```{code-cell} ipython3
+P_planner = mfg_riccati(A, B, Q + 2*Θ_X, Γ + 2*Θ_A, ρ)
+JG_planner = closed_loop(A, B, Γ + 2*Θ_A, P_planner)
+
+print("equilibrium eigenvalues:", np.linalg.eigvals(JG).real.round(4))
+print("planner eigenvalues: ", np.linalg.eigvals(JG_planner).real.round(4))
+```
+
+Let's see what this means for the path of the aggregate state.
+
+```{code-cell} ipython3
+---
+mystnb:
+ figure:
+ caption: Path of the aggregate state
+ name: fig-mfg-planner-path
+---
+X0 = np.array([1.0, 0.5])
+times = np.linspace(0, 12, 200)
+
+paths = {'no interactions': G, 'equilibrium': JG, 'planner': JG_planner}
+
+fig, ax = plt.subplots(figsize=(8, 4.5))
+for label, M in paths.items():
+ traj = np.array([expm(M*t) @ X0 for t in times])
+ ax.plot(times, traj[:, 0], lw=2, label=label)
+ax.set_xlabel('$t$')
+ax.set_ylabel('first component of $X(t)$')
+ax.legend()
+plt.tight_layout()
+plt.show()
+```
+
+## Multiproduct price setting with Kimball demand
+
+Our second example is multidimensional, and it delivers a surprise.
+
+{cite:t}`AlvarezArgente2026` study a continuum of "stores", each selling $n$ products with constant marginal costs $z_j$.
+
+Products within a store are aggregated by a CES price index with elasticity $\bar\eta_d$, and stores are aggregated by a symmetric Kimball aggregator {cite}`Kimball1995`.
+
+Let $\eta_D(y)$ be the elasticity of a store's demand with respect to its relative price, and let $\bar\eta_D > 1$ and $\bar\eta_D'$ denote its level and its derivative at the symmetric point.
+
+The derivative $\bar\eta_D'$ is the **superelasticity** of demand, and it is the reason Kimball demand is so widely used in models of price setting: a positive superelasticity means that a store which raises its prices above the average faces a more elastic demand, which discourages it from moving away from the crowd.
+
+That is strategic complementarity in prices, and it is the mechanism that {cite:t}`KlenowWillis2016` and much of the subsequent literature rely on for real rigidity.
+
+Writing $x$ and $X$ for log deviations of a store's prices and of the average store's prices from the flexible-price level $\bar p_i = \bar z_i \bar\eta_D/(\bar\eta_D-1)$, and $\bar s$ for the vector of steady-state expenditure shares, the curvature matrices are
+
+```{math}
+:label: mfg_kimball_Q
+\begin{aligned}
+Q &= (\bar\eta_D - 1)\left[\left(\bar\eta_D - \bar\eta_d
++ \frac{\bar\eta_D'}{\bar\eta_D-1}\right)\bar s\bar s^\top
++ \bar\eta_d \operatorname{diag}(\bar s)\right] , \\
+\Theta_X &= -\bar\eta_D' \, \bar s \bar s^\top , \\
+Q + \Theta_X &= (\bar\eta_D-1)\left[(\bar\eta_D - \bar\eta_d)\bar s \bar s^\top
++ \bar\eta_d \operatorname{diag}(\bar s)\right] .
+\end{aligned}
+```
+
+Stare at the third line.
+
+The superelasticity appears in $Q$ and in $\Theta_X$, but it *cancels* from $Q + \Theta_X$.
+
+By {prf:ref}`mfg_prop_riccati`, the sum $Q+\Theta_X$ is the only channel through which either matrix reaches aggregate dynamics.
+
+Actions are the rates of change of prices, and stores pay quadratic Rotemberg costs of changing them.
+
+The matrix $\Gamma$ lets that cost depend on which bundle of prices is changed, with negative off-diagonal elements representing economies of scope in repricing of the kind emphasized by {cite:t}`Midrigan2011` and {cite:t}`AlvarezLippi2014`.
+
+There is no interaction through aggregate actions, so $\Theta_{\mathcal A} = 0$, and a nonzero rate of cost inflation makes $A$ diagonal.
+
+```{code-cell} ipython3
+def kimball(η_d, η_D, η_D_prime, s):
+ "Curvature and state-interaction matrices under Kimball demand."
+ s = np.asarray(s, dtype=float)
+ S = np.outer(s, s)
+ Q = (η_D - 1)*((η_D - η_d + η_D_prime/(η_D - 1))*S + η_d*np.diag(s))
+ Θ_X = -η_D_prime*S
+ return Q, Θ_X
+
+s_bar = np.array([0.5, 0.3, 0.2]) # three products, unequal shares
+η_d, η_D = 6.0, 4.0 # within-store and across-store elasticities
+ρ_K, π_K = 0.04, 0.02 # discount rate and cost inflation
+
+n_K = len(s_bar)
+A_K = π_K*np.eye(n_K)
+B_K = np.eye(n_K)
+Γ_K = 20.0*(np.eye(n_K) - 0.25*(np.ones((n_K, n_K)) - np.eye(n_K)))
+
+print("Rotemberg cost matrix Γ =\n", Γ_K)
+print("\neigenvalues of Γ:", np.linalg.eigvalsh(Γ_K).round(4))
+```
+
+### The superelasticity and aggregate dynamics
+
+Now sweep the superelasticity across a wide range, including a negative value, and watch what changes and what does not.
+
+```{code-cell} ipython3
+print(f"{'η_D′':>6} {'eigenvalues of Q':>28} {'eigenvalues of Q + Θ_X':>28}")
+for η_Dp in (-3.0, 0.0, 3.0, 10.0):
+ Q_K, Θ_K = kimball(η_d, η_D, η_Dp, s_bar)
+ print(f"{η_Dp:>6} {str(np.linalg.eigvalsh(Q_K).round(3)):>28}"
+ f" {str(np.linalg.eigvalsh(Q_K + Θ_K).round(3)):>28}")
+```
+
+The own-curvature matrix $Q$ moves a great deal, and $\Theta_X$ moves with it, but the effective curvature does not move at all.
+
+Aggregate price dynamics are therefore invariant to the superelasticity.
+
+```{code-cell} ipython3
+print(f"{'η_D′':>6} {'aggregate eigenvalues':>34} {'individual eigenvalues':>34}")
+for η_Dp in (-3.0, 0.0, 3.0, 10.0):
+ Q_K, Θ_K = kimball(η_d, η_D, η_Dp, s_bar)
+ P_K = mfg_riccati(A_K, B_K, Q_K + Θ_K, Γ_K, ρ_K)
+ β2_K = mfg_riccati(A_K, B_K, Q_K, Γ_K, ρ_K)
+ ev_agg = np.sort(np.linalg.eigvals(closed_loop(A_K, B_K, Γ_K, P_K)).real)
+ ev_ind = np.sort(np.linalg.eigvals(closed_loop(A_K, B_K, Γ_K, β2_K)).real)
+ print(f"{η_Dp:>6} {str(ev_agg.round(4)):>34} {str(ev_ind.round(4)):>34}")
+```
+
+The left block of numbers is identical in every row, and the right block is not.
+
+The superelasticity changes how an individual store behaves without changing how the industry behaves.
+
+Almost all of the movement is in a single mode, because $\Theta_X$ is rank one and points in the direction $\bar s$, which is the store's own share-weighted price index.
+
+The remaining modes, which involve relative prices within the store, barely move.
+
+### Static complementarity
+
+It is worth seeing how much static complementarity we are varying.
+
+Maximizing the static profit function gives the best response $x^{*}(X) = -Q^{-1}\Theta_X X$, and {cite:t}`AlvarezArgente2026` show that
+
+```{math}
+:label: mfg_kimball_br
+\frac{\partial x_i^{*}(X)}{\partial X_j} = \bar s_j \frac{\kappa}{1+\kappa},
+\qquad
+\kappa \equiv \frac{\bar\eta_D'}{(\bar\eta_D-1)\bar\eta_D} .
+```
+
+```{code-cell} ipython3
+print(f"{'η_D′':>6}{'pass-through':>14} best response matrix, first row")
+for η_Dp in (-3.0, 0.0, 3.0, 10.0):
+ Q_K, Θ_K = kimball(η_d, η_D, η_Dp, s_bar)
+ BR = -np.linalg.solve(Q_K, Θ_K)
+ κ = η_Dp/((η_D - 1)*η_D)
+ BR_closed = κ/(1 + κ)*np.outer(np.ones(n_K), s_bar)
+ assert np.allclose(BR, BR_closed)
+ print(f"{η_Dp:>6}{BR.sum(axis=1)[0]:>14.4f} {BR[0].round(4)}")
+
+print("\nΘ_X symmetric: ", np.allclose(Θ_K, Θ_K.T))
+print("best response symmetric:", np.allclose(BR, BR.T))
+```
+
+Static pass-through runs from $-33\%$ to $+45\%$ across these rows, and it changes sign with the superelasticity, yet every one of these economies has exactly the same aggregate dynamics.
+
+An intuition that reads stronger static complementarity as more aggregate propagation is therefore unreliable.
+
+Notice also that the best response matrix is *not* symmetric, because shares differ across products, while $\Theta_X$ always is.
+
+Symmetry of $\Theta_X$ is what {prf:ref}`mfg_prop_planner` needs, and it survives even when the static game looks asymmetric.
+
+### Closed-form eigenvalues
+
+Because $A_K$ is a multiple of the identity and $B_K = I$, the aggregate eigenvalues have the same form as in the scalar case, one for each eigenvalue $\omega_i$ of $(\Gamma+\Theta_{\mathcal A})^{-1}(Q+\Theta_X)$:
+
+$$
+\lambda_i = \frac\rho2 - \sqrt{\left(\frac\rho2 + a\right)^2 + \omega_i} .
+$$
+
+```{code-cell} ipython3
+Q_K, Θ_K = kimball(η_d, η_D, 3.0, s_bar)
+P_K = mfg_riccati(A_K, B_K, Q_K + Θ_K, Γ_K, ρ_K)
+JG_K = closed_loop(A_K, B_K, Γ_K, P_K)
+
+ω = np.linalg.eigvals(np.linalg.solve(Γ_K, Q_K + Θ_K)).real
+predicted = np.sort(ρ_K/2 - np.sqrt((ρ_K/2 + π_K)**2 + ω))
+
+print("eigenvalues of the closed-loop matrix:", np.sort(np.linalg.eigvals(JG_K).real).round(6))
+print("from the closed-form formula: ", predicted.round(6))
+```
+
+{ref}`mfg_ex8` asks what happens when inflation differs across products, so that $A$ is diagonal but not a multiple of the identity.
+
+### Aggregate and individual price paths
+
+The decomposition {eq}`mfg_decomposition` splits a store's prices into the industry average $X$ and its own deviation $z = x - X$.
+
+The first follows the equilibrium matrix $P$, the second the single-agent matrix $\bar\beta_2$.
+
+So the invariance we found should show up as identical paths for the industry and different paths for a store that is out of line.
+
+```{code-cell} ipython3
+---
+mystnb:
+ figure:
+ caption: Industry and store price paths
+ name: fig-mfg-kimball-paths
+---
+t_K = np.linspace(0, 8, 200)
+shock = 0.10*np.ones(n_K) # ten percent above target, all products
+
+fig, axes = plt.subplots(1, 2, figsize=(11, 4.2))
+for k, η_Dp in enumerate((-3.0, 0.0, 3.0, 10.0)):
+ Q_K, Θ_K = kimball(η_d, η_D, η_Dp, s_bar)
+ P_K = mfg_riccati(A_K, B_K, Q_K + Θ_K, Γ_K, ρ_K)
+ β2_K = mfg_riccati(A_K, B_K, Q_K, Γ_K, ρ_K)
+ U_XX = closed_loop(A_K, B_K, Γ_K, P_K)
+ U_zz = closed_loop(A_K, B_K, Γ_K, β2_K)
+ agg = np.array([s_bar @ expm(U_XX*t) @ shock for t in t_K])
+ dev = np.array([s_bar @ expm(U_zz*t) @ shock for t in t_K])
+ label = f"$\\bar\\eta_D' = {η_Dp}$"
+ # decreasing line widths, so that four coincident curves remain visible
+ axes[0].plot(t_K, 100*agg, lw=6 - 1.5*k, label=label)
+ axes[1].plot(t_K, 100*dev, lw=2, label=label)
+
+axes[0].set_title('industry price index, $\\bar s^\\top X(t)$')
+axes[1].set_title("one store's deviation, $\\bar s^\\top z(t)$")
+for ax in axes:
+ ax.set_xlabel('years')
+ ax.set_ylabel('percent above target')
+ ax.legend()
+plt.tight_layout()
+plt.show()
+```
+
+The four curves in the left panel lie exactly on top of one another.
+
+The four curves in the right panel do not: the higher the superelasticity, the faster a store closes a gap between its own prices and the industry's.
+
+Micro and macro price flexibility are governed by different objects, and only the micro one responds to the superelasticity.
+
+### The planner does care
+
+Doubling the interaction gives the planner the effective curvature $Q + 2\Theta_X = (Q + \Theta_X) - \bar\eta_D' \bar s\bar s^\top$, which *does* depend on the superelasticity.
+
+```{code-cell} ipython3
+print(f"{'η_D′':>6} {'eig(Q + 2Θ_X)':>26} {'planner eigenvalues':>32}")
+for η_Dp in (-3.0, 0.0, 3.0, 10.0, 20.0):
+ Q_K, Θ_K = kimball(η_d, η_D, η_Dp, s_bar)
+ M = Q_K + 2*Θ_K
+ P_p = mfg_riccati(A_K, B_K, M, Γ_K, ρ_K)
+ ev = np.sort(np.linalg.eigvals(closed_loop(A_K, B_K, Γ_K, P_p)).real)
+ flag = "" if np.linalg.eigvalsh(M).min() > 0 else " <- not positive definite"
+ print(f"{η_Dp:>6} {str(np.linalg.eigvalsh(M).round(3)):>26}"
+ f" {str(ev.round(4)):>32}{flag}")
+```
+
+So the equilibrium's insensitivity to the superelasticity is special to the equilibrium.
+
+The gap between what a planner would do and what the industry does widens as the superelasticity rises, and in the last row the planner's effective curvature has stopped being positive definite and the returned matrix no longer stabilizes the system.
+
+{ref}`mfg_ex7` locates the threshold exactly, and gives it an interpretation in terms of static pass-through.
+
+
+## Aggregate shocks and identification
+
+Now add a shock that hits everyone at once.
+
+Let $\mathcal J$ be a compensated jump process and suppose
+
+$$
+dx = (B\alpha - Ax)dt + \Sigma^{1/2}dW + \Upsilon \, d\mathcal J .
+$$
+
+With common noise the value function must keep track of the aggregate state as well as the individual state, so it becomes $v(x, X)$.
+
+Nevertheless, matching coefficients in the recursive HJB equation delivers a result worth emphasizing.
+
+```{prf:proposition}
+:label: mfg_prop_common_noise
+
+With common noise, the matrix $P$ governing aggregate dynamics solves the *same* equilibrium Riccati equation as before.
+```
+
+This is a certainty-equivalence result of the kind familiar from linear quadratic control.
+
+It also yields a clean decomposition.
+
+Writing $z = x - X$ for an agent's deviation from the cross-sectional mean,
+
+```{math}
+:label: mfg_decomposition
+\begin{aligned}
+dX &= \left(\Lambda P - A\right) X dt + \Upsilon d\mathcal J , \\
+dz &= \left(B\Gamma^{-1}B^\top\bar\beta_2 - A\right) z \, dt + \Sigma^{1/2}dW , \\
+\alpha &= (\Gamma+\Theta_{\mathcal A})^{-1}B^\top P X + \Gamma^{-1}B^\top\bar\beta_2 z .
+\end{aligned}
+```
+
+Look carefully at the second line.
+
+The dynamics of an agent's deviation from the mean involve $\bar\beta_2$, the solution of the *single-agent* Riccati equation, and neither interaction matrix appears.
+
+The same is true of the part of the action that responds to $z$.
+
+```{prf:proposition}
+:label: mfg_prop_identification
+
+Data on $x(t) - X(t)$ and $\alpha(t)-\mathcal A(t)$ contain no information about $\Theta_X$ or $\Theta_{\mathcal A}$.
+```
+
+This is a sharp statement of the "missing intercept" problem.
+
+Removing time effects from micro data -- a standard way to control for aggregate conditions -- removes exactly the variation that identifies strategic interaction.
+
+Aggregate data, by contrast, do carry that information, and can be combined with micro data to recover it.
+
+```{code-cell} ipython3
+# reduced-form matrices that an econometrician could estimate
+U_XX = closed_loop(A, B, Γ + Θ_A, P) # drift of the aggregate state
+U_zz = closed_loop(A, B, Γ, β2) # drift of the deviation from the mean
+
+print("aggregate drift U_XX =\n", U_XX.round(4))
+print("\ndeviation drift U_zz =\n", U_zz.round(4))
+
+# now double the state interaction and recompute
+P_alt = mfg_riccati(A, B, Q + 2*Θ_X, Γ + Θ_A, ρ)
+print("\nwith Θ_X doubled:")
+print(" aggregate drift changes: ",
+ not np.allclose(U_XX, closed_loop(A, B, Γ + Θ_A, P_alt)))
+print(" deviation drift changes: ",
+ not np.allclose(U_zz, closed_loop(A, B, Γ, β2)))
+```
+
+{ref}`mfg_ex4` shows how to recover $\Theta_X$ from aggregate data, and why $\Theta_X$ and $\Theta_{\mathcal A}$ cannot be told apart without a normalization.
+
+## Exercises
+
+```{exercise}
+:label: mfg_ex1
+
+Formulas {eq}`mfg_scalar_existence` and {eq}`mfg_scalar_stability` divide the scalar model into four regions.
+
+Define
+
+$$
+-\theta^{*} \equiv q + a(a+\rho)\frac{\gamma+\theta_{\mathcal A}}{b^2},
+\qquad
+-\theta^{**} \equiv q + \left(\frac\rho2+a\right)^2\frac{\gamma+\theta_{\mathcal A}}{b^2} .
+$$
+
+Take $\rho = 0.5$, $a = 0.3$, $b = 1$, $q = 1$, $\gamma = 1$, $\theta_{\mathcal A}=0$.
+
+1. Compute $\theta^{*}$ and $\theta^{**}$, and verify that $-\theta^{**} = -\theta^{*} + (\rho/2)^2(\gamma+\theta_{\mathcal A})/b^2$.
+1. For values of $\theta_X$ on either side of each threshold, compute $\lambda$ and classify the outcome: stable, a unit root, divergent but admissible, or no equilibrium.
+1. What does `mfg_riccati` do when no equilibrium exists?
+1. Plot $\lambda$ against $\theta_X$ and mark the thresholds.
+```
+
+```{solution-start} mfg_ex1
+:class: dropdown
+```
+
+```{code-cell} ipython3
+ρ_e, a_e, b_e, q_e, γ_e, θA_e = 0.5, 0.3, 1.0, 1.0, 1.0, 0.0
+
+θ_star = -(q_e + a_e*(a_e + ρ_e)*(γ_e + θA_e)/b_e**2)
+θ_ss = -(q_e + (ρ_e/2 + a_e)**2*(γ_e + θA_e)/b_e**2)
+
+print(f"θ* = {θ_star:.4f}")
+print(f"θ** = {θ_ss:.4f}")
+print(f"gap = {θ_star - θ_ss:.4f}, "
+ f"(ρ/2)²(γ+θ_A)/b² = {(ρ_e/2)**2*(γ_e + θA_e)/b_e**2:.4f}")
+```
+
+```{code-cell} ipython3
+for θ_X in (0.5, -0.5, θ_star, -1.27, -1.31):
+ inside = (ρ_e/2 + a_e)**2 + b_e**2*(q_e + θ_X)/(γ_e + θA_e)
+ if inside < 0:
+ print(f"θ_X = {θ_X:+.4f}: no equilibrium")
+ continue
+ λ = ρ_e/2 - np.sqrt(inside)
+ if λ < -1e-9:
+ kind = "stable, X converges to zero"
+ elif abs(λ) <= 1e-9:
+ kind = "unit root, X stays where it starts"
+ else:
+ kind = "divergent but admissible"
+ print(f"θ_X = {θ_X:+.4f}: λ = {λ:+.5f} {kind}")
+```
+
+Below $\theta^{**}$ there is no real root, and the solver reports failure rather than returning a spurious answer.
+
+```{code-cell} ipython3
+try:
+ mfg_riccati(np.array([[a_e]]), np.array([[b_e]]),
+ np.array([[q_e - 1.31]]), np.array([[γ_e]]), ρ_e)
+except Exception as e:
+ print(f"solver raises {type(e).__name__} when no equilibrium exists")
+```
+
+```{code-cell} ipython3
+θ_grid = np.linspace(-1.30, 0.5, 400)
+inside = (ρ_e/2 + a_e)**2 + b_e**2*(q_e + θ_grid)/(γ_e + θA_e)
+λ_grid = np.where(inside >= 0, ρ_e/2 - np.sqrt(np.maximum(inside, 0)), np.nan)
+
+fig, ax = plt.subplots(figsize=(8, 4.5))
+ax.plot(θ_grid, λ_grid, lw=2)
+ax.axhline(0, color='k', lw=0.8)
+ax.axhline(ρ_e/2, color='grey', ls=':', lw=1, label=r'$\rho/2$')
+ax.axvline(θ_star, color='r', ls='--', lw=1, label=r'$\theta^{*}$')
+ax.axvline(θ_ss, color='b', ls='--', lw=1, label=r'$\theta^{**}$')
+ax.set_xlabel(r'$\theta_X$')
+ax.set_ylabel(r'$\lambda$')
+ax.legend()
+plt.tight_layout()
+plt.show()
+```
+
+Moving left along the horizontal axis means stronger complementarity in states.
+
+Persistence rises smoothly until $\theta^{*}$, where the aggregate state stops converging; between $\theta^{*}$ and $\theta^{**}$ equilibrium paths diverge, though slowly enough to keep discounted payoffs finite; below $\theta^{**}$ no equilibrium exists at all.
+
+```{solution-end}
+```
+
+```{exercise}
+:label: mfg_ex2
+
+The lecture showed that stronger complementarity in states raises the *trace* of the closed-loop matrix.
+
+Does it also raise every eigenvalue?
+
+Draw many random two-dimensional economies: take $B = I$, let $Q$ and $\Gamma$ be random positive definite matrices, let $\Theta_X$ be random negative definite, and set $\rho = 0.05$.
+
+For each draw, compare the equilibrium with interaction $\Theta_X$ to the one with $1.5\,\Theta_X$, keeping only draws in which both equilibria exist and are admissible.
+
+Report how often the trace rises and how often *every* eigenvalue rises.
+```
+
+```{solution-start} mfg_ex2
+:class: dropdown
+```
+
+```{code-cell} ipython3
+rng = np.random.default_rng(3)
+trace_rose = eig_rose = kept = 0
+
+for _ in range(400):
+ A_r = rng.normal(size=(2, 2))*0.3 + 0.4*np.eye(2)
+ B_r = np.eye(2)
+ M = rng.normal(size=(2, 2)); Q_r = M @ M.T + 0.5*np.eye(2)
+ M = rng.normal(size=(2, 2)); Γ_r = M @ M.T + 0.5*np.eye(2)
+ M = rng.normal(size=(2, 2)); Θ_r = -0.2 * (M @ M.T)
+
+ try:
+ P0 = mfg_riccati(A_r, B_r, Q_r + Θ_r, Γ_r, 0.05)
+ P1 = mfg_riccati(A_r, B_r, Q_r + 1.5*Θ_r, Γ_r, 0.05)
+ except Exception:
+ continue
+
+ J0 = closed_loop(A_r, B_r, Γ_r, P0)
+ J1 = closed_loop(A_r, B_r, Γ_r, P1)
+ if max(np.linalg.eigvals(J0).real.max(), np.linalg.eigvals(J1).real.max()) >= 0.025:
+ continue
+
+ kept += 1
+ trace_rose += np.trace(J1) > np.trace(J0) - 1e-10
+ e0 = np.sort(np.linalg.eigvals(J0).real)
+ e1 = np.sort(np.linalg.eigvals(J1).real)
+ eig_rose += np.all(e1 >= e0 - 1e-10)
+
+print(f"admissible draws: {kept}")
+print(f"trace rose: {trace_rose}/{kept}")
+print(f"every eigenvalue rose: {eig_rose}/{kept}")
+```
+
+The trace result holds in every draw, as the theory says it must.
+
+Eigenvalue-by-eigenvalue monotonicity fails in a noticeable minority of cases.
+
+The reason is that $Q+\Theta_X$ and $B(\Gamma+\Theta_{\mathcal A})^{-1}B^\top$ need not commute, so the problem does not separate into independent one-dimensional problems, and a change that slows adjustment overall can still speed it up along some direction.
+
+Additional restrictions -- for instance a scalar drift matrix $A = a I$ -- restore monotonicity mode by mode.
+
+```{solution-end}
+```
+
+```{exercise}
+:label: mfg_ex3
+
+Compare the planner with the decentralized equilibrium.
+
+Using the two-dimensional example from the lecture, compute the eigenvalues of the closed-loop matrix for the equilibrium and for the planner in four cases:
+
+1. only complementarity in states, $\Theta_X \prec 0$ and $\Theta_{\mathcal A}=0$
+1. only substitutability in actions, $\Theta_X = 0$ and $\Theta_{\mathcal A} = 0.2 I$
+1. only complementarity in actions, $\Theta_X = 0$ and $\Theta_{\mathcal A} = -0.2 I$
+1. complementarity in both
+
+In which cases is the planner's allocation more persistent than the equilibrium? Explain.
+```
+
+```{solution-start} mfg_ex3
+:class: dropdown
+```
+
+```{code-cell} ipython3
+def eigen_pair(Θ_X_use, Θ_A_use):
+ "Closed-loop eigenvalues for the equilibrium and for the planner."
+ P_eq = mfg_riccati(A, B, Q + Θ_X_use, Γ + Θ_A_use, ρ)
+ P_pl = mfg_riccati(A, B, Q + 2*Θ_X_use, Γ + 2*Θ_A_use, ρ)
+ e_eq = np.sort(np.linalg.eigvals(closed_loop(A, B, Γ + Θ_A_use, P_eq)).real)
+ e_pl = np.sort(np.linalg.eigvals(closed_loop(A, B, Γ + 2*Θ_A_use, P_pl)).real)
+ return e_eq, e_pl
+
+zero = np.zeros((2, 2))
+cases = {'states, complements': (Θ_X, zero),
+ 'actions, substitutes': (zero, 0.2*np.eye(2)),
+ 'actions, complements': (zero, -0.2*np.eye(2)),
+ 'both complements': (Θ_X, -0.2*np.eye(2))}
+
+print(f"{'case':24}{'equilibrium':>22}{'planner':>22} planner slower?")
+for label, (tx, ta) in cases.items():
+ e_eq, e_pl = eigen_pair(tx, ta)
+ slower = bool(np.all(e_pl >= e_eq - 1e-12))
+ print(f"{label:24}{str(e_eq.round(4)):>22}{str(e_pl.round(4)):>22} {slower}")
+```
+
+With only complementarity in states, the planner's allocation is more persistent.
+
+The planner recognizes that when one agent stays away from the steady state, others are content to stay away too, so there is less reason to hurry back.
+
+With only complementarity in *actions*, the comparison reverses and the planner adjusts faster: the planner internalizes that when one agent adjusts, others want to adjust as well.
+
+The case of substitutability in actions is the mirror image of the last one, and again makes the planner slower.
+
+When complementarity is present in both states and actions, the two forces work against each other.
+
+In this calibration the state interaction dominates and the planner is still slower, but that ranking is a quantitative accident, not a theorem: in general the comparison between planner and equilibrium persistence cannot be signed.
+
+```{solution-end}
+```
+
+```{exercise}
+:label: mfg_ex4
+
+This exercise works through {prf:ref}`mfg_prop_identification` and its consequences.
+
+1. Verify that the drift of an agent's deviation from the cross-sectional mean is unchanged when $\Theta_X$ and $\Theta_{\mathcal A}$ change.
+1. Suppose an econometrician knows $\rho$, $Q$, $A$, $B$, $\Gamma$ and $\Theta_{\mathcal A}$, and estimates the aggregate drift matrix $U_{\dot X, X}$. Show how to recover $\Theta_X$, and verify your procedure numerically.
+1. In the scalar model, show that $\theta_X$ and $\theta_{\mathcal A}$ are not separately identified: construct a family of pairs that generate identical aggregate dynamics *and* identical policy coefficients.
+```
+
+```{solution-start} mfg_ex4
+:class: dropdown
+```
+
+For part 1, the deviation drift is $B\Gamma^{-1}B^\top\bar\beta_2 - A$, and $\bar\beta_2$ solves the single-agent Riccati equation {eq}`mfg_beta2`, in which no interaction matrix appears.
+
+```{code-cell} ipython3
+for label, (tx, ta) in {'baseline': (Θ_X, Θ_A),
+ 'very different': (3*Θ_X, -0.1*np.eye(2))}.items():
+ β2_case = mfg_riccati(A, B, Q, Γ, ρ) # does not depend on tx, ta
+ print(f"{label:16}: U_zz =", closed_loop(A, B, Γ, β2_case).round(6).tolist())
+```
+
+For part 2, invert the definition of the closed-loop matrix to get $P$, then read $\Theta_X$ off the equilibrium Riccati equation:
+
+$$
+P = \Lambda^{-1}\left(U_{\dot X, X} + A\right),
+\qquad
+\Theta_X = P\Lambda P - Q - \rho P - PA - A^\top P .
+$$
+
+```{code-cell} ipython3
+U_obs = closed_loop(A, B, Γ + Θ_A, P) # what the econometrician estimates
+
+P_hat = np.linalg.solve(Λ, U_obs + A)
+Θ_X_hat = P_hat @ Λ @ P_hat - Q - ρ*P_hat - P_hat @ A - A.T @ P_hat
+
+print("true Θ_X =\n", Θ_X.round(6))
+print("\nrecovered Θ_X =\n", Θ_X_hat.round(6))
+print(f"\nmaximum error: {np.abs(Θ_X - Θ_X_hat).max():.2e}")
+```
+
+For part 3, formula {eq}`mfg_scalar_lambda` shows that $\lambda$ depends on the two interactions only through the ratio $(q+\theta_X)/(\gamma+\theta_{\mathcal A})$.
+
+Holding that ratio fixed traces out a one-parameter family of observationally equivalent economies.
+
+The policy coefficient cannot break the tie, because $\lambda = b\,U_{\alpha,X} - a$ ties it to $\lambda$.
+
+```{code-cell} ipython3
+ratio = (q + (-0.4))/(γ + 0.3) # baseline θ_X = -0.4, θ_A = 0.3
+
+print(f"{'θ_A':>7}{'θ_X':>12}{'λ':>12}{'policy coeff':>15}")
+for θ_A_alt in (0.3, 0.0, 0.6, 1.0):
+ θ_X_alt = ratio*(γ + θ_A_alt) - q
+ λ_alt = scalar_lambda(ρ_s, a, b, q, γ, θ_X_alt, θ_A_alt)
+ print(f"{θ_A_alt:>7.2f}{θ_X_alt:>12.6f}{λ_alt:>12.6f}{(λ_alt + a)/b:>15.6f}")
+```
+
+Every row describes a different economy, with a different amount of strategic complementarity in states and in actions, yet all of them generate exactly the same aggregate dynamics and the same policy rule.
+
+Distinguishing them requires normalizing one interaction, or bringing outside information to bear.
+
+```{solution-end}
+```
+
+```{exercise}
+:label: mfg_ex5
+
+This exercise derives the two curvatures that we simply assumed when calibrating the capital accumulation example.
+
+Suppose the adjustment cost is
+
+$$
+\psi(i) = \frac{\phi}{2}\,\bar i\left(\frac{i - \bar i}{\bar i}\right)^2 ,
+$$
+
+so that $\psi'(\bar i) = 0$ and $\psi''(\bar i) = \phi/\bar i$, and suppose investment goods are supplied with constant elasticity $\varepsilon_s$,
+
+$$
+\mathcal P(I) = \left(\frac{I}{\bar i}\right)^{1/\varepsilon_s} .
+$$
+
+1. Use the steady-state Euler equation $\Pi_k(\bar k, \bar k) = \rho + \delta$ to show that $\bar k^{1-\nu} = \nu(\eta-1)/[\eta(\rho+\delta)]$, and then that
+
+$$
+\gamma = \phi\,\delta\bar k^{1-\nu} , \qquad
+\theta_{\mathcal A} = \frac{\delta \bar k^{1-\nu}}{\varepsilon_s} .
+$$
+
+1. Which $(\phi, \varepsilon_s)$ reproduce the calibration $\gamma = 0.05$ and $\theta_{\mathcal A} = 0.09$?
+1. Show that all pairs with the same value of $\phi + 1/\varepsilon_s$ generate identical *aggregate* dynamics, and verify numerically that they nevertheless imply different individual investment rules and different planner allocations.
+```
+
+```{solution-start} mfg_ex5
+:class: dropdown
+```
+
+For part 1, $\Pi_k(k,K) = \nu\frac{\eta-1}{\eta}k^{\nu(1-1/\eta)-1}K^{\nu/\eta}$, so on the diagonal $\Pi_k(\bar k,\bar k) = \nu\frac{\eta-1}{\eta}\bar k^{\nu-1}$.
+
+Setting this equal to $\rho+\delta$, which is the steady-state user cost when $\mathcal P(\bar i) = 1$ and $\psi'(\bar i) = 0$, gives the stated expression for $\bar k^{1-\nu}$.
+
+Since $\bar\Pi = \bar k^{\nu}$ and $\bar i = \delta\bar k$,
+
+$$
+\gamma = \frac{\delta^2\bar k^2}{\bar k^{\nu}}\frac{\phi}{\delta \bar k}
+= \phi\,\delta\bar k^{1-\nu} ,
+\qquad
+\theta_{\mathcal A} = \frac{\delta^2\bar k^2}{\bar k^{\nu}}
+\frac{1}{\varepsilon_s \delta\bar k} = \frac{\delta\bar k^{1-\nu}}{\varepsilon_s} .
+$$
+
+```{code-cell} ipython3
+scale_c = δ_c*ν_c*(η_c - 1)/(η_c*(ρ_c + δ_c)) # δ k̄^{1-ν}
+
+print(f"δ k̄^(1-ν) = {scale_c:.4f}")
+print(f"φ implied by γ = {γ_c}: {γ_c/scale_c:.4f}")
+print(f"ε_s implied by θ_A = {θ_A_c}: {scale_c/θ_A_c:.4f}")
+```
+
+The calibration corresponds to a moderately convex adjustment cost, $\phi = 0.14$, and an investment supply elasticity of about $3.9$.
+
+For part 3, $\gamma + \theta_{\mathcal A} = \delta\bar k^{1-\nu}(\phi + 1/\varepsilon_s)$, and by {eq}`mfg_scalar_lambda` only this sum matters for $\lambda$.
+
+But the individual's Riccati equation {eq}`mfg_beta2` involves $\gamma$ alone, and the planner's involves $\gamma + 2\theta_{\mathcal A}$, so both separate the pairs.
+
+```{code-cell} ipython3
+print(f"{'φ':>6}{'1/ε_s':>8}{'aggregate':>12}{'individual':>12}{'planner':>10}")
+for φ, inv_ε in ((0.40, 0.00), (0.30, 0.10), (1/7, 0.257143), (0.05, 0.35)):
+ γ_case, θ_A_case = φ*scale_c, inv_ε*scale_c
+ λ_agg = scalar_lambda(ρ_c, δ_c, δ_c, q_c, γ_case, θ_X_c, θ_A_case)
+ λ_ind = scalar_lambda(ρ_c, δ_c, δ_c, q_c, γ_case, 0.0, 0.0)
+ λ_pl = scalar_lambda(ρ_c, δ_c, δ_c, q_c, γ_case, 2*θ_X_c, 2*θ_A_case)
+ print(f"{φ:>6.3f}{inv_ε:>8.3f}{λ_agg:>12.6f}{λ_ind:>12.6f}{λ_pl:>10.4f}")
+```
+
+Aggregate dynamics are identical down to the last digit, while individual behavior ranges from sluggish to almost frictionless.
+
+An econometrician with only aggregate data cannot tell a congested market for capital goods from an expensive installation technology, which is the scalar version of {prf:ref}`mfg_prop_identification`.
+
+```{solution-end}
+```
+
+```{exercise}
+:label: mfg_ex6
+
+The right panel of the figure above suggests that something special happens as returns to scale approach constancy.
+
+1. Show that $q + \theta_X \to 0$ and $\lambda \to -\delta$ as $\nu \to 1$, for every $\eta > 1$.
+1. Show that the response of aggregate investment to a capital gap, $(\lambda+\delta)/\delta$, goes to zero in the same limit.
+1. Explain the limit in economic terms.
+```
+
+```{solution-start} mfg_ex6
+:class: dropdown
+```
+
+Part 1 is immediate from {eq}`mfg_capital_coeffs`: $q + \theta_X = \frac{\eta-1}{\eta}\nu(1-\nu) \to 0$, and with $a = b = \delta$,
+
+$$
+\lambda \to \frac\rho2 - \sqrt{\left(\frac\rho2 + \delta\right)^2} = -\delta .
+$$
+
+For part 2, the scalar version of {eq}`mfg_aggregate_action` gives $\mathcal A = \frac{\lambda+\delta}{\delta}X$, which vanishes as $\lambda \to -\delta$.
+
+```{code-cell} ipython3
+print(f"{'ν':>8}{'q + θ_X':>10}{'λ':>10}{'half-life':>11}{'A/X':>9}")
+for ν in (0.7, 0.9, 0.99, 0.999, 0.99999):
+ λ_ν = scalar_lambda(ρ_c, δ_c, δ_c, cap_q(η_c, ν), γ_c, cap_θ_X(η_c, ν), θ_A_c)
+ print(f"{ν:>8}{cap_q(η_c,ν) + cap_θ_X(η_c,ν):>10.5f}{λ_ν:>10.5f}"
+ f"{half_life(λ_ν):>11.3f}{(λ_ν + δ_c)/δ_c:>9.4f}")
+```
+
+For part 3, note that $q + \theta_X = -\bar k^2\left[\Pi_{kk} + \Pi_{kK}\right]/\bar\Pi$ measures the curvature of profit along the *diagonal*, that is, the rate at which the marginal profitability of capital falls when the whole industry expands together.
+
+With $\nu = 1$ the profit function {eq}`mfg_capital_profit` is homogeneous of degree one in $(k, K)$ jointly, so $\Pi_k(k,k)$ does not depend on $k$ at all.
+
+An industry-wide capital gap then creates no incentive to invest differently, and the gap closes only through depreciation.
+
+Effective curvature is zero, the economy sits exactly on the boundary of the existence region in {eq}`mfg_scalar_existence`, and the equilibrium remains unique and stable with $\lambda = -\delta$.
+
+```{solution-end}
+```
+
+```{exercise}
+:label: mfg_ex7
+
+In the Kimball example, the equilibrium's effective curvature $Q + \Theta_X$ is positive definite for every superelasticity, but the planner's, $Q + 2\Theta_X$, is not.
+
+1. Using $Q + 2\Theta_X = (Q+\Theta_X) - \bar\eta_D'\,\bar s\bar s^\top$, show that it is positive definite if and only if
+$\bar\eta_D'\,\bar s^\top(Q+\Theta_X)^{-1}\bar s < 1$.
+1. Show that $(Q+\Theta_X)\mathbb{1} = (\bar\eta_D-1)\bar\eta_D\,\bar s$, where $\mathbb{1}$ is a vector of ones, and hence that the condition is $\bar\eta_D' < (\bar\eta_D-1)\bar\eta_D$.
+1. Show that this is exactly the condition that static pass-through in {eq}`mfg_kimball_br` be below one half, and verify the threshold numerically.
+```
+
+```{solution-start} mfg_ex7
+:class: dropdown
+```
+
+For part 1, if $\bar\eta_D' \leq 0$ the rank-one term is added rather than subtracted and positive definiteness is immediate.
+
+If $\bar\eta_D' > 0$, then for $M \succ 0$ the matrix $M - c vv^\top$ with $c>0$ is positive definite if and only if $c\, v^\top M^{-1}v < 1$, which follows from the determinant identity $\det(M - cvv^\top) = \det(M)(1 - c\,v^\top M^{-1}v)$ applied to every leading block, or directly from the Schur complement of the bordered matrix.
+
+For part 2, using $\bar s^\top\mathbb{1} = 1$ in the third line of {eq}`mfg_kimball_Q`,
+
+$$
+(Q+\Theta_X)\mathbb{1}
+= (\bar\eta_D-1)\left[(\bar\eta_D-\bar\eta_d)\bar s + \bar\eta_d \bar s\right]
+= (\bar\eta_D-1)\bar\eta_D\,\bar s .
+$$
+
+So $(Q+\Theta_X)^{-1}\bar s = \mathbb{1}/[(\bar\eta_D-1)\bar\eta_D]$ and therefore
+
+$$
+\bar s^\top(Q+\Theta_X)^{-1}\bar s = \frac{1}{(\bar\eta_D-1)\bar\eta_D} ,
+$$
+
+which turns the condition in part 1 into $\bar\eta_D' < (\bar\eta_D-1)\bar\eta_D$.
+
+For part 3, that inequality says precisely that $\kappa < 1$, and $\kappa/(1+\kappa)$ is increasing in $\kappa$ with value $1/2$ at $\kappa = 1$.
+
+Total static pass-through is $\sum_j \partial x_i^{*}/\partial X_j = \kappa/(1+\kappa)$ because the shares sum to one, so the planner's problem is well behaved exactly when a store would pass less than half of an industry-wide price increase into its own prices.
+
+```{code-cell} ipython3
+lo, hi = 0.0, 100.0
+for _ in range(60):
+ mid = (lo + hi)/2
+ Q_m, Θ_m = kimball(η_d, η_D, mid, s_bar)
+ if np.linalg.eigvalsh(Q_m + 2*Θ_m).min() > 0:
+ lo = mid
+ else:
+ hi = mid
+
+κ_star = lo/((η_D - 1)*η_D)
+print(f"threshold by bisection: η_D′ = {lo:.6f}")
+print(f"(η_D - 1) η_D = {(η_D - 1)*η_D:.6f}")
+print(f"κ at the threshold = {κ_star:.6f}")
+print(f"pass-through there = {κ_star/(1 + κ_star):.6f}")
+```
+
+```{solution-end}
+```
+
+```{exercise}
+:label: mfg_ex8
+
+The closed-form eigenvalues in the Kimball example used $A = \pi I$.
+
+Replace it by $A = \operatorname{diag}(0.00, 0.02, 0.06)$, so that the three products face different rates of cost inflation.
+
+1. Check that the closed-form formula fails.
+1. Check that the trace comparative static of the *Persistence* section still holds, by scaling $\Theta_X$ and recording the trace and the eigenvalues of the closed-loop matrix.
+1. Does the invariance of aggregate dynamics to the superelasticity survive?
+```
+
+```{solution-start} mfg_ex8
+:class: dropdown
+```
+
+```{code-cell} ipython3
+A_het = np.diag([0.00, 0.02, 0.06])
+Q_h, Θ_h = kimball(η_d, η_D, 3.0, s_bar)
+
+P_h = mfg_riccati(A_het, B_K, Q_h + Θ_h, Γ_K, ρ_K)
+JG_h = closed_loop(A_het, B_K, Γ_K, P_h)
+
+ω_h = np.linalg.eigvals(np.linalg.solve(Γ_K, Q_h + Θ_h)).real
+print("closed-loop eigenvalues:", np.sort(np.linalg.eigvals(JG_h).real).round(5))
+print("closed-form formula: ",
+ np.sort(ρ_K/2 - np.sqrt((ρ_K/2 + np.diag(A_het))**2 + np.sort(ω_h))).round(5))
+```
+
+The formula no longer holds: with $A$ not a multiple of the identity there is no single scalar shift to put inside the square root, and the eigenvectors of $A$ and of $Q+\Theta_X$ need not agree.
+
+The errors are modest here because the three inflation rates are close together, but they are systematic, and they grow with the dispersion in $A$.
+
+The trace result, on the other hand, requires no such restriction.
+
+```{code-cell} ipython3
+print(f"{'scale on Θ_X':>14}{'trace':>10} eigenvalues")
+for scale in (0.0, 0.5, 1.0, 1.5):
+ P_s = mfg_riccati(A_het, B_K, Q_h + scale*Θ_h, Γ_K, ρ_K)
+ JG_s = closed_loop(A_het, B_K, Γ_K, P_s)
+ print(f"{scale:>14}{np.trace(JG_s):>10.5f} "
+ f"{np.sort(np.linalg.eigvals(JG_s).real).round(5)}")
+```
+
+Raising the scale strengthens complementarity and raises the trace, exactly as in the two-dimensional example earlier.
+
+For part 3, the invariance has nothing to do with $A$: it comes from the cancellation of $\bar\eta_D'$ in $Q + \Theta_X$, and {prf:ref}`mfg_prop_riccati` shows that only $Q+\Theta_X$ and $\Gamma+\Theta_{\mathcal A}$ enter the equilibrium Riccati equation.
+
+```{code-cell} ipython3
+for η_Dp in (-3.0, 0.0, 3.0, 10.0):
+ Q_i, Θ_i = kimball(η_d, η_D, η_Dp, s_bar)
+ P_i = mfg_riccati(A_het, B_K, Q_i + Θ_i, Γ_K, ρ_K)
+ ev = np.sort(np.linalg.eigvals(closed_loop(A_het, B_K, Γ_K, P_i)).real)
+ print(f"η_D′ = {η_Dp:>5}: {ev.round(6)}")
+```
+
+```{solution-end}
+```
+
+
+## Further reading
+
+{cite:t}`AlvarezArgente2026` develop the results in this lecture, along with the two economic examples that we implemented above.
+
+They also extend the analysis to interactions through higher moments of the cross-sectional distribution.
+
+{cite:t}`CarmonaDelarue2018` give a comprehensive probabilistic treatment of mean field games, and {cite:t}`AchdouEtAl2022` describe the numerical methods used to solve the coupled partial differential equations when the model is not linear quadratic.
diff --git a/lectures/lucas_prescott_investment.md b/lectures/lucas_prescott_investment.md
new file mode 100644
index 000000000..a8666a526
--- /dev/null
+++ b/lectures/lucas_prescott_investment.md
@@ -0,0 +1,1019 @@
+---
+jupytext:
+ text_representation:
+ extension: .md
+ format_name: myst
+ format_version: 0.13
+kernelspec:
+ display_name: Python 3
+ language: python
+ name: python3
+---
+
+(lucas_prescott_investment)=
+```{raw} jupyter
+
+```
+
+# Investment Under Uncertainty
+
+```{contents} Contents
+:depth: 2
+```
+
+In addition to what's in Anaconda, this lecture will need the following libraries:
+
+```{code-cell} ipython3
+---
+tags: [hide-output]
+---
+!pip install quantecon
+```
+
+## Overview
+
+This lecture studies {cite:t}`Lucas_Prescott_1971`, a paper that helped to ignite a *rational expectations revolution*.
+
+Lucas and Prescott studied a competitive industry in which
+
+* demand shifts randomly each period
+* firms face costs of adjusting their capital stocks
+* firms must forecast future prices in order to decide how much to invest
+* the probability distribution that firms use to forecast prices *equals* the probability distribution that their investment decisions actually generate
+
+That last bullet point is what {cite:t}`muth1961` called **rational expectations**.
+
+The QuantEcon lecture {doc}`rational_expectations` presents what we might call a "baby" version of the Lucas-Prescott model.
+
+That lecture studies a linear-quadratic industry *without uncertainty*.
+
+The present lecture describes the more ambitious structure that Lucas and Prescott actually built.
+
+Relative to the baby version, Lucas and Prescott
+
+* let demand be shifted by a Markov process $\{u_t\}$, so that the equilibrium is a stochastic process rather than a deterministic path
+* allow a nonlinear technology for converting investment into capacity
+* prove that a competitive equilibrium *exists* and is *unique*
+* show that the equilibrium is the solution of a *planning problem* that maximizes discounted consumer surplus
+* show that the equilibrium is a *Markov process* in the state $(k_t, u_t)$
+* provide conditions under which that Markov process has an *invariant probability distribution* to which it converges from any initial condition
+
+The last item is the part of the paper that most influenced later work.
+
+A model whose equilibrium is a Markov process with an invariant distribution is a model that can be taken to time series data.
+
+That observation set the stage for the *rational expectations econometrics* subsequently developed by Lars Peter Hansen and Thomas Sargent {cite}`HanSar1980`.
+
+Along the way we'll describe how {cite:t}`PrescottMehra1980` later distilled the Lucas-Prescott structure into a general definition of a **recursive competitive equilibrium**.
+
+The sequel {doc}`optimal_growth_uncertainty` studies a paper that asks the same questions about a one-sector optimal growth model, {cite:t}`BrockMirman1972`, and a paper that uses that model to think about Tobin's $q$, {cite:t}`Sargent1980q`.
+
+Let's start with some imports:
+
+```{code-cell} ipython3
+import numpy as np
+import matplotlib.pyplot as plt
+import quantecon as qe
+from collections import namedtuple
+```
+
+## The industry
+
+An industry consists of many small firms.
+
+Each firm produces a single output $q_t$ with a single input, capital $k_t$.
+
+Production has constant returns to scale, and with a suitable choice of units the production function is
+
+```{math}
+:label: lp_production
+0 \leq q_t \leq k_t .
+```
+
+Because capital is the only input and output is sold at a positive price, every firm produces at capacity, so that $q_t = k_t$.
+
+Let $x_t$ denote gross investment.
+
+Capacity next period is related to capacity this period and investment by
+
+```{math}
+:label: lp_accumulation
+k_{t+1} = k_t \, h\!\left(\frac{x_t}{k_t}\right),
+```
+
+where $h$ is bounded, continuously differentiable, increasing, and strictly *concave*.
+
+The strict concavity of $h$ is what creates **costs of adjustment**: doubling the rate of investment per unit of capital less than doubles the resulting increment to capacity.
+
+Adjustment costs are why firms change their capital stocks gradually instead of jumping immediately to a long-run target.
+
+Assume that $\delta = h^{-1}(1)$ exists and satisfies $0 < \delta < 1$.
+
+Then $x_t = \delta k_t$ is the investment rate that just maintains capacity, so $\delta$ plays the role of a depreciation rate.
+
+Let $p_t$ be the output price and let $\beta = 1/(1+r)$, where $r > 0$ is the cost of capital.
+
+The present value of a firm is
+
+```{math}
+:label: lp_value
+V = \sum_{t=0}^\infty \beta^t \left[ p_t q_t - x_t \right].
+```
+
+Because the allocation of a given industry capital stock across firms does not matter, we can use $k_t, x_t, q_t$ interchangeably for firm and industry variables.
+
+Equivalently, we can think of a competitive industry with a single price-taking firm.
+
+Industry demand is subject to random shifts:
+
+```{math}
+:label: lp_demand
+p_t = D(q_t, u_t),
+```
+
+where $D$ is continuous and strictly decreasing in $q_t$ and increasing in $u_t$, so that an increase in $u_t$ shifts the demand curve to the right.
+
+The demand shifter $\{u_t\}$ is a Markov process with transition distribution $p(\cdot, u)$, meaning that the probability that $u_{t+1} \in A$ conditional on $u_t = u$ is $\int_A p(dz, u)$.
+
+## The firm and the price of installed capital
+
+Before studying equilibrium, Lucas and Prescott pause over an instructive question: what does an individual firm actually need to know?
+
+Let $w_t$ be the current market value of a unit of installed capital and let $w^*_t$ be the value per unit expected to prevail next period.
+
+A firm that begins period $t$ with capital $k_t$ and invests $x$ obtains next-period capital worth $\beta k_t h(x/k_t) w^*_t$ at a cost of $x$, so it solves
+
+$$
+\max_x \left[ -x + \beta k_t h(x/k_t) w^*_t \right] .
+$$
+
+The current value of the firm is
+
+```{math}
+:label: lp_firmvalue
+w_t k_t = p_t k_t - x + \beta k_t h(x/k_t) w^*_t
+```
+
+and the first-order condition is
+
+```{math}
+:label: lp_firmfoc
+0 \geq -1 + \beta h'(x/k_t) w^*_t, \quad \text{with equality if } x > 0 .
+```
+
+Solving {eq}`lp_firmvalue` and {eq}`lp_firmfoc` jointly for $x$ and $w^*_t$ gives an investment function of the form
+
+```{math}
+:label: lp_investment_fn
+x_t = k_t \, g(w_t - p_t), \qquad g'(\cdot) > 0 .
+```
+
+Lucas and Prescott note that {eq}`lp_investment_fn` is essentially the investment function that Grunfeld had used in empirical work, with the market value of the firm as an explanatory variable.
+
+Their argument is stronger than Grunfeld's, though: a firm does not need to forecast its own future income stream at all.
+
+It needs only to know the value that securities markets place on a unit of installed capital.
+
+Readers will recognize a version of what later became known as Tobin's $q$ theory of investment.
+
+But equation {eq}`lp_investment_fn` is a *consistency requirement*, not yet a theory of capital accumulation, because the path of $w_t$ is still unknown.
+
+To determine $w_t$ we have to study equilibrium.
+
+## Rational expectations equilibrium
+
+Firms must forecast future prices.
+
+Lucas and Prescott describe the usual approach as postulating a forecasting rule -- for example "adaptive expectations" -- that generates investment behavior, which in conjunction with demand generates an actual price process.
+
+They object that if the underlying disturbance has a regular stochastic character, then, except by coincidence, forecast prices and actual prices will have *different probability distributions*, and the difference will be persistent, costly, and easy to correct.
+
+So they go to the opposite extreme and assume that the actual and anticipated prices have the *same probability distribution*.
+
+To say this precisely, fix an initial state $(k_0, u_0)$.
+
+Because prices depend on the history of demand shocks, an anticipated price process is a sequence $\{p_t\}$ of functions of $(u_1, \ldots, u_t)$.
+
+Similarly, an investment-output plan is a pair of sequences $\{q_t, x_t\}$ of functions of $(u_1, \ldots, u_t)$ -- a contingency plan that says in advance what the firm will do after every possible history.
+
+```{prf:definition}
+:label: lp_equilibrium_def
+
+An **industry equilibrium** for a fixed initial state $(k_0, u_0)$ is a triple of sequences $\{q^0_t, x^0_t, p^0_t\}$ such that
+
+1. the demand curve {eq}`lp_demand` holds for every history, and
+1. the plan $\{q^0_t, x^0_t\}$ maximizes expected present value
+
+ $$
+ \mathbb{E} \left\{ \sum_{t=0}^\infty \beta^t \left[ p^0_t q_t - x_t \right] \right\}
+ $$
+
+ over all plans $\{q_t, x_t\}$ that satisfy {eq}`lp_production` and {eq}`lp_accumulation`, *given* the price process $\{p^0_t\}$.
+```
+
+The rational expectations requirement is hiding in plain sight in {prf:ref}`lp_equilibrium_def`.
+
+The price process $\{p^0_t\}$ that firms take as given when they maximize is the *same* price process that their own decisions generate through the demand curve.
+
+This is exactly the fixed point idea of the lecture {doc}`rational_expectations`, where a **perceived law of motion** $H$ for aggregate output must equal the **actual law of motion** that the resulting decision rule generates.
+
+The difference is that here the fixed point is in a space of sequences of functions of histories rather than in a space of linear decision rules.
+
+```{note}
+Lucas and Prescott are careful about what rationality does and does not assume.
+
+They write that they "surrender, in advance, any hope of shedding light on the process by which firms translate current information into price forecasts."
+
+They also defend the assumption: if the demand shift process really does have a regular, stationary structure, then expectations that are rational in their sense "are surely more plausible than any simple, adaptive scheme"; and if it does not, then adopting some other expectations hypothesis "will certainly not improve matters."
+```
+
+## Equilibrium as a planning problem
+
+How can we compute an object defined by a fixed point in such a large space?
+
+Lucas and Prescott's answer is the device that the lecture {doc}`rational_expectations` also uses: find a **planning problem** whose solution is the equilibrium.
+
+Define **consumer surplus** as the area under the demand curve
+
+$$
+s(q, u) = \int_0^q D(z, u) \, dz ,
+$$
+
+and define discounted consumer surplus net of investment costs by
+
+```{math}
+:label: lp_surplus
+S = \mathbb{E} \left\{ \sum_{t=0}^\infty \beta^t \left[ s(q_t, u_t) - x_t \right] \right\} .
+```
+
+Associated with the problem of maximizing $S$ is the functional equation
+
+```{math}
+:label: lp_bellman
+v(k, u) = \sup_{x \geq 0} \left\{ s(k, u) - x + \beta \int v\!\left[ k h\!\left(\frac{x}{k}\right), z \right] p(dz, u) \right\} .
+```
+
+```{prf:theorem}
+:label: lp_theorem1
+
+The functional equation {eq}`lp_bellman` has a unique bounded solution $v$, and for each $(k,u)$ the supremum is attained at a unique $x(k,u)$.
+
+In terms of that policy function, the unique industry equilibrium, given $(k_0, u_0)$, is
+
+$$
+x_t = x(k_t, u_t), \qquad
+k_{t+1} = k_t h\!\left(\frac{x(k_t,u_t)}{k_t}\right), \qquad
+q_t = k_t, \qquad
+p_t = D(q_t, u_t) .
+$$
+```
+
+The proof has two halves, and both halves matter for later work.
+
+The first half shows that a competitive equilibrium maximizes $S$, and conversely.
+
+This is an application of the welfare theorems in an infinite-dimensional commodity space, using the valuation equilibria of Debreu and the price systems that Prescott and Lucas developed in a companion paper.
+
+Lucas and Prescott are explicit that they use this connection only as a computational device: "the welfare significance of $S$ is not important. We are interested only in using the connection between the maximization of $S$ and competitive equilibrium in order to determine the properties of the latter."
+
+The second half shows that the planning problem is solved by the functional equation {eq}`lp_bellman`.
+
+Here they use the operator
+
+$$
+Tf(k,u) = \sup_{x \geq 0} \left\{ s(k,u) - x + \beta \int f\!\left[ k h(x/k), z \right] p(dz, u) \right\}
+$$
+
+and verify that $T$ is monotone and satisfies a discounting property, so that by Blackwell's theorem {cite}`Blackwell1965` it has a unique fixed point that successive approximations converge to.
+
+They also show that $T$ preserves concavity and monotonicity in $k$, which delivers a unique and continuous policy function $x(k,u)$.
+
+```{note}
+These arguments are now standard and are treated at length in {cite:t}`StokeyLucas1989`.
+
+In 1971 they were not standard, which is one reason the paper is hard to read.
+
+Much of its length is devoted to measurability details -- Baire functions, Borel sets -- that a modern treatment would relegate to an appendix.
+```
+
+Two features of {prf:ref}`lp_theorem1` deserve emphasis.
+
+First, the equilibrium is **recursive**: the pair $(k_t, u_t)$ is a Markov process, and equilibrium prices and quantities are time-invariant functions of it.
+
+Second, the equilibrium is computed *without ever iterating on a mapping from beliefs to outcomes*.
+
+The lecture {doc}`rational_expectations` explains why that matters: the mapping $\Phi$ from a perceived law of motion to an actual law of motion is *not a contraction*, and iterating on it can diverge.
+
+The planning problem replaces an unreliable fixed point calculation with a dynamic program that is a contraction.
+
+## Recursive competitive equilibrium
+
+{cite:t}`PrescottMehra1980` later extracted the general structure that Lucas and Prescott had exploited.
+
+Their goal was to replace a search for equilibrium *sequences of contingency functions*, in the style of Arrow and Debreu, with a search for equilibrium *decision rules*.
+
+Such rules specify current actions as functions of a small number of **state variables** that summarize the effects of past decisions and current information.
+
+As Prescott and Mehra put it, these equilibrium decision rules "must be time invariant in order to apply standard time series methods and this necessitates a recursive structure."
+
+That sentence is the bridge from Lucas and Prescott's theory to econometrics.
+
+In a recursive competitive equilibrium
+
+* the state variables should be of minimal dimension, indexing only the factors that can change over time
+* the state is observed, or is an invertible function of observables
+* the conditional distribution of next period's state given current decisions and the current state is time invariant
+* individual decision rules are optimal given equilibrium pricing functions, and markets clear
+
+Prescott and Mehra note that their structure "subsumes the structure considered in Lucas and Prescott's analysis of equilibrium investment under uncertainty."
+
+Their analysis also establishes optimality of recursive equilibria and supportability of Pareto optima "in a simpler and more direct way" than arguments that pass through equivalence with state-contingent equilibria.
+
+For us, the important point is that {prf:ref}`lp_theorem1` produces exactly the objects that rational expectations econometrics needs: time-invariant decision rules, driven by a Markov state, with cross-equation restrictions linking the parameters of the shock process to the parameters of the decision rules.
+
+## A computable version
+
+Let's now compute equilibria of a version of the model.
+
+We take the adjustment technology
+
+$$
+h(z) = (1 - \delta + z)^\alpha, \qquad 0 < \alpha \leq 1 ,
+$$
+
+which satisfies the Lucas-Prescott assumptions: $h$ is increasing and strictly concave for $\alpha < 1$, and $h(\delta) = 1$, so $\delta$ is the maintenance investment rate.
+
+When $\alpha = 1$ we recover the familiar linear accumulation equation $k_{t+1} = (1-\delta) k_t + x_t$.
+
+When $\alpha < 1$ there are adjustment costs.
+
+Note that $h'(\delta) = \alpha$, a fact we will use below.
+
+We take a linear inverse demand curve
+
+$$
+D(q, u) = a_0 + u - a_1 q ,
+$$
+
+which matches the demand curve in the lecture {doc}`rational_expectations` except that it is shifted by $u$.
+
+Consumer surplus is then
+
+$$
+s(k, u) = (a_0 + u) k - \frac{a_1}{2} k^2 .
+$$
+
+The demand shifter follows a Gaussian AR(1) process
+
+$$
+u_{t+1} = \rho u_t + \sigma \epsilon_{t+1}, \qquad \epsilon_{t+1} \sim N(0,1),
+$$
+
+which is an example that Lucas and Prescott themselves offer of a process satisfying their assumptions.
+
+We discretize it with the Tauchen method.
+
+Rather than choosing investment $x$ directly, it is convenient to let the planner choose next period's capital $k'$ on a grid, and to invert {eq}`lp_accumulation` to find the required investment
+
+$$
+x = k \left[ \left(\frac{k'}{k}\right)^{1/\alpha} - (1 - \delta) \right] .
+$$
+
+```{code-cell} ipython3
+Model = namedtuple("Model", "r β δ α a0 a1 k u P X feasible s")
+
+def create_model(r=0.05, δ=0.10, α=0.70, a0=1.0, a1=0.01,
+ ρ=0.9, σ=0.02, n_u=9, n_k=400, k_lo=20.0, k_hi=160.0):
+ "Discretize the Lucas-Prescott industry."
+ β = 1 / (1 + r)
+ mc = qe.markov.tauchen(n_u, ρ, σ)
+ u, P = mc.state_values, mc.P
+ k = np.linspace(k_lo, k_hi, n_k)
+ # investment needed to move from k (rows) to k' (columns)
+ X = k[:, None] * ((k[None, :] / k[:, None])**(1/α) - (1 - δ))
+ feasible = X >= 0
+ s = (a0 + u[None, :]) * k[:, None] - a1 * k[:, None]**2 / 2
+ return Model(r, β, δ, α, a0, a1, k, u, P, X, feasible, s)
+```
+
+We solve the planner's Bellman equation {eq}`lp_bellman` by value function iteration, with Howard policy improvement steps to speed convergence.
+
+```{code-cell} ipython3
+def solve_model(m, tol=1e-8, maxit=1000, howard=30):
+ "Solve the planning problem; return value function and policies."
+ n_k, n_u = len(m.k), len(m.u)
+ R = np.where(m.feasible, -m.X, -1e12)
+ rows, cols = np.arange(n_k)[:, None], np.arange(n_u)[None, :]
+ v = m.s.copy()
+
+ for it in range(maxit):
+ EV = v @ m.P.T # EV[k', u] = E[v(k', u') | u]
+ obj = R[:, :, None] + m.β * EV[None, :, :] # (k, k', u)
+ idx = obj.argmax(axis=1) # choice of k' given (k, u)
+ v_new = m.s + np.take_along_axis(obj, idx[:, None, :], axis=1)[:, 0, :]
+
+ for _ in range(howard): # policy evaluation steps
+ EV = v_new @ m.P.T
+ v_new = m.s + R[rows, idx] + m.β * EV[idx, cols]
+
+ if np.max(np.abs(v_new - v)) < tol:
+ v = v_new
+ break
+ v = v_new
+
+ k_next = m.k[idx]
+ x = np.take_along_axis(m.X, idx, axis=1)
+ return v, idx, k_next, x
+
+m = create_model()
+v, idx, k_next, x = solve_model(m)
+print(f"grid: {len(m.k)} capital points, {len(m.u)} demand states")
+```
+
+Let's look at the equilibrium investment policy and the law of motion for capital.
+
+```{code-cell} ipython3
+---
+mystnb:
+ figure:
+ caption: Investment policy and law of motion
+ name: fig-lp-policy
+---
+fig, axes = plt.subplots(1, 2, figsize=(12, 4.5))
+
+for j in [0, len(m.u)//2, len(m.u)-1]:
+ axes[0].plot(m.k, x[:, j], label=f'$u = {m.u[j]:.3f}$')
+ axes[1].plot(m.k, k_next[:, j], label=f'$u = {m.u[j]:.3f}$')
+
+axes[0].plot(m.k, m.δ * m.k, 'k--', lw=1, label=r'$\delta k$')
+axes[0].set_xlabel('$k$'); axes[0].set_ylabel('$x(k, u)$')
+axes[0].set_title('investment policy')
+axes[1].plot(m.k, m.k, 'k--', lw=1, label='45 degree line')
+axes[1].set_xlabel('$k$'); axes[1].set_ylabel("$k'(k, u)$")
+axes[1].set_title('law of motion for capital')
+for ax in axes:
+ ax.legend()
+plt.tight_layout()
+plt.show()
+```
+
+Capital rises when $x(k,u)$ lies above the maintenance line $\delta k$ and falls when it lies below.
+
+Higher demand shifts the investment policy up, so the capital stock that the industry sustains is higher when demand is strong.
+
+### The price of installed capital
+
+The planner's problem also delivers the market value $w$ of a unit of installed capital that appeared in {eq}`lp_firmvalue`.
+
+Let $z = x/k$ denote the investment rate.
+
+Differentiating the Bellman equation {eq}`lp_bellman` and using the envelope condition gives
+
+$$
+w(k,u) = v_k(k, u) = D(k,u) + \beta \mathbb{E}\left[ v_k(k', u') \mid u \right] \left[ h(z) - z h'(z) \right],
+$$
+
+while the first-order condition for $x$ is
+
+```{math}
+:label: lp_planner_foc
+\beta \mathbb{E}\left[ v_k(k', u') \mid u \right] = \frac{1}{h'(z)} .
+```
+
+Combining them expresses the shadow price in closed form,
+
+```{math}
+:label: lp_shadow
+w(k,u) = D(k,u) + \frac{h(z)}{h'(z)} - z .
+```
+
+The marginal value of installed capital equals the current price of output plus the value of the capacity that the unit carries into the future.
+
+Notice that {eq}`lp_planner_foc` is the planner's counterpart of the firm's first-order condition {eq}`lp_firmfoc`, with $w^* = \mathbb{E}[v_k(k',u') \mid u]$.
+
+That correspondence is the "big $K$, little $k$" logic of the lecture {doc}`rational_expectations` in its Lucas-Prescott form.
+
+```{code-cell} ipython3
+h = lambda z, m: (1 - m.δ + z)**m.α
+h_prime = lambda z, m: m.α * (1 - m.δ + z)**(m.α - 1)
+
+z = x / m.k[:, None]
+D = m.a0 + m.u[None, :] - m.a1 * m.k[:, None]
+w = D + h(z, m) / h_prime(z, m) - z
+
+# check the first-order condition (up to grid error)
+Ew = np.take_along_axis(w @ m.P.T, idx, axis=0)
+resid = np.abs(m.β * Ew - 1 / h_prime(z, m))
+scale = np.median(1 / h_prime(z, m))
+near = (m.k > 70) & (m.k < 95) # capital levels the industry actually visits
+print(f"typical size of each side of the FOC: {scale:.3f}")
+print(f"median residual, all k: {np.median(resid):.2e}")
+print(f"median residual, 70 < k < 95: {np.median(resid[near]):.2e}")
+```
+
+The residual is a few tenths of one per cent of the magnitude of the terms being compared, which confirms {eq}`lp_shadow`.
+
+It does not vanish entirely because the planner chooses $k'$ from a finite grid, so the policy function jumps by a whole grid point at a time.
+
+Residuals are much larger at capital levels so extreme that the industry never visits them.
+
+## Long run behavior with serially independent demand
+
+Lucas and Prescott next ask what happens in the long run.
+
+They treat two cases, and the first is the special case in which $u_t$ and $u_s$ are independent for $s \neq t$.
+
+Inspecting the Bellman equation {eq}`lp_bellman` when $p(dz,u)$ does not depend on $u$ shows that the optimal investment rate $x(k,u)$ *does not depend on $u$*.
+
+A demand shift is then a pure windfall: it tells firms nothing about future demand, so it does not change investment.
+
+Consequently the capital stock evolves *deterministically*, according to $k_{t+1} = k_t h(x(k_t)/k_t)$, while output is supplied inelastically and demand shocks move only prices.
+
+````{prf:theorem}
+:label: lp_theorem2
+
+Under independence, there are two possibilities for the capital stock.
+
+If
+
+```{math}
+:label: lp_existence_iid
+\int D(0, u) p(du) > \delta + \frac{r}{h'(\delta)} ,
+```
+
+and $k_0 > 0$, then $k_t$ converges monotonically to the unique stationary value $k^c$ given implicitly by
+
+```{math}
+:label: lp_kc
+\int D(k^c, u) p(du) = \delta + \frac{r}{h'(\delta)} .
+```
+
+Otherwise capital converges monotonically to zero.
+````
+
+Condition {eq}`lp_kc` has a familiar interpretation.
+
+The left side is expected marginal revenue product of capital, which here is just the expected output price, because the marginal physical product is one.
+
+The right side is a **user cost of capital**: a depreciation term $\delta$ plus an interest term $r/h'(\delta)$.
+
+Lucas and Prescott observe that this case corresponds closely to the textbook dichotomy between short-run and long-run supply.
+
+In the short run, capacity is fixed and demand determines price.
+
+In the long run, demand fluctuations play no role at all: capacity is determined entirely by *average* demand.
+
+Let's verify this numerically by setting $\rho = 0$.
+
+```{code-cell} ipython3
+m_iid = create_model(ρ=0.0)
+v_iid, idx_iid, k_next_iid, x_iid = solve_model(m_iid)
+
+# does the policy depend on u?
+print("investment policy independent of u:",
+ np.allclose(x_iid, x_iid[:, [0]], atol=1e-10))
+
+# stationary capital: where x(k) crosses δ k
+def stationary_k(x_col, m):
+ "Capital where investment just maintains capacity."
+ d = x_col - m.δ * m.k
+ i = np.where(np.sign(d[:-1]) != np.sign(d[1:]))[0]
+ if len(i) == 0:
+ return np.nan
+ i = i[0]
+ return np.interp(0, [d[i+1], d[i]], [m.k[i+1], m.k[i]])
+
+kc = stationary_k(x_iid[:, 0], m_iid)
+user_cost = m_iid.δ + m_iid.r / h_prime(m_iid.δ, m_iid)
+print(f"\nstationary capital k^c = {kc:.3f}")
+print(f"expected price at k^c = {m_iid.a0 - m_iid.a1 * kc:.5f}")
+print(f"user cost δ + r / h'(δ) = {user_cost:.5f}")
+```
+
+The stationary capital stock equates the expected price to the user cost of capital, as {eq}`lp_kc` requires.
+
+Now let's confirm that capital approaches $k^c$ monotonically, and from either direction.
+
+```{code-cell} ipython3
+---
+mystnb:
+ figure:
+ caption: Capital paths under IID demand
+ name: fig-lp-iid-paths
+---
+def capital_path(m, idx, k0, T=60, u_index=None):
+ "Simulate capital, holding the demand state fixed if u_index is given."
+ ki = np.abs(m.k - k0).argmin()
+ path = np.empty(T)
+ j = len(m.u) // 2 if u_index is None else u_index
+ for t in range(T):
+ path[t] = m.k[ki]
+ ki = idx[ki, j]
+ return path
+
+fig, ax = plt.subplots(figsize=(8, 4.5))
+for k0 in (30.0, 55.0, 110.0, 150.0):
+ ax.plot(capital_path(m_iid, idx_iid, k0), lw=2, label=f'$k_0 = {k0:.0f}$')
+ax.axhline(kc, color='k', ls='--', lw=1, label='$k^c$')
+ax.set_xlabel('$t$'); ax.set_ylabel('$k_t$')
+ax.legend()
+plt.tight_layout()
+plt.show()
+```
+
+Convergence is monotone and the limit does not depend on the initial capital stock.
+
+## Long run behavior with serially correlated demand
+
+The more interesting case allows demand shifts to be positively serially correlated, so that a high demand today signals high demand tomorrow.
+
+Now the current demand state *does* affect investment, and the capital stock is genuinely stochastic.
+
+To characterize the long run, Lucas and Prescott impose additional restrictions on the $\{u_t\}$ process, whose purpose is to guarantee that the distribution of $(k_t, u_t)$ settles down.
+
+In words, they assume that
+
+* from any current $u$, next period's shock lands in any non-degenerate interval with positive probability
+* $u_t$ has a limiting distribution that does not depend on the initial $u_0$ and that puts positive probability on every non-degenerate interval
+* $\mathbb{P}\{u_{t+1} \geq x \mid u_t\}$ is strictly increasing in $u_t$, so high demand today always signals high demand tomorrow
+* consumer surplus $s(k,u)$ converges uniformly as $u \to \pm\infty$
+
+A Gaussian AR(1) process with $0 < \rho < 1$ satisfies these conditions, which is the example they give and the one we simulate.
+
+The analysis then proceeds by bounding the capital stock.
+
+Let $\bar v(k)$ and $\underline v(k)$ be the limits of the expected value function as $u \to \infty$ and $u \to -\infty$, and let $\bar x(k)$ and $\underline x(k)$ be the associated investment policies.
+
+Because investment is increasing in $u$, these bracket the policy for every $u$.
+
+Let $\bar k$ solve $\bar x(k) = \delta k$ and let $\underline k$ solve $\underline x(k) = \delta k$.
+
+These are the capital stocks that would be sustained under permanently maximal and permanently minimal demand.
+
+Lucas and Prescott then prove that
+
+* the sets $(0, \underline k)$ and $(\bar k, \infty)$, paired with any demand state, are **transient**: once the industry leaves them it does not return, and from any starting point it enters $(\underline k, \bar k)$ with probability approaching one
+* the set $B = (\underline k, \bar k) \times E$, where $E$ is the set of possible values of $u$, is a **single ergodic set**
+
+```{prf:theorem}
+:label: lp_theorem3
+
+If $B$ is non-empty, then for all $(k,u)$ and every initial state $(k_0, u_0)$,
+
+$$
+\lim_{t \to \infty} \mathbb{P}\{ k_t \leq k, u_t \leq u \mid k_0, u_0 \} = P(k,u)
+$$
+
+exists and *does not depend on $(k_0, u_0)$*.
+
+The function $P$ is a probability distribution that assigns probability zero to the transient sets and positive probability to every subset of $B$ with positive area.
+```
+
+```{prf:theorem}
+:label: lp_theorem4
+
+If $B$ is non-empty, then for any initial state, with probability one
+
+$$
+\lim_{T \to \infty} \frac{1}{T}\sum_{t=1}^T k_t = k^* ,
+$$
+
+where $k^*$ is the mean of $k$ under the invariant distribution $P$.
+```
+
+The ergodic set is non-empty -- and so this long-run behavior applies -- if and only if
+
+```{math}
+:label: lp_existence
+\lim_{u \to \infty} D(0, u) > \delta + \frac{r}{h'(\delta)} ,
+```
+
+which says that demand must sometimes be strong enough to justify holding any capital at all.
+
+{prf:ref}`lp_theorem3` and {prf:ref}`lp_theorem4` are the results that make this model an object that econometricians can use.
+
+The first says that the model implies a well-defined stationary probability distribution for the observable time series.
+
+The second says that sample averages computed from a single long realization converge to the corresponding population moments of that distribution.
+
+Let's compute the bounds $\underline k$ and $\bar k$ for our parameterization and check that simulations behave as the theorems say.
+
+```{code-cell} ipython3
+bounds = np.array([stationary_k(x[:, j], m) for j in range(len(m.u))])
+k_lo_star, k_hi_star = bounds.min(), bounds.max()
+print(f"conditional stationary capital, lowest demand state: {k_lo_star:.2f}")
+print(f"conditional stationary capital, highest demand state: {k_hi_star:.2f}")
+print(f"ergodic set for capital: ({k_lo_star:.2f}, {k_hi_star:.2f})")
+```
+
+Now we simulate the equilibrium Markov process from two very different initial capital stocks, using the *same* sequence of demand shocks.
+
+```{code-cell} ipython3
+---
+mystnb:
+ figure:
+ caption: Capital paths entering the ergodic set
+ name: fig-lp-ergodic-paths
+---
+def simulate(m, idx, k0, T=20_000, seed=0):
+ "Simulate the equilibrium Markov process for (k, u)."
+ mc = qe.MarkovChain(m.P, m.u)
+ u_idx = mc.simulate_indices(T, init=len(m.u)//2, random_state=seed)
+ ki = np.abs(m.k - k0).argmin()
+ k_path = np.empty(T)
+ for t in range(T):
+ k_path[t] = m.k[ki]
+ ki = idx[ki, u_idx[t]]
+ p_path = m.a0 + m.u[u_idx] - m.a1 * k_path
+ return k_path, p_path
+
+k_low, p_low = simulate(m, idx, k0=30.0, seed=1)
+k_high, p_high = simulate(m, idx, k0=150.0, seed=1)
+
+fig, ax = plt.subplots(figsize=(9, 4.5))
+ax.plot(k_low[:250], lw=2, label='$k_0 = 30$')
+ax.plot(k_high[:250], lw=2, label='$k_0 = 150$')
+ax.axhline(k_lo_star, color='k', ls='--', lw=1)
+ax.axhline(k_hi_star, color='k', ls='--', lw=1, label='ergodic set')
+ax.set_xlabel('$t$'); ax.set_ylabel('$k_t$')
+ax.legend()
+plt.tight_layout()
+plt.show()
+```
+
+Both paths are drawn into the ergodic set and then fluctuate inside it forever.
+
+The next figure compares the long-run distributions of capital computed from the two simulations, after discarding a burn-in sample.
+
+```{code-cell} ipython3
+---
+mystnb:
+ figure:
+ caption: Invariant distributions of capital and price
+ name: fig-lp-invariant
+---
+burn = 2000
+fig, axes = plt.subplots(1, 2, figsize=(12, 4.5))
+
+axes[0].hist(k_low[burn:], bins=60, density=True, alpha=0.5, label='from $k_0 = 30$')
+axes[0].hist(k_high[burn:], bins=60, density=True, alpha=0.5, label='from $k_0 = 150$')
+axes[0].set_xlabel('$k$'); axes[0].set_ylabel('density')
+axes[0].set_title('invariant distribution of capital')
+axes[0].legend()
+
+axes[1].hist(p_low[burn:], bins=60, density=True, alpha=0.5)
+axes[1].set_xlabel('$p$'); axes[1].set_ylabel('density')
+axes[1].set_title('invariant distribution of price')
+
+plt.tight_layout()
+plt.show()
+
+print(f"mean capital from k_0 = 30: {k_low[burn:].mean():.3f}")
+print(f"mean capital from k_0 = 150: {k_high[burn:].mean():.3f}")
+print(f"range visited: ({k_low[burn:].min():.2f}, {k_low[burn:].max():.2f})")
+```
+
+The two histograms coincide, as {prf:ref}`lp_theorem3` promises, and the capital stock stays inside the ergodic set.
+
+Finally, here is {prf:ref}`lp_theorem4` in action: time averages from a single realization converge to the mean of the invariant distribution.
+
+```{code-cell} ipython3
+---
+mystnb:
+ figure:
+ caption: Time average of capital
+ name: fig-lp-time-average
+---
+running_mean = np.cumsum(k_low) / np.arange(1, len(k_low) + 1)
+
+fig, ax = plt.subplots(figsize=(8, 4.5))
+ax.plot(running_mean, lw=2)
+ax.axhline(k_low[burn:].mean(), color='k', ls='--', lw=1, label='$k^*$')
+ax.set_xlabel('$T$'); ax.set_ylabel(r'$T^{-1}\sum_{t \leq T} k_t$')
+ax.set_xscale('log')
+ax.legend()
+plt.tight_layout()
+plt.show()
+```
+
+## Relation to the rational expectations lecture
+
+It is worth collecting the correspondences between this lecture and {doc}`rational_expectations`.
+
+| | {doc}`rational_expectations` | this lecture |
+|---|---|---|
+| uncertainty | none | Markov demand shifter $u_t$ |
+| adjustment costs | quadratic, $\gamma (y'-y)^2/2$ | concave technology $k' = k h(x/k)$ |
+| equilibrium object | belief $H$ with $Y' = H(Y)$ | price process $\{p_t\}$, equivalently policy $x(k,u)$ |
+| equilibrium concept | $H$ is a fixed point of $\Phi$ | anticipated price distribution equals actual |
+| how it is computed | planning problem, solved as an LQ problem | planning problem, solved by dynamic programming |
+| what the planner maximizes | consumer plus producer surplus | discounted consumer surplus {eq}`lp_surplus` |
+| equilibrium dynamics | $Y_{t+1} = \kappa_0 + \kappa_1 Y_t$ | Markov process for $(k_t, u_t)$ |
+| long-run behavior | convergence to a steady state | convergence to an invariant distribution |
+
+The deepest common element is the strategy for computing an equilibrium.
+
+In both lectures, the direct approach -- guess a law of motion, compute the induced best response, and iterate -- is unreliable, because that mapping need not be a contraction.
+
+In both lectures, the remedy is to find a planning problem whose Euler equations coincide with the equilibrium conditions, and then to solve the planning problem by dynamic programming.
+
+The lecture {doc}`rational_expectations` verifies this correspondence by matching Euler equations for a particular linear-quadratic example.
+
+{prf:ref}`lp_theorem1` is the general statement: for this class of economies, the set of competitive equilibria and the set of solutions of the planning problem coincide, and both are singletons.
+
+What the baby version cannot show, because it has no uncertainty, is the payoff that Lucas and Prescott were after: an equilibrium that is a *stationary stochastic process*, with an invariant distribution and ergodic time averages.
+
+That is what makes it possible to confront such a model with data, and what led on to rational expectations econometrics.
+
+The companion lecture {doc}`optimal_growth_uncertainty` pursues exactly this theme in a one-sector growth model.
+
+{cite:t}`BrockMirman1972` prove there the counterparts of {prf:ref}`lp_theorem3` and {prf:ref}`lp_theorem4`: the distribution of capital converges to an invariant distribution that does not depend on initial conditions, and time averages along a single realization converge to population moments.
+
+That lecture also shows what the shadow price of capital in such a planning problem becomes in a competitive equilibrium -- namely Tobin's $q$ -- and examines a subtle question about the differentiability of the value function that the answer depends on.
+
+## Exercises
+
+```{exercise}
+:label: lp_ex1
+
+The user cost of capital in {eq}`lp_kc` depends on the curvature parameter $\alpha$ of the adjustment technology through $h'(\delta) = \alpha$.
+
+1. Explain why a *lower* $\alpha$ -- meaning stronger adjustment costs -- should reduce the long-run capital stock.
+1. For the serially independent case, compute the stationary capital stock $k^c$ for $\alpha \in \{0.4, 0.6, 0.8, 1.0\}$ and verify in each case that the marginal condition {eq}`lp_kc` holds.
+1. Confirm that when $\alpha = 1$ the accumulation equation is $k_{t+1} = (1-\delta)k_t + x_t$ and the user cost is the textbook $\delta + r$.
+```
+
+```{solution-start} lp_ex1
+:class: dropdown
+```
+
+A lower $\alpha$ makes $h$ more concave, so a unit of investment buys less capacity at the margin.
+
+Since $h'(\delta) = \alpha$, the interest component of the user cost, $r / h'(\delta) = r/\alpha$, rises as $\alpha$ falls.
+
+A higher user cost must be matched by a higher expected price, and since demand slopes down, that means a smaller capital stock.
+
+```{code-cell} ipython3
+print(f"{'α':>5} {'k^c':>10} {'E[price]':>12} {'user cost':>12}")
+for α in (0.4, 0.6, 0.8, 1.0):
+ m_α = create_model(ρ=0.0, α=α, k_lo=5.0, k_hi=160.0, n_k=600)
+ _, _, _, x_α = solve_model(m_α)
+ kc_α = stationary_k(x_α[:, 0], m_α)
+ price = m_α.a0 - m_α.a1 * kc_α
+ cost = m_α.δ + m_α.r / h_prime(m_α.δ, m_α)
+ print(f"{α:>5.1f} {kc_α:>10.3f} {price:>12.5f} {cost:>12.5f}")
+```
+
+Stronger adjustment costs (lower $\alpha$) do indeed lower the long-run capital stock.
+
+With $\alpha = 1$ we have $h(z) = 1 - \delta + z$, so $k' = k(1 - \delta + x/k) = (1-\delta)k + x$, and $h'(\delta) = 1$, so the user cost is $\delta + r$.
+
+```{solution-end}
+```
+
+```{exercise}
+:label: lp_ex2
+
+{prf:ref}`lp_theorem1` says that the planner's policy *is* the competitive equilibrium.
+
+Verify this numerically, using the "big $K$, little $k$" logic of {doc}`rational_expectations`.
+
+Solve the problem of an individual price-taking firm that
+
+* owns capital $k_i$ and chooses $k_i'$ subject to the same accumulation technology
+* takes as given the aggregate capital stock $K$, which evolves according to the planner's policy computed above
+* takes as given the price $p = a_0 + u - a_1 K$, which depends on aggregate, not own, capital
+
+Then check that when the firm's own capital equals aggregate capital, $k_i = K$, the firm chooses exactly what the planner chooses.
+
+Use a coarser grid for the firm's own capital to keep the computation small.
+```
+
+```{solution-start} lp_ex2
+:class: dropdown
+```
+
+The firm's Bellman equation is
+
+$$
+v_i(k_i, K, u) = \max_{k_i'} \left\{ p(K,u) k_i - x(k_i, k_i')
+ + \beta \mathbb{E}\left[ v_i(k_i', K', u') \mid u \right] \right\}
+$$
+
+where $K' $ follows the planner's law of motion.
+
+Note that the firm's own capital affects its revenue but not the price.
+
+```{code-cell} ipython3
+def firm_problem(m, idx_agg, n_i=80, tol=1e-8, maxit=1000, howard=20):
+ "Solve an individual firm's problem taking the aggregate law of motion as given."
+ sub = np.linspace(0, len(m.k) - 1, n_i).astype(int) # firm grid ⊂ aggregate grid
+ ki = m.k[sub]
+ n_K, n_u = len(m.k), len(m.u)
+
+ Xi = ki[:, None] * ((ki[None, :] / ki[:, None])**(1/m.α) - (1 - m.δ))
+ Ri = np.where(Xi >= 0, -Xi, -1e12) # (k_i, k_i')
+ price = m.a0 + m.u[None, :] - m.a1 * m.k[:, None] # (K, u)
+ revenue = ki[:, None, None] * price[None, :, :] # (k_i, K, u)
+
+ v_i = np.zeros((n_i, n_K, n_u))
+ u_cols = np.arange(n_u)[None, :]
+ for it in range(maxit):
+ EV = np.tensordot(v_i, m.P, axes=([2], [1])) # E[v_i(k_i', K', u') | u]
+ cont = EV[:, idx_agg, u_cols] # impose K' = planner's choice
+ obj = Ri[:, :, None, None] + m.β * cont[None, :, :, :]
+ pol = obj.argmax(axis=1)
+ v_new = revenue + np.take_along_axis(obj, pol[:, None, :, :], axis=1)[:, 0, :, :]
+
+ for _ in range(howard):
+ EV = np.tensordot(v_new, m.P, axes=([2], [1]))
+ cont = EV[:, idx_agg, u_cols]
+ v_new = (revenue + Ri[np.arange(n_i)[:, None, None], pol]
+ + m.β * np.take_along_axis(cont, pol, axis=0))
+
+ if np.max(np.abs(v_new - v_i)) < tol:
+ v_i = v_new
+ break
+ v_i = v_new
+
+ return ki, sub, pol
+
+ki, sub, pol_firm = firm_problem(m, idx)
+
+# compare the firm's choice with the planner's, evaluated at k_i = K
+gaps = []
+for a, K_i in enumerate(sub):
+ for j in range(len(m.u)):
+ gaps.append(abs(ki[pol_firm[a, K_i, j]] - m.k[idx[K_i, j]]))
+gaps = np.array(gaps)
+
+print(f"firm grid spacing: {np.diff(ki).mean():.3f}")
+print(f"mean |firm choice - planner choice|: {gaps.mean():.3f}")
+print(f"max |firm choice - planner choice|: {gaps.max():.3f}")
+```
+
+The discrepancies are smaller than the spacing of the firm's own capital grid.
+
+So the price-taking firm, responding optimally to the price process that the planner's allocation generates, chooses to do exactly what the planner does.
+
+That is the content of {prf:ref}`lp_theorem1`, and it is the Lucas-Prescott counterpart of the fixed point condition $H(Y) = h(Y,Y)$ in {doc}`rational_expectations`.
+
+```{solution-end}
+```
+
+```{exercise}
+:label: lp_ex3
+
+{prf:ref}`lp_theorem3` says that the invariant distribution does not depend on initial conditions, but it says nothing about how *wide* that distribution is.
+
+Investigate how serial correlation in demand affects the ergodic set.
+
+1. For $\rho \in \{0.0, 0.5, 0.9, 0.98\}$, compute the ergodic bounds $\underline k$ and $\bar k$.
+1. Simulate each economy and compare the invariant distributions of capital.
+1. Explain the pattern. Why does the $\rho = 0$ case produce a degenerate distribution for capital?
+```
+
+```{solution-start} lp_ex3
+:class: dropdown
+```
+
+Here is one solution.
+
+```{code-cell} ipython3
+fig, ax = plt.subplots(figsize=(9, 4.5))
+print(f"{'ρ':>6} {'k_lo':>9} {'k_hi':>9} {'width':>9} {'std(k)':>9}")
+
+for ρ in (0.0, 0.5, 0.9, 0.98):
+ m_ρ = create_model(ρ=ρ)
+ _, idx_ρ, _, x_ρ = solve_model(m_ρ)
+ b = np.array([stationary_k(x_ρ[:, j], m_ρ) for j in range(len(m_ρ.u))])
+ k_ρ, _ = simulate(m_ρ, idx_ρ, k0=80.0, seed=3)
+ print(f"{ρ:>6.2f} {b.min():>9.2f} {b.max():>9.2f} "
+ f"{b.max()-b.min():>9.2f} {k_ρ[2000:].std():>9.3f}")
+ if ρ > 0: # the ρ = 0 distribution is a spike at k^c, so we omit it here
+ ax.hist(k_ρ[2000:], bins=50, density=True, alpha=0.45, label=f'$\\rho = {ρ}$')
+
+ax.set_xlabel('$k$'); ax.set_ylabel('density')
+ax.legend()
+plt.tight_layout()
+plt.show()
+```
+
+The more persistent is demand, the wider the ergodic set and the more dispersed the invariant distribution of capital.
+
+(The figure omits $\rho = 0$, whose distribution is a spike at $k^c$ that would dwarf the others.)
+
+The reason is the one Lucas and Prescott emphasize.
+
+Investment responds to *news about future demand*, not to current demand as such.
+
+When $\rho = 0$, a demand shift conveys no information about the future, so investment does not respond at all, and capital converges to the single deterministic value $k^c$ of {prf:ref}`lp_theorem2`: the invariant distribution of capital is degenerate even though prices keep fluctuating.
+
+As $\rho$ rises, a high demand state signals a sustained period of high prices, so firms invest more, and the capital stock inherits the persistence of demand.
+
+```{solution-end}
+```
diff --git a/lectures/optimal_growth_uncertainty.md b/lectures/optimal_growth_uncertainty.md
new file mode 100644
index 000000000..6d812bc2a
--- /dev/null
+++ b/lectures/optimal_growth_uncertainty.md
@@ -0,0 +1,854 @@
+---
+jupytext:
+ text_representation:
+ extension: .md
+ format_name: myst
+ format_version: 0.13
+kernelspec:
+ display_name: Python 3
+ language: python
+ name: python3
+---
+
+(optimal_growth_uncertainty)=
+```{raw} jupyter
+
+```
+
+# Optimal Growth Under Uncertainty and Tobin's q
+
+```{contents} Contents
+:depth: 2
+```
+
+## Overview
+
+This lecture studies two papers.
+
+The first is {cite:t}`BrockMirman1972`, a classic analysis of optimal one-sector growth when the production function is hit by random shocks.
+
+The second is {cite:t}`Sargent1980q`, which adds one small ingredient -- **irreversible investment** -- and uses the result to think about James Tobin's $q$ theory of investment.
+
+The lecture {doc}`lucas_prescott_investment` studied a competitive industry whose equilibrium is the solution of a planning problem, and whose equilibrium is a Markov process with an invariant distribution.
+
+Brock and Mirman ask the same questions about a one-sector growth model:
+
+* does the planning problem have a well-behaved solution, with continuous and monotone policy functions?
+* the optimal policy makes capital a Markov process; does that process have an *invariant distribution*?
+* does the distribution of capital converge to it from *any* initial condition?
+* do *time averages* computed from a single realization converge to population moments?
+
+The last two questions are the reason both papers matter for econometrics.
+
+A model that answers them affirmatively delivers a stationary, ergodic stochastic process for observable time series.
+
+Sample moments computed from one long realization then estimate population moments, which is exactly what the rational expectations econometrics of {cite:t}`HanSar1980` requires.
+
+{cite:t}`Sargent1980q` puts the Brock-Mirman apparatus to work on a question in macroeconomics: when, and in what sense, is there an investment demand schedule relating investment to Tobin's $q$?
+
+Along the way, this lecture pauses over a technical issue that turns out to be central:
+
+* the derivative of the planner's value function with respect to capital *is* the competitive price of used capital, i.e. it is essentially Tobin's $q$
+* so the analysis stands or falls on whether that derivative exists
+* irreversible investment creates a **corner**, and at a corner the standard argument for differentiability breaks down
+
+We'll describe the difficulty, note a gap in the published argument, and give a corrected proof.
+
+Let's start with some imports:
+
+```{code-cell} ipython3
+import numpy as np
+import matplotlib.pyplot as plt
+from collections import namedtuple
+```
+
+## The Brock-Mirman planning problem
+
+A planner chooses consumption to maximize
+
+```{math}
+:label: bm_objective
+\mathbb{E}_0 \sum_{t=0}^\infty \beta^t u(c_t), \qquad 0 < \beta < 1,
+```
+
+subject to
+
+$$
+c_t + i_t \leq f(k_t, r_t), \qquad c_t \geq 0, \quad i_t \geq 0 ,
+$$
+
+where $k_t$ is capital per worker, $i_t$ is investment, and $\{r_t\}$ is a sequence of independent and identically distributed shocks to production.
+
+Brock and Mirman assume that for each realization of the shock, $f(\cdot, r)$ is increasing, strictly concave, and satisfies the Inada conditions
+
+$$
+f(0, r) = 0, \qquad f'(0, r) = +\infty, \qquad f'(\infty, r) = 0 ,
+$$
+
+and that $f$ is increasing in $r$, so that a higher shock means more output.
+
+The period utility function $u$ is increasing, strictly concave, and differentiable.
+
+In their formulation capital depreciates fully in one period, so that $k_{t+1} = i_t$ and current resources are $s_t = f(k_{t-1}, r_{t-1})$.
+
+The Bellman equation is
+
+```{math}
+:label: bm_bellman
+v(s) = \max_{0 \leq c \leq s} \left\{ u(c) + \beta \int v\bigl(f(s - c, r)\bigr) \, \nu(dr) \right\} ,
+```
+
+where $\nu$ is the distribution of the shock.
+
+Standard arguments -- a contraction mapping, plus preservation of monotonicity and concavity -- give a unique bounded solution $v$, attained by a unique consumption policy $c = g(s)$ and investment policy $x = h(s) = s - g(s)$.
+
+```{prf:proposition}
+:label: bm_policies
+
+The optimal policies $g$ and $h$ are increasing and continuous, with $g(0) = h(0) = 0$.
+```
+
+Brock and Mirman prove monotonicity from the first-order condition
+
+```{math}
+:label: bm_euler
+u'(g(s)) = \beta \int u'\bigl(g(f(s - g(s), r))\bigr) \, f'(s - g(s), r) \, \nu(dr) ,
+```
+
+which is the stochastic analogue of the Euler equation.
+
+If $g$ did not increase with $s$, the left side of {eq}`bm_euler` would stay constant while the right side would fall, because $f$ increases and $u'$ and $f'$ decrease.
+
+## Long-run behavior
+
+The optimal policy makes capital a Markov process,
+
+```{math}
+:label: bm_markov
+k_{t+1} = h\bigl(f(k_t, r_t)\bigr) ,
+```
+
+and Brock and Mirman devote most of their paper to the long-run behavior of this process.
+
+The strategy resembles the one used in {doc}`lucas_prescott_investment`.
+
+Consider the deterministic difference equations obtained by fixing the shock at its lowest possible value $\underline r$ and at its highest possible value $\bar r$:
+
+$$
+k_{t+1} = h(f(k_t, \underline r)), \qquad k_{t+1} = h(f(k_t, \bar r)) .
+$$
+
+Let $\underline k$ be a positive fixed point of the first and $\bar k$ a positive fixed point of the second.
+
+Because $f$ is increasing in the shock and $h$ is increasing, $\underline k \leq \bar k$.
+
+Brock and Mirman say that the model has a **stable configuration of fixed points** when $\underline k$ and $\bar k$ are positive and $\underline k < \bar k$.
+
+They then show that
+
+* the sets of capital stocks below $\underline k$ and above $\bar k$ are **transient**: the process leaves them and does not return
+* the interval $[\underline k, \bar k]$ is where the process eventually lives
+
+```{prf:theorem}
+:label: bm_theorem
+
+There is a distribution function $F$ such that the distribution $F_t$ of $k_t$ converges to $F$ uniformly, and $F$ does not depend on the initial capital stock.
+```
+
+{prf:ref}`bm_theorem` is the counterpart of the invariant-distribution theorem of {doc}`lucas_prescott_investment`.
+
+An important part of the proof is an argument about the **inverse optimal process**, which runs the Markov process backwards in time; Brock and Mirman use it to show that a stationary distribution exists and is unique without appealing to heavier machinery from probability theory.
+
+Convergence of distributions is not by itself enough for econometrics.
+
+What an econometrician needs in addition is a **mean-ergodic theorem**: a guarantee that averages computed along a single realization converge to moments of $F$,
+
+```{math}
+:label: bm_ergodic
+\frac{1}{T}\sum_{t=1}^T \phi(k_t) \to \int \phi \, dF \qquad \text{with probability one} .
+```
+
+For Markov processes with a unique invariant distribution and a stable configuration of fixed points, such laws of large numbers are available; {cite:t}`Sargent1980q` invokes the version in Doob's book to justify computing population moments of his model and comparing them with sample moments.
+
+This is the bridge from Brock and Mirman's theory to the rational expectations econometrics developed in the late 1970s and early 1980s.
+
+Without {prf:ref}`bm_theorem` and {eq}`bm_ergodic`, a likelihood function computed from a single time series would have no firm justification.
+
+```{note}
+{cite:t}`BrockMirman1972` study the case in which the shocks are independent and identically distributed.
+
+The lecture {doc}`lucas_prescott_investment` describes a parallel set of results for a model in which the shock is serially correlated.
+
+In both cases the economics is the same: the state must eventually wander inside a compact set on which the process is well behaved, and the boundaries of that set are the stationary points associated with the most and least favorable shocks.
+```
+
+## Irreversible investment and Tobin's q
+
+{cite:t}`Sargent1980q` modifies the model in one respect: capital, once installed, cannot be eaten.
+
+Output can be consumed or added to the capital stock, but the conversion does not run backwards,
+
+```{math}
+:label: q_irreversible
+K_{t+1} = (1 - \delta) K_t + I_t, \qquad I_t \geq 0 ,
+```
+
+where $0 < \delta < 1$ is the depreciation rate.
+
+Production is $y_t = f(K_t)\theta_t$, and the one-period utility function $u(c_t, e_t)$ is hit by a preference shock $e_t$.
+
+The shocks $(\theta_t, e_t)$ are independent and identically distributed over time.
+
+Why does this small change matter?
+
+In the model with reversible investment, the price of a unit of installed capital always equals the price of a unit of newly produced output, so Tobin's $q$ is identically one and firms have no investment demand schedule at all.
+
+The irreversibility constraint is a **friction** that lets the price of installed capital fall below the price of new capital.
+
+Sargent describes a competitive economy in which households own capital, rent it to firms, and trade claims to installed capital at a relative price $p_{Kt}$, which is Tobin's $q$.
+
+Following {cite:t}`Lucas_Prescott_1971` -- exactly the strategy of {doc}`lucas_prescott_investment` -- he studies the competitive equilibrium indirectly, through the planning problem that generates it.
+
+The planner solves
+
+```{math}
+:label: q_bellman
+v(K, \theta, e) = \max_{K' \geq (1-\delta)K}
+\left\{ u\bigl(f(K)\theta + (1-\delta)K - K', e\bigr)
++ \beta \mathbb{E}\bigl[v(K', \theta', e')\bigr] \right\} .
+```
+
+Let $\lambda \geq 0$ be the multiplier on the irreversibility constraint.
+
+The first-order condition is
+
+```{math}
+:label: q_foc
+u_c(c, e) = \beta \mathbb{E}\bigl[v_K(K', \theta', e')\bigr] + \lambda ,
+\qquad \lambda \geq 0, \quad \lambda I = 0 ,
+```
+
+and the price of installed capital is
+
+```{math}
+:label: q_definition
+q = \frac{\beta \mathbb{E}\bigl[v_K(K', \theta', e')\bigr]}{u_c(c,e)} = 1 - \frac{\lambda}{u_c(c,e)} .
+```
+
+So this model implies
+
+* $q \leq 1$ always
+* $q = 1$ exactly when investment is positive
+* $q < 1$ exactly when the irreversibility constraint binds, which is when investment is zero
+
+Notice what {eq}`q_definition` says: *Tobin's $q$ is the derivative of the planner's value function*, normalized by marginal utility.
+
+Everything therefore depends on whether $v_K$ exists.
+
+## Differentiability of the value function
+
+Here is the difficulty.
+
+The standard tool for differentiability of a value function is the theorem of {cite:t}`BenvenisteScheinkman1979`.
+
+```{prf:theorem} Benveniste-Scheinkman
+:label: bs_theorem
+
+Let $v$ be concave on an open set $D$ and let $K_0 \in D$.
+
+Suppose $W$ is concave, differentiable at $K_0$, and satisfies $W(K) \leq v(K)$ on a neighborhood of $K_0$, with $W(K_0) = v(K_0)$.
+
+Then $v$ is differentiable at $K_0$ and $v'(K_0) = W'(K_0)$.
+```
+
+The usual way to build such a $W$ is to take the optimal plan at $K_0$, *freeze* next period's capital at its optimal value $K_0'$, and let consumption absorb the change in $K$:
+
+```{math}
+:label: q_W1
+W_1(K) = u\bigl(f(K)\theta + (1-\delta)K - K_0', e\bigr) + \beta \mathbb{E}\bigl[v(K_0', \theta', e')\bigr] .
+```
+
+This is a feasible plan, so $W_1 \leq v$, with equality at $K_0$, and it is differentiable.
+
+But feasibility requires $K_0' \geq (1-\delta)K$, that is $K \leq K_0'/(1-\delta)$.
+
+When investment is positive, $K_0' > (1-\delta)K_0$ and the plan is feasible on a full neighborhood of $K_0$.
+
+When investment is *zero*, $K_0' = (1-\delta)K_0$ exactly, and the plan is infeasible for every $K > K_0$.
+
+At a corner, the standard support function is available only from the left.
+
+This is precisely where the published argument becomes delicate, and in our reading it has gaps.
+
+```{note}
+Two specific difficulties.
+
+First, {cite:t}`Sargent1980q` states the derivative of the value function in the form
+
+$$
+v_K(K,\theta,e) = u_c(c,e)\bigl[f'(K)\theta + (1-\delta)\bigr] ,
+$$
+
+which is obtained by substituting the first-order condition {eq}`q_foc` *with equality* into the envelope condition.
+
+That substitution is legitimate only where investment is positive.
+
+Where investment is zero, $\lambda > 0$ and the formula overstates $v_K$; the paper's own subsequent inequality records this, so the two statements are not consistent with each other.
+
+Second, the argument establishes differentiability of the value function by induction along the iterates $v^j = T^j v^0$, and then passes to the limit.
+
+That route requires knowing how the set of capital stocks at which the constraint just binds is structured.
+
+The published proof handles three configurations, drawn in its Figures 3-5, and appeals to an appendix that assumes the iterates are twice differentiable almost everywhere.
+
+The appendix in turn justifies this by differentiating the first-order condition and observing that "since the right-hand side exists almost everywhere, so does the left," which does not follow as stated, and it asserts without proof that the set of binding points has Lebesgue measure zero.
+```
+
+Fortunately the conclusion is true, and there is a route to it that avoids the induction on iterates entirely.
+
+The key observation is that at a corner a *different* feasible plan supplies the needed support function: investing nothing is feasible at *every* capital stock, so it works on both sides.
+
+````{prf:proposition}
+:label: q_differentiability
+
+Assume $u$ and $f$ are increasing, strictly concave and continuously differentiable, with $u_c(0,e) = \infty$ and $f'(0) = \infty$.
+
+Then for each $(\theta, e)$ the value function $v(\cdot,\theta,e)$ defined by {eq}`q_bellman` is continuously differentiable on $(0,\infty)$, and
+
+```{math}
+:label: q_envelope
+v_K(K,\theta,e) = u_c(c,e) f'(K)\theta + \beta(1-\delta) \mathbb{E}\bigl[v_K(K',\theta',e')\bigr] ,
+```
+
+where $c$ and $K'$ are optimal at $(K,\theta,e)$.
+
+Where investment is positive, {eq}`q_envelope` reduces to $v_K = u_c(c,e)[f'(K)\theta + (1-\delta)]$.
+
+Where investment is zero, $v_K < u_c(c,e)[f'(K)\theta + (1-\delta)]$.
+````
+
+````{prf:proof}
+**Step 0.** The operator associated with {eq}`q_bellman` maps bounded continuous concave functions into bounded continuous strictly concave functions, so $v(\cdot,\theta,e)$ is concave and continuous, and the optimal policy is single valued and continuous.
+
+**Step 1 (investment positive).** Suppose $I(K_0,\theta,e) > 0$, and let $K_0'$ be the optimal choice.
+
+Then $K_0' > (1-\delta)K_0$, so by continuity the plan that freezes next period's capital at $K_0'$ is feasible for all $K$ in a neighborhood of $K_0$.
+
+The function $W_1$ of {eq}`q_W1` is therefore concave, continuously differentiable, dominated by $v$, and equal to $v$ at $K_0$.
+
+{prf:ref}`bs_theorem` gives differentiability at $K_0$ with
+
+$$
+v_K(K_0,\theta,e) = u_c(c,e)\bigl[f'(K_0)\theta + (1-\delta)\bigr] .
+$$
+
+Because the first-order condition holds with equality here, $\beta \mathbb{E}[v_K(K_0',\cdot)] = u_c(c,e)$, and substituting gives {eq}`q_envelope`.
+
+**Step 2 (investment zero, conditional on a smaller capital stock).** Suppose $I(K_0,\theta,e) = 0$, so that $K_0' = (1-\delta)K_0$ and investing nothing is optimal at $K_0$.
+
+Consider instead the plan that invests nothing this period and behaves optimally thereafter:
+
+$$
+W_2(K) = u\bigl(f(K)\theta, e\bigr) + \beta \mathbb{E}\bigl[v\bigl((1-\delta)K, \theta', e'\bigr)\bigr] .
+$$
+
+Investing nothing is feasible at *every* capital stock, so $W_2 \leq v$ everywhere, with $W_2(K_0) = v(K_0)$, and $W_2$ is concave.
+
+Suppose that $v(\cdot,\theta',e')$ is differentiable at $(1-\delta)K_0$ for every $(\theta',e')$.
+
+Then $W_2$ is differentiable at $K_0$; differentiation under the expectation is legitimate because the functions $v(\cdot,\theta',e')$ are concave, hence locally Lipschitz with a common bound on a compact neighborhood.
+
+{prf:ref}`bs_theorem` then gives differentiability of $v$ at $K_0$, with
+
+$$
+v_K(K_0,\theta,e) = u_c(c,e) f'(K_0)\theta + \beta(1-\delta) \mathbb{E}\bigl[v_K((1-\delta)K_0, \theta', e')\bigr] ,
+$$
+
+which is {eq}`q_envelope`.
+
+**Step 3 (a region where the corner cannot bind).** Because $f'(0) = \infty$, there is an $\eta > 0$ such that $I(K,\theta,e) > 0$ for every $K \leq \eta$ and every $(\theta,e)$.
+
+The intuition is that the marginal product of capital becomes arbitrarily large as capital approaches zero, so that giving up a little consumption today buys a great deal of consumption tomorrow.
+
+Making this precise requires comparing the rates at which the two sides of {eq}`q_foc` diverge as $K \downarrow 0$, since with, say, logarithmic utility both sides become unbounded.
+
+{cite:t}`Sargent1980q` proves the statement in his Appendix A (his Proposition A2), under an explicit restriction on $u$ and $f$ that he imposes for this purpose.
+
+That result is the one ingredient of his appendix that the argument below borrows, and it is independent of the differentiability question at issue here.
+
+By Step 1, $v(\cdot,\theta,e)$ is therefore differentiable on $(0,\eta]$ for every $(\theta,e)$.
+
+**Step 4 (bootstrap).** Let
+
+$$
+D = \{K > 0 : v(\cdot,\theta,e) \text{ is differentiable at } K \text{ for every } (\theta,e)\} .
+$$
+
+We claim that if $(0, A) \subseteq D$ then $(0, A/(1-\delta)) \subseteq D$.
+
+Take $K < A/(1-\delta)$ and any $(\theta,e)$.
+
+If $I(K,\theta,e) > 0$, Step 1 applies directly.
+
+If $I(K,\theta,e) = 0$, then $(1-\delta)K < A$, so $v(\cdot,\theta',e')$ is differentiable at $(1-\delta)K$ for every $(\theta',e')$, and Step 2 applies.
+
+By Step 3 we may start the induction at $A = \eta$.
+
+Since $1/(1-\delta) > 1$, iterating the claim gives $(0, \eta (1-\delta)^{-n}) \subseteq D$ for every $n$, and therefore $D = (0,\infty)$.
+
+**Step 5 (continuity).** A concave function that is differentiable on an open interval has a continuous derivative there, so $v(\cdot,\theta,e)$ is continuously differentiable.
+
+Finally, where investment is zero the first-order condition holds with $\lambda > 0$, so $\beta \mathbb{E}[v_K(K',\cdot)] < u_c$, and {eq}`q_envelope` gives $v_K < u_c[f'(K)\theta + (1-\delta)]$.
+````
+
+The corrected formula has a natural reading.
+
+Iterating {eq}`q_envelope` forward gives
+
+```{math}
+:label: q_envelope_sum
+v_K(K_t,\theta_t,e_t) = \mathbb{E}_t \sum_{j=0}^\infty \beta^j (1-\delta)^j \,
+u_c(c_{t+j}, e_{t+j}) \, f'(K_{t+j})\theta_{t+j} .
+```
+
+A marginal unit of capital installed today yields marginal products for as long as it survives, and each is valued at the marginal utility of consumption on the date it arrives.
+
+When investment is positive, the market prices that whole stream at the cost of a unit of new output, and {eq}`q_envelope_sum` collapses to $u_c[f'(K)\theta + (1-\delta)]$.
+
+When investment is zero, it does not, and the difference is exactly what pushes $q$ below one.
+
+## Computing the model
+
+We now solve the model of {eq}`q_bellman` with
+
+$$
+u(c,e) = e \ln c, \qquad f(K) = K^a .
+$$
+
+The shocks $\theta$ and $e$ each take two values with equal probability and are independent of each other and over time.
+
+One numerical detail matters a great deal.
+
+The irreversibility constraint says $K' \geq (1-\delta)K$, so we want $(1-\delta)K$ to be a point of the capital grid whenever $K$ is.
+
+Following {cite:t}`Sargent1980q`, we use a *geometric* grid with ratio $(1-\delta)^{1/z}$ for an integer $z$, so that $(1-\delta)K_i = K_{i-z}$ exactly.
+
+```{code-cell} ipython3
+Model = namedtuple("Model", "β δ a z K θ e W nθ ne")
+
+def create_model(β=0.95, δ=0.05, a=0.25, z=10, n_K=500, K_hi=20.0,
+ θ_vals=(0.85, 1.15), e_vals=(0.6, 1.4)):
+ "Geometric capital grid so that (1-δ)K is itself a grid point."
+ ratio = (1 - δ)**(1/z)
+ K = K_hi * ratio**np.arange(n_K - 1, -1, -1)
+ θ, e = np.array(θ_vals), np.array(e_vals)
+ W = np.outer(np.ones(len(θ))/len(θ), np.ones(len(e))/len(e))
+ return Model(β, δ, a, z, K, θ, e, W, len(θ), len(e))
+
+f = lambda m, K: K**m.a
+f_prime = lambda m, K: m.a * K**(m.a - 1)
+```
+
+The planner chooses next period's capital from the grid, subject to positive consumption and to irreversibility.
+
+```{code-cell} ipython3
+def solve_model(m, irreversible=True, tol=1e-10, maxit=5000, howard=50):
+ "Value function iteration with Howard policy improvement steps."
+ nK = len(m.K)
+ C = f(m, m.K)[:, None] * m.θ[None, :] # output (K, θ)
+ C = C[:, None, :] + (1 - m.δ)*m.K[:, None, None] - m.K[None, :, None]
+ ok = C > 1e-12 # (K, K', θ)
+
+ if irreversible: # K' ≥ (1-δ)K
+ irr = np.zeros((nK, nK), bool)
+ for i in range(nK):
+ irr[i, max(i - m.z, 0):] = True
+ ok = ok & irr[:, :, None]
+
+ U = np.where(ok[:, :, :, None],
+ m.e[None, None, None, :] * np.log(np.where(ok, C, 1.0))[:, :, :, None],
+ -1e12)
+
+ v = np.zeros((nK, m.nθ, m.ne))
+ for it in range(maxit):
+ EV = np.tensordot(v, m.W, axes=([1, 2], [0, 1])) # E v(K') over (θ', e')
+ obj = U + m.β * EV[None, :, None, None]
+ idx = obj.argmax(axis=1)
+ v_new = np.take_along_axis(obj, idx[:, None, :, :], axis=1)[:, 0, :, :]
+
+ for _ in range(howard):
+ EV = np.tensordot(v_new, m.W, axes=([1, 2], [0, 1]))
+ v_new = (np.take_along_axis(U, idx[:, None, :, :], axis=1)[:, 0, :, :]
+ + m.β * EV[idx])
+
+ if np.max(np.abs(v_new - v)) < tol:
+ v = v_new
+ break
+ v = v_new
+
+ K_next = m.K[idx]
+ I = K_next - (1 - m.δ) * m.K[:, None, None]
+ C_pol = (f(m, m.K)[:, None, None] * m.θ[None, :, None]
+ + (1 - m.δ) * m.K[:, None, None] - K_next)
+ return v, idx, K_next, I, C_pol
+```
+
+To compute $q$ we need $v_K$, and {prf:ref}`q_differentiability` tells us how to get it: equation {eq}`q_envelope` is a linear fixed point problem in $v_K$ given the optimal policy, and it is a contraction with modulus $\beta(1-\delta)$.
+
+```{code-cell} ipython3
+def marginal_value(m, idx, C_pol, tol=1e-13, maxit=50_000):
+ "Solve the envelope equation v_K = u_c f'(K)θ + β(1-δ) E v_K(K')."
+ vK = np.zeros_like(C_pol)
+ direct = (m.e[None, None, :]/C_pol) * f_prime(m, m.K)[:, None, None] * m.θ[None, :, None]
+ for _ in range(maxit):
+ EvK = np.tensordot(vK, m.W, axes=([1, 2], [0, 1]))
+ new = direct + m.β * (1 - m.δ) * EvK[idx]
+ if np.max(np.abs(new - vK)) < tol:
+ return new
+ vK = new
+ return vK
+
+m = create_model()
+v, idx, K_next, I, C_pol = solve_model(m)
+vK = marginal_value(m, idx, C_pol)
+
+u_c = m.e[None, None, :] / C_pol
+E_vK = np.tensordot(vK, m.W, axes=([1, 2], [0, 1]))
+q = m.β * E_vK[idx] / u_c
+corner = I <= 1e-12
+
+print(f"share of states with zero investment: {corner.mean():.3f}")
+```
+
+Let's check {prf:ref}`q_differentiability` numerically, by comparing the envelope formula with a finite-difference derivative of the computed value function.
+
+```{code-cell} ipython3
+vK_fd = np.gradient(v, m.K, axis=0)
+naive = u_c * (f_prime(m, m.K)[:, None, None] * m.θ[None, :, None] + (1 - m.δ))
+mid = ((m.K > 2.2) & (m.K < 7.0))[:, None, None] & np.ones_like(corner)
+
+rel = lambda x: np.median((np.abs(x - vK_fd)/np.abs(vK_fd))[mid & sel])
+
+sel = ~corner
+print(f"investment positive: envelope error {rel(vK):.4f}, "
+ f"naive formula error {rel(naive):.4f}")
+sel = corner
+print(f"investment zero: envelope error {rel(vK):.4f}, "
+ f"naive formula error {rel(naive):.4f}")
+```
+
+Where investment is positive, both formulas agree with the numerical derivative.
+
+Where investment is zero, the envelope formula {eq}`q_envelope` remains accurate while the formula $u_c[f'(K)\theta + (1-\delta)]$ is off by tens of percent.
+
+This is the practical content of the correction: at corners the two expressions are genuinely different objects, and it is the envelope formula that gives the price of installed capital.
+
+We can also verify Step 3 of the proof, which asserts a region of small capital stocks where the corner never binds.
+
+```{code-cell} ipython3
+m_wide = create_model(n_K=700) # a grid reaching lower capital stocks
+_, idx_w, _, I_w, _ = solve_model(m_wide)
+frac_corner = (I_w <= 1e-12).reshape(len(m_wide.K), -1).mean(axis=1)
+first = np.argmax(frac_corner > 0)
+print(f"grid runs from K = {m_wide.K.min():.3f}")
+print(f"investment is positive for every shock when K < {m_wide.K[first]:.3f}")
+```
+
+### Policies and the price of installed capital
+
+```{code-cell} ipython3
+---
+mystnb:
+ figure:
+ caption: Law of motion and Tobin's q
+ name: fig-ogu-policy-q
+---
+fig, axes = plt.subplots(1, 2, figsize=(12, 4.5))
+show = (m.K > 1.5) & (m.K < 9)
+
+for j in range(m.nθ):
+ for l in range(m.ne):
+ lab = rf'$\theta={m.θ[j]}, e={m.e[l]}$'
+ axes[0].plot(m.K[show], K_next[show, j, l], label=lab)
+ axes[1].plot(m.K[show], q[show, j, l], label=lab)
+
+axes[0].plot(m.K[show], m.K[show], 'k--', lw=1, label='45 degree line')
+axes[0].plot(m.K[show], (1-m.δ)*m.K[show], 'k:', lw=1, label=r'$(1-\delta)K$')
+axes[0].set_xlabel('$K$'); axes[0].set_ylabel("$K'$"); axes[0].set_title('law of motion')
+axes[1].axhline(1.0, color='k', ls='--', lw=1)
+axes[1].set_xlabel('$K$'); axes[1].set_ylabel('$q$'); axes[1].set_title("Tobin's $q$")
+axes[0].legend(fontsize=8); axes[1].legend(fontsize=8)
+plt.tight_layout()
+plt.show()
+```
+
+The law of motion runs along the lower dotted line $(1-\delta)K$ whenever the irreversibility constraint binds.
+
+Exactly on that region, $q$ falls below one.
+
+### The invariant distribution
+
+As in {doc}`lucas_prescott_investment`, we check that the long-run distribution does not depend on where the economy starts.
+
+```{code-cell} ipython3
+def simulate(m, idx, K0, T=50_000, seed=0, burn=500):
+ "Simulate the equilibrium Markov process."
+ rng = np.random.default_rng(seed)
+ j_idx = rng.integers(0, m.nθ, T)
+ l_idx = rng.integers(0, m.ne, T)
+ k = np.abs(m.K - K0).argmin()
+ path = np.empty(T, int)
+ for t in range(T):
+ path[t] = k
+ k = idx[k, j_idx[t], l_idx[t]]
+ return path[burn:], j_idx[burn:], l_idx[burn:]
+
+p_lo, j_lo, l_lo = simulate(m, idx, K0=2.0, seed=7)
+p_hi, j_hi, l_hi = simulate(m, idx, K0=15.0, seed=7)
+
+print(f"mean capital starting from K0 = 2: {m.K[p_lo].mean():.4f}")
+print(f"mean capital starting from K0 = 15: {m.K[p_hi].mean():.4f}")
+print(f"capital visited: [{m.K[p_lo].min():.2f}, {m.K[p_lo].max():.2f}]")
+```
+
+```{code-cell} ipython3
+---
+mystnb:
+ figure:
+ caption: Invariant distribution and investment against q
+ name: fig-ogu-invariant-q
+---
+fig, axes = plt.subplots(1, 2, figsize=(12, 4.5))
+
+axes[0].hist(m.K[p_lo], bins=60, density=True, alpha=0.5, label='from $K_0 = 2$')
+axes[0].hist(m.K[p_hi], bins=60, density=True, alpha=0.5, label='from $K_0 = 15$')
+axes[0].set_xlabel('$K$'); axes[0].set_ylabel('density')
+axes[0].set_title('invariant distribution of capital')
+axes[0].legend()
+
+q_sim, I_sim = q[p_lo, j_lo, l_lo], I[p_lo, j_lo, l_lo]
+axes[1].scatter(q_sim, I_sim, s=4, alpha=0.2)
+axes[1].set_xlabel('$q$'); axes[1].set_ylabel('$I$')
+axes[1].set_title("investment and Tobin's $q$")
+
+plt.tight_layout()
+plt.show()
+```
+
+The two histograms coincide, as {prf:ref}`bm_theorem` leads us to expect.
+
+The scatter plot on the right reproduces the central picture of {cite:t}`Sargent1980q`.
+
+Investment is positive only when $q$ equals one; when $q$ is below one, investment is exactly zero.
+
+```{code-cell} ipython3
+print(f"q when I > 0: [{q_sim[I_sim > 1e-12].min():.4f}, {q_sim[I_sim > 1e-12].max():.4f}]")
+print(f"q when I = 0: [{q_sim[I_sim <= 1e-12].min():.4f}, {q_sim[I_sim <= 1e-12].max():.4f}]")
+```
+
+The small departures from exactly one reflect the discreteness of the capital grid.
+
+Sargent's point is now visible.
+
+There *is* a positive relationship between investment and $q$ in these data, and an econometrician could certainly run that regression.
+
+But the relationship is not an investment demand schedule.
+
+It is a **mongrel relation** that mixes together preferences, technology and the distribution of the shocks, and it will shift whenever any of them changes.
+
+{ref}`ogu_ex3` asks you to demonstrate this.
+
+## Exercises
+
+```{exercise}
+:label: ogu_ex1
+
+{cite:t}`BrockMirman1972` is famous partly for a special case that can be solved by hand.
+
+Let $u(c) = \ln c$, let $f(k, r) = r k^\alpha$ with $0 < \alpha < 1$, and let capital depreciate fully each period, so that $k_{t+1} = f(k_t, r_t) - c_t$.
+
+1. Verify that the optimal policy is $k_{t+1} = \alpha\beta\, r_t k_t^\alpha$.
+1. Show that $\ln k_t$ follows an AR(1) process, and derive the mean and variance of its invariant distribution when $\ln r_t \sim N(\mu, \sigma^2)$.
+1. Simulate the model and check both the invariant distribution and the mean-ergodic property {eq}`bm_ergodic`.
+```
+
+```{solution-start} ogu_ex1
+:class: dropdown
+```
+
+Guess that a constant fraction of resources is saved, $k_{t+1} = s\, r_t k_t^\alpha$.
+
+The Euler equation for this problem is
+
+$$
+\frac{1}{c_t} = \beta \mathbb{E}_t \left[ \frac{1}{c_{t+1}} \alpha r_{t+1} k_{t+1}^{\alpha - 1} \right] .
+$$
+
+With $c_t = (1-s) r_t k_t^\alpha$ and $k_{t+1} = s r_t k_t^\alpha$, the right side becomes
+
+$$
+\beta \mathbb{E}_t \left[\frac{\alpha r_{t+1}k_{t+1}^{\alpha-1}}{(1-s) r_{t+1} k_{t+1}^{\alpha}}\right]
+= \frac{\beta \alpha}{(1-s) k_{t+1}}
+= \frac{\beta\alpha}{(1-s) s r_t k_t^{\alpha}} ,
+$$
+
+while the left side is $1/[(1-s) r_t k_t^\alpha]$.
+
+Equating the two gives $s = \alpha\beta$.
+
+Taking logs of the policy,
+
+$$
+\ln k_{t+1} = \ln(\alpha\beta) + \alpha \ln k_t + \ln r_t ,
+$$
+
+an AR(1) with coefficient $\alpha$.
+
+With $\ln r_t \sim N(\mu, \sigma^2)$, the invariant distribution of $\ln k$ is normal with
+
+$$
+\text{mean} = \frac{\ln(\alpha\beta) + \mu}{1 - \alpha},
+\qquad
+\text{variance} = \frac{\sigma^2}{1 - \alpha^2} .
+$$
+
+```{code-cell} ipython3
+α, β_d, μ, σ = 0.4, 0.95, 0.0, 0.1
+T = 200_000
+rng = np.random.default_rng(0)
+ln_r = μ + σ * rng.normal(size=T)
+
+k = np.empty(T + 1)
+k[0] = 1.0
+for t in range(T):
+ k[t+1] = α * β_d * np.exp(ln_r[t]) * k[t]**α
+
+ln_k = np.log(k[1000:])
+print(f"mean of ln k: simulated {ln_k.mean():.4f}, "
+ f"theory {(np.log(α*β_d) + μ)/(1-α):.4f}")
+print(f"var of ln k: simulated {ln_k.var():.4f}, "
+ f"theory {σ**2/(1-α**2):.4f}")
+```
+
+The time averages match the population moments of the invariant distribution, which is the mean-ergodic property {eq}`bm_ergodic` in action.
+
+```{solution-end}
+```
+
+```{exercise}
+:label: ogu_ex2
+
+This exercise examines the difference between the two candidate formulas for $v_K$ discussed above.
+
+For the baseline model, compute at every state
+
+* the envelope formula {eq}`q_envelope`
+* the formula $u_c(c,e)[f'(K)\theta + (1-\delta)]$
+* a finite-difference derivative of the value function
+
+Then
+
+1. Confirm that all three agree where investment is positive.
+1. Confirm that the second disagrees with the other two where investment is zero, and report by how much.
+1. Explain, using {eq}`q_foc`, why the second formula is an upper bound for $v_K$.
+1. What would go wrong with the computed $q$ if you used the second formula everywhere?
+```
+
+```{solution-start} ogu_ex2
+:class: dropdown
+```
+
+The second formula is what you get by substituting the first-order condition {eq}`q_foc` into the envelope condition *as though* $\lambda = 0$.
+
+Since $\lambda \geq 0$, dropping it can only raise the expression, so
+
+$$
+v_K = u_c f'(K)\theta + (1-\delta)\bigl[u_c - \lambda\bigr]
+\leq u_c\bigl[f'(K)\theta + (1-\delta)\bigr] ,
+$$
+
+with equality exactly when $\lambda = 0$, that is, when investment is positive.
+
+```{code-cell} ipython3
+gap = np.abs(naive - vK_fd)/np.abs(vK_fd)
+env = np.abs(vK - vK_fd)/np.abs(vK_fd)
+
+for name, sel in (("investment positive", ~corner), ("investment zero", corner)):
+ s = mid & sel
+ print(f"{name:20}: envelope {np.median(env[s]):.4f} "
+ f"naive {np.median(gap[s]):.4f} max naive {gap[s].max():.4f}")
+
+q_naive = m.β * np.tensordot(naive, m.W, axes=([1, 2], [0, 1]))[idx] / u_c
+print(f"\nusing the naive formula, max q = {q_naive.max():.3f} "
+ f"(theory says q ≤ 1)")
+print(f"fraction of states with q > 1: {(q_naive > 1 + 1e-8).mean():.3f}")
+```
+
+Using the second formula everywhere produces values of $q$ that exceed one, which the theory rules out.
+
+The reason is economic, not numerical: at a corner the market does not price installed capital at the cost of new capital, precisely because the household would like to sell capital and cannot.
+
+```{solution-end}
+```
+
+```{exercise}
+:label: ogu_ex3
+
+Show that the regression of investment on $q$ is not structural.
+
+Solve and simulate the model for several economies that differ in
+
+* the amount of preference risk (the spread of $e$)
+* the amount of technology risk (the spread of $\theta$)
+* the depreciation rate $\delta$
+
+For each economy, report the slope and $R^2$ of a regression of $I$ on $q$, together with the frequency with which investment is zero.
+
+Comment on what this implies for an econometrician who estimates an "investment demand schedule" relating investment to $q$.
+```
+
+```{solution-start} ogu_ex3
+:class: dropdown
+```
+
+Here is one solution.
+
+```{code-cell} ipython3
+def q_regression(**kwargs):
+ "Solve an economy, simulate it, and regress I on q."
+ mm = create_model(**kwargs)
+ vv, ii, _, II, CC = solve_model(mm)
+ vvK = marginal_value(mm, ii, CC)
+ uu_c = mm.e[None, None, :]/CC
+ qq = mm.β * np.tensordot(vvK, mm.W, axes=([1, 2], [0, 1]))[ii] / uu_c
+ p, j, l = simulate(mm, ii, K0=3.5)
+ q_s, I_s = qq[p, j, l], II[p, j, l]
+ slope = np.polyfit(q_s, I_s, 1)[0]
+ corr = np.corrcoef(I_s, q_s)[0, 1]
+ return slope, corr**2, (I_s <= 1e-12).mean()
+
+cases = [("baseline", {}),
+ ("less preference risk", dict(e_vals=(0.8, 1.2))),
+ ("more preference risk", dict(e_vals=(0.4, 1.6))),
+ ("less technology risk", dict(θ_vals=(0.95, 1.05))),
+ ("more technology risk", dict(θ_vals=(0.7, 1.3))),
+ ("faster depreciation", dict(δ=0.10))]
+
+print(f"{'economy':24}{'slope':>9}{'R^2':>8}{'zero I':>9}")
+for name, kw in cases:
+ slope, r2, zero = q_regression(**kw)
+ print(f"{name:24}{slope:9.3f}{r2:8.3f}{zero:9.3f}")
+```
+
+The slope and the fit both move around substantially across economies that share the same preferences and technology parameters but differ in the distribution of shocks or in the depreciation rate.
+
+Nothing in the regression is invariant, so it cannot be used to predict what investment would do under a policy that changed any of these features.
+
+This is the message of {cite:t}`Sargent1980q`, and it is a concrete instance of the Lucas critique: the very friction that makes $q$ interesting -- the occasionally binding irreversibility constraint -- also makes the relationship between $I$ and $q$ a reduced-form artifact rather than a decision rule.
+
+```{solution-end}
+```
diff --git a/lectures/rational_expectations.md b/lectures/rational_expectations.md
index 844d98286..5cc40e347 100644
--- a/lectures/rational_expectations.md
+++ b/lectures/rational_expectations.md
@@ -30,7 +30,7 @@ kernelspec:
In addition to what's in Anaconda, this lecture will need the following libraries:
-```{code-cell} ipython
+```{code-cell} ipython3
---
tags: [hide-output]
---
@@ -46,6 +46,14 @@ due to Lucas and Prescott {cite}`Lucas_Prescott_1971`.
That 1971 paper is one of a small number of research articles that ignited a *rational expectations revolution*.
+You can regard the present lecture as a "baby" version of that paper, and as an introduction to ideas that two sequels study in more general settings.
+
+{doc}`lucas_prescott_investment` describes the model that Lucas and Prescott actually built, in which demand is shifted by a Markov process, so that the equilibrium is a stochastic process rather than a deterministic path.
+
+{doc}`optimal_growth_uncertainty` studies a one-sector optimal growth model with random shocks to production, and uses it to think about Tobin's $q$.
+
+Both sequels ask a question that cannot arise here, because this lecture has no uncertainty: does the equilibrium have an invariant probability distribution to which it converges from any initial condition?
+
We follow Lucas and Prescott by employing a setting that is readily "Bellmanized" (i.e., susceptible to being formulated as a dynamic programming problems.
Because we use linear quadratic setups for demand and costs, we can deploy the LQ programming techniques described in {doc}`this lecture `.
@@ -66,14 +74,14 @@ Except that for us
Let's start with some standard imports:
-```{code-cell} ipython
+```{code-cell} ipython3
import matplotlib.pyplot as plt
import numpy as np
```
We'll also use the LQ class from `QuantEcon.py`.
-```{code-cell} ipython
+```{code-cell} ipython3
from quantecon import LQ
```
@@ -199,7 +207,7 @@ Thus, a $Y$ that solves {eq}`staticY` is a competitive equilibrium output as wel
This type of outcome provides an intellectual justification for liking a competitive equilibrium.
-### Further Reading
+### Further reading
References for this lecture include
@@ -207,6 +215,8 @@ References for this lecture include
* {cite}`Sargent1987`, chapter XIV
* {cite}`Ljungqvist2012`, chapter 7
+The two sequels to this lecture are {doc}`lucas_prescott_investment` and {doc}`optimal_growth_uncertainty`.
+
## Rational expectations equilibrium
```{index} single: Rational Expectations Equilibrium; Definition
@@ -578,6 +588,30 @@ y_{t+1} = h_0 + h_1 y_t + h_2 Y_t
Hence a rational expectations equilibrium will be defined by the parameters
$(\kappa_0, \kappa_1, h_0, h_1, h_2)$ in {eq}`ree_hlom2`--{eq}`ree_ex5`.
+## Concluding remarks
+
+Three ideas from this lecture recur throughout macroeconomics.
+
+The first is the equilibrium concept itself: a *perceived* law of motion for a market-wide object must coincide with the *actual* law of motion that the resulting decisions generate.
+
+The second is the "Big $Y$, little $y$" device that lets a price-taking firm be representative.
+
+The third is the computational strategy: because the mapping from perceived to actual laws of motion is not a contraction, we found an equilibrium by solving a *planning problem* instead, and then read off equilibrium prices as shadow prices.
+
+The two sequels take these ideas into settings with uncertainty.
+
+{doc}`lucas_prescott_investment` returns to {cite:t}`Lucas_Prescott_1971` itself.
+
+There, demand is shifted by a Markov process, firms face a nonlinear technology for converting investment into capacity, and the equilibrium is proved to exist, to be unique, and to solve a planning problem that maximizes discounted consumer surplus.
+
+Because the equilibrium is a Markov process, one can ask whether it converges to an invariant distribution, and whether time averages computed from a single realization converge to population moments.
+
+Affirmative answers are what make such models usable in econometrics.
+
+{doc}`optimal_growth_uncertainty` pursues the same questions in the one-sector optimal growth model of {cite:t}`BrockMirman1972`, and then follows {cite:t}`Sargent1980q` in adding irreversible investment.
+
+That small change makes the shadow price of installed capital -- Tobin's $q$ -- diverge from the price of new capital, and it turns the planner's value function into the object on which a theory of investment rests.
+
## Exercises
```{exercise}
@@ -664,7 +698,7 @@ $$
Here's our solution
-```{code-cell} python3
+```{code-cell} ipython3
# Model parameters
a0 = 100
@@ -773,7 +807,7 @@ $\kappa_1 = h_1 + h_2$.
The following code implements this test
-```{code-cell} python3
+```{code-cell} ipython3
candidates = ((94.0886298678, 0.923409232937),
(93.2119845412, 0.984323478873),
(95.0818452486, 0.952459076301))
@@ -871,7 +905,7 @@ $\kappa_0 = -F_1$ and $\kappa_1 = 1-F_0$.
The Python code to solve this problem is below:
-```{code-cell} python3
+```{code-cell} ipython3
# Formulate the planner's LQ problem
A = np.array([[1, 0], [0, 1]])
@@ -935,7 +969,7 @@ $$
The problem can be solved as follows
-```{code-cell} python3
+```{code-cell} ipython3
A = np.array([[1, 0], [0, 1]])
B = np.array([[1], [0]])
R = np.array([[a1, -a0 / 2], [-a0 / 2, 0]])
@@ -975,7 +1009,7 @@ who learn can converge to rational expectations equilibria features
iterations on a modification of the mapping $\Phi$ that can be
approximated as $\gamma \Phi + (1-\gamma)I$. Here $I$ is the
identity operator and $\gamma \in (0,1)$ is a *relaxation parameter*.
-See {cite}`MarcetSargent1989` and {cite}`EvansHonkapohja2001` for statements
+See {cite:t}`MarcetSargent1989` and {cite:t}`EvansHonkapohja2001` for statements
and applications of this approach to establish conditions under which
collections of adaptive agents who use least squares learning to converge to a
rational expectations equilibrium.