Connects to: Principles Ch. 7, Ch. 9–10, Ch. 23, Ch. 27, Appendix B
Dynamic Stochastic General Equilibrium models are the workhorse of modern central bank policy analysis. The Federal Reserve, the ECB, the Bank of England, the Riksbank, and the IMF all use medium-scale DSGE models — descendants of Smets and Wouters (2007) — as the primary quantitative framework for conditional forecasting, policy simulation, and communication with the public.
This part covers the complete DSGE pipeline: from the nonlinear model equations to the policy functions used for simulation and estimation. Chapter 27 develops log-linearization — the approximation that transforms the nonlinear DSGE into a tractable linear system, with a complete worked example for both the NK and RBC models. Chapter 28 solves the linearized system using the Blanchard–Kahn conditions and Sims’ gensys algorithm, proving the determinacy condition formally. Chapter 29 goes beyond first-order approximations to second-order perturbation, which is needed for welfare analysis, risk premia, and ELB dynamics. Chapter 30 develops Bayesian estimation of DSGE models via the Metropolis–Hastings algorithm, with the Kalman filter providing the likelihood. Chapter 31 integrates everything into working software — Dynare, APL, Python, Julia, and R — with a complete, reproducible implementation of the same NK model in every language.
Every chapter connects to the three-equation NK model of Principles. The reader who completes this part will be able to take any log-linearized DSGE model, solve it numerically, estimate it on data, and interpret the results — the complete toolkit of a central bank research economist.
Chapter 27: Linearization and Log-Linearization¶
Approximating DSGE Models Around the Steady State
“The first-order approximation is the simplest thing that works. For most policy questions, it is also the right thing.” — Michael Woodford
Cross-reference: Principles Ch. 7 (AS–AD derivation from IS–LM); Ch. 9 (IS–LM as linear system); Ch. 23 (NK three-equation model); Appendix B (DSGE estimation) [P:Ch.7, P:Ch.9, P:Ch.23, P:AppB]
27.1 Why Linearize?¶
DSGE models are systems of nonlinear equations. The household’s Euler equation is ; the firm’s pricing equation involves a nonlinear aggregator over price dispersion; the capital accumulation equation has multiplicative terms. Solving these nonlinear systems exactly is computationally tractable only for very simple models (via VFI, Chapter 17) or in special cases with closed-form solutions (Chapter 10).
The linearization strategy: Approximate the nonlinear model by a linear one near the steady state. The approximation error is second-order: where measures the deviation from steady state. For business-cycle analysis — where fluctuations are typically 1–5% of steady-state values — the linearization error is , small relative to the first-order effects we care about.
The linearized model is a system of linear expectational difference equations — exactly the kind solved by the methods of Chapters 18 and 28. This is why linearization is the gateway to the entire DSGE estimation pipeline.
27.2 Linear Approximation: Deviation Variables¶
The simplest linearization uses absolute deviations from the steady state .
Definition 27.1 (Linear Approximation). For a smooth function , the first-order Taylor expansion around the steady state :
using (steady-state condition).
The result is a linear equation in deviations . For dynamic models with operators, the linearization is applied similarly, treating expectations as linear operators:
27.3 Log-Linearization: The Convention¶
For macroeconomic variables that are always positive (output, consumption, prices, the capital stock), log-linearization is typically preferred over level linearization. The log-deviation:
has a direct percentage interpretation: is the percentage deviation from the steady state.
Definition 27.2 (Log-Linearization Rules). For variables near their steady states , with , :
| Expression | Log-linearized form | Rule |
|---|---|---|
| Log of product = sum of logs | ||
| Log of ratio = difference of logs | ||
| Log of power = multiply by exponent | ||
| Requires care (see below) | ||
| Expectation passes through |
Handling sums: For , the log-linearization is:
i.e., — a weighted average of percentage deviations, with steady-state shares as weights.
Proof of the product rule. Write and . Then . Log-linearizing gives . The deviation form: .
27.4 Log-Linearizing the New Keynesian Model¶
Cross-reference: Principles Ch. 23 (NK three-equation model derivation) [P:Ch.23]
We log-linearize the NK model from microfoundations, connecting the algebraic steps to the equations of Principles Ch. 23.
27.4.1 Household Euler Equation¶
The household’s CRRA Euler equation:
where is the nominal interest rate and is gross inflation. The steady state: , giving .
Log-linearize each side. Left side: (using , so deviation is ).
Right side, use where ... more cleanly: define . Then:
Rearranging:
In terms of the output gap (deviation of consumption from its flexible-price level) and letting (log utility):
the Dynamic IS (DIS) equation. Here is the natural rate of interest (the real interest rate that would prevail with flexible prices). This is precisely the DIS equation of Principles Ch. 23 [P:Ch.23.1].
27.4.2 The New Keynesian Phillips Curve¶
Firms set prices using Calvo (1983) contracts: each firm can adjust its price with probability each period. Log-linearizing the aggregate price-level equation and the firm’s optimal reset-price condition gives:
where is the inverse Frisch elasticity of labor supply and is the cost-push shock [P:Ch.10.3].
Derivation of . The firm’s optimal reset price satisfies (in log deviations):
where is the log real marginal cost. The aggregate price equation:
Under standard assumptions , combining gives the NKPC with . The precise formula depends on whether labor is firm-specific or economy-wide; the standard form is as stated.
27.4.3 Taylor Rule¶
The Taylor rule requires no log-linearization — it is already linear:
The three-equation NK system — DIS, NKPC, Taylor rule — is now the linearized representation of the full nonlinear model, valid to first order in deviations from the steady state.
27.5 Log-Linearizing the RBC Model¶
Cross-reference: Principles Ch. 27 (RBC model) [P:Ch.27]
The RBC model has four key equilibrium conditions. We log-linearize each around the deterministic steady state.
27.5.1 Household Euler Equation¶
. With and (capital rental rate):
where . Rearranging:
27.5.2 Labor Market Clearing¶
From (intratemporal condition) with (KPR):
Log-linearizing (using steady-state labor share ):
27.5.3 Capital Accumulation and Resource Constraint¶
27.5.4 Production Function¶
The complete log-linearized RBC system is five equations in five variables plus the exogenous .
27.6 Approximation Error and Second-Order Terms¶
Theorem 27.1 (First-Order Approximation Error). The first-order log-linearization of a smooth model is accurate to order where measures the maximum deviation from steady state. Specifically, for a twice-differentiable function :
The first-order approximation discards the Hessian term. For a model with (2% fluctuations), the relative approximation error is — acceptable for most policy questions.
When is the approximation poor?
Large shocks: Crisis episodes (2008-09: -9% output gap, 2020: -10%) push far from the linearization point. Second-order approximations (Chapter 29) are more accurate.
Nonlinear mechanisms: The ELB is a binding inequality constraint that the linear approximation cannot handle. Requires global methods or piecewise-linear approximation.
Welfare analysis: Welfare depends on the variance of consumption (), which is a second-order effect — invisible in the first-order approximation.
27.7 Worked Example: Medium-Scale NK Model with Investment¶
Cross-reference: Principles Ch. 23, Ch. 27 (medium-scale model) [P:Ch.23, P:Ch.27]
We add investment to the NK model, following Christiano, Eichenbaum, and Evans (2005). The additional equation is the investment Euler equation (from Tobin’s theory, Chapter 13):
where is Tobin’s deviation and is the log-deviation of the return on capital. The capital accumulation:
Full system (8 equations, 8 variables):
DIS:
NKPC:
Taylor:
q-eq:
Invest:
K-accum:
rk eq: (MPK relation)
Output:
This is the prototype system for the CEE (2005) and Smets–Wouters (2007) models. Chapter 28 solves it using the Blanchard–Kahn machinery.
Python¶
import numpy as np
# Log-linearization verification: check that linearized model
# matches nonlinear model near steady state for small shocks
alpha, delta, beta, sigma = 0.36, 0.025, 0.99, 1.0
kappa_NK, phi_pi, phi_y = 0.15, 1.5, 0.5
# Steady state (normalized: Y*=1, C*=1-delta*K*, etc.)
r_star = 1/beta - 1
K_star = (alpha/(r_star+delta))**(1/(1-alpha))
Y_star = K_star**alpha
C_star = Y_star - delta*K_star
I_star = delta*K_star
print("NK model steady state:")
print(f" Y* = {Y_star:.4f}, K* = {K_star:.4f}, C* = {C_star:.4f}, I* = {I_star:.4f}")
print(f" r* = {r_star*100:.2f}% (quarterly), K/Y = {K_star/Y_star:.2f}")
# Log-linearize: verify DIS, NKPC hold
# Given a unit TFP shock hat_A = 1%:
hat_A = 0.01
# Natural rate: r^n = α*rho_A*hat_A (approximately, from the Euler eq. at flex prices)
rho_A = 0.95
r_n = alpha * rho_A * hat_A # approximately
# MSV solution from Chapter 18
G0 = np.array([[1, -kappa_NK], [sigma*phi_pi, 1+sigma*phi_y]])
G1 = np.array([[beta, 0], [-sigma, 1]])
A = np.linalg.inv(G0) @ G1
eigs = np.linalg.eigvals(A)
print(f"\nEigenvalues of A: {np.abs(eigs).round(3)} — determinacy: {np.all(np.abs(eigs)>1)}")
# Response to natural rate shock
C_A = np.linalg.inv(G0) @ np.array([0, sigma]) # loading on r_n shock
Omega = np.linalg.solve(np.eye(2) - rho_A*A, C_A.reshape(2,1))
print(f"\nMSV solution (response to 1% TFP shock via natural rate):")
print(f" π̂_t = {Omega[0,0]:.4f} * û_t")
print(f" x̂_t = {Omega[1,0]:.4f} * û_t")Julia¶
# Julia — automated log-linearization via symbolic differentiation
using ForwardDiff, LinearAlgebra
# Define nonlinear NK equations F(y_t, y_{t-1}, E_y_{t+1}, z_t) = 0
# y = [pi, x], z = [r_n]
function nk_equations(yt, yt_1, Eyt1, zt; beta=0.99, kappa=0.15, sigma=1.0, phi_pi=1.5, phi_y=0.5)
pi_t, x_t = yt
pi_t1, x_t1 = Eyt1
r_n = zt[1]
r_t = phi_pi*pi_t + phi_y*x_t # Taylor rule gives nominal rate
F1 = pi_t - beta*pi_t1 - kappa*x_t # NKPC
F2 = x_t - x_t1 + sigma*(r_t - pi_t1 - r_n) # DIS
return [F1, F2]
end
# Compute Jacobians at steady state
y_ss = [0.0, 0.0]; z_ss = [0.0]
J_yt = ForwardDiff.jacobian(y -> nk_equations(y,y_ss,y_ss,z_ss), y_ss)
J_Eyt = ForwardDiff.jacobian(Ey -> nk_equations(y_ss,y_ss,Ey,z_ss), y_ss)
J_zt = ForwardDiff.jacobian(z -> nk_equations(y_ss,y_ss,y_ss,z), z_ss)
println("Γ₀ (J_yt) = ", round.(J_yt, digits=3))
println("Γ₁ (-J_Eyt) = ", round.(-J_Eyt, digits=3))
println("Ψ (J_zt) = ", round.(J_zt, digits=3))
# These are the Γ₀, Γ₁, Ψ matrices for Chapter 28's gensysR¶
# R — log-linearization rules demonstration
alpha <- 0.36; delta <- 0.025; beta <- 0.99
# Steady state
r_star <- 1/beta - 1
K_star <- (alpha/(r_star+delta))^(1/(1-alpha))
Y_star <- K_star^alpha
C_star <- Y_star - delta*K_star
# Log-linearization of production: Ŷ = Â + α*K̂ + (1-α)*n̂
# Verify: at small deviations, log-lin ≈ exact percentage change
hat_A_vec <- seq(-0.05, 0.05, 0.01) # -5% to +5% TFP shocks
# Exact nonlinear response (holding K, n fixed at SS)
Y_exact <- Y_star * exp(hat_A_vec) # Y = A * K^α * n^(1-α), only A changes
# Log-linearized response: Ŷ ≈ Â (with K, n fixed)
Y_linear <- Y_star * (1 + hat_A_vec)
cat("Approximation error (log-linear vs exact):\n")
for(i in c(1,3,5,7,9,11)){
err <- abs(Y_exact[i] - Y_linear[i]) / Y_star
cat(sprintf(" Â=%.2f: exact=%.4f, linear=%.4f, error=%.4e\n",
hat_A_vec[i], Y_exact[i], Y_linear[i], err))
}27.8 Programming Exercises¶
Exercise 27.1 (APL — Log-Linearization of the Euler Equation)¶
Implement the log-linearization of the household Euler equation step by step in APL. (a) Express each term as (1+hat_C)^{-sigma} ≈ 1-sigma×hat_C using 1+(-sigma)×hat_C. (b) Equate deviations on both sides to derive the DIS equation. (c) Verify numerically: generate 100 periods of model data with deviations and check that the log-linearized DIS holds to .
Exercise 27.2 (Python — Calvo Pricing Derivation)¶
Derive the NKPC slope for the standard Calvo model with linear disutility of labor. (a) Start from the firm’s optimal reset price . (b) Log-linearize and use the law of motion for the price level to obtain the NKPC. (c) Compute for and .
Exercise 27.3 — Approximation Error ()¶
For the RBC Euler equation : (a) log-linearize to get the linearized Euler equation; (b) simulate the exact nonlinear model for 500 periods with TFP shock std dev ; (c) compute the Euler equation residual in both the linearized and exact versions; (d) show the linearized residual is .
27.9 Chapter Summary¶
Key results:
Log-deviation is the natural variable for percentage deviations; log-linearization uses the rules: product → sum, ratio → difference, power → multiply.
The DIS equation and NKPC are the first-order approximations of the household Euler equation and Calvo pricing, valid to .
The approximation error is : for 2% fluctuations (), the relative error is — acceptable for most policy analysis.
The RBC log-linearized system has five equations in ; the NK system has three in ; medium-scale models augment these with investment, habits, price and wage stickiness.
In APL: log-linearization of a product
X*Yis(X_ss*hat_X) + (Y_ss*hat_Y); of a ratioX/Yishat_X - hat_Y; ForwardDiff.jl automates the Jacobian computation to give directly.
Next: Chapter 28 — Solving Linear DSGE Models: Blanchard–Kahn and Sims