15Simulated Method of Moments and Indirect Inference
In this chapter we study two estimators that use simulation to evaluate the objective function: the method of simulated moments, which is the simulation analogue of GMM, and indirect inference, which is a simulated version of minimum distance. We apply the method of simulated moments to the savings model, and close with some practical advice for implementing these estimators.
15.1 Method of Simulated Moments
The method of simulated moments (MSM) is the simulation analogue of GMM. Suppose that the moment conditions take the form:
If we cannot evaluate \(g\) analytically, we can replace it with a simulated version: \[\hat{g}(\mathbf{w}_{n},\theta) = \frac{1}{R}\sum_{r=1}^{R}\tilde{g}(\mathbf{w}_{n},\mathbf{u}^{r},\theta)\]
where \(\mathbb{E}_{\mathbf{u}}[\tilde{g}(\mathbf{w},\mathbf{u},\theta)]=g(\mathbf{w},\theta)\). The MSM estimator is:
In many structural applications, the moment conditions do not involve observation-level simulation. Instead, we match aggregate statistics from the data to their model-implied counterparts computed by simulating the model. The moments take the form:
where \(\hat{\mathbf{m}}\) is a vector of sample statistics (means, variances, covariances, etc.) and \(\tilde{\mathbf{m}}(\theta)\) is the corresponding vector computed from simulated data. This is the structure we will use for the savings model below.
15.1.2 Asymptotic Distribution
Theorem 15.1 (Asymptotic Distribution of MSM) Suppose the standard regularity conditions for GMM hold and \(\mathbb{E}_{\mathbf{u}}[\tilde{g}(\mathbf{w},\mathbf{u},\theta)]=g(\mathbf{w},\theta)\). Then with \(R\) fixed:
with \(\nabla_{\theta}g_{0}=\mathbb{E}[\nabla_{\theta}g(\mathbf{w},\theta_{0})']\).
Several features are worth highlighting:
Consistency does not require \(R\rightarrow\infty\). Because \(\hat{g}\) is an unbiased estimator of \(g\), the simulated sample moments converge to zero at \(\theta_{0}\) by the law of large numbers. This is in contrast to MSL.
Simulation adds variance. Because \(\mathbb{V}[\hat{g}]\geq\mathbb{V}[g]\), the MSM estimator is less efficient than the infeasible GMM estimator that uses the true \(g\). For the common case of a frequency simulator (where \(\tilde{g}\) is a binary indicator), the variance inflates by a factor of \((1+1/R)\).
If \(\sqrt{N}/R\rightarrow 0\), the efficiency loss from simulation disappears and the MSM achieves the same asymptotic variance as GMM.
See Newey and McFadden (1994) for a comprehensive treatment.
Example: Simulating the Savings Model
Example 15.1 To estimate the savings model by MSM, we first need to be able to simulate data from it. Given a solution (the policy function \(A\)), we can forward-simulate a panel of individuals by drawing income shocks and applying the optimal savings rule.
usingDistributions, Random, LinearAlgebra, Statistics# === Model setup (from savings model chapter) ===Φ_cdf(x) =cdf(Normal(),x)functiontauchen(ρ,ση,Kϵ) sd = ση/sqrt(1-ρ^2) grid =range(-3sd,stop=3sd,length=Kϵ) Π =zeros(Kϵ,Kϵ) Δ = grid[2]-grid[1]for j=1:Kϵ Π[1,j] =Φ_cdf((grid[1] + Δ/2- ρ*grid[j])/ση) Π[end,j] =1-Φ_cdf((grid[end] - Δ/2- ρ*grid[j])/ση)for k=2:(Kϵ-1) Π[k,j] =Φ_cdf((grid[k] + Δ/2- ρ*grid[j])/ση) -Φ_cdf((grid[k] - Δ/2- ρ*grid[j])/ση)endendreturn Π,collect(grid)endu(c,σ) = c^(1-σ) / (1-σ)functionsolve_max(V,t,iϵ,ia,pars) (;agrid,ϵgrid,Π,σ,Ka,r,β) = pars cash =exp(pars.μ[t] + ϵgrid[iϵ]) + agrid[ia] amax =1 vmax =-Inf loop =true a =1while loop && a<Ka c = cash - agrid[a] / (1+r)if c>0 v =u(c,σ)for iϵ′ inaxes(V,1) v += β * Π[iϵ′,iϵ] * V[iϵ′,a,t+1]endif v>vmax vmax = v amax = aendelse loop =falseend a +=1endreturn amax,vmaxendfunctioniterate!(V,A,t,pars)for ia inaxes(V,2), iϵ inaxes(V,1) A[iϵ,ia,t],V[iϵ,ia,t] =solve_max(V,t,iϵ,ia,pars)endendfunctionterminal_values!(V,pars) (;σ,ψ,agrid) = parsfor ia inaxes(V,2), iϵ inaxes(V,1) V[iϵ,ia] = ψ >0 ? ψ *u(max(agrid[ia], 1e-10), σ) :0.0endendfunctionbackward_induction!(V,A,pars) (;T) = pars@viewsterminal_values!(V[:,:,T+1],pars)for t inreverse(1:T)iterate!(V,A,t,pars)endendfunctionsetup_and_solve(θ) β, σ, ψ = θ T =45 Ka =100 Kϵ =5 ρ =0.9 ση =0.1 r =0.05 μ =fill(2., T) agrid =collect(LinRange(0, μ[1] * T, Ka)) Π, ϵgrid =tauchen(ρ, ση, Kϵ) pars = (;T, β, σ, ρ, ση, μ, ψ, r, Ka, Kϵ, agrid, Π, ϵgrid) V =zeros(Kϵ, Ka, T+1) A =zeros(Int64, Kϵ, Ka, T)backward_induction!(V, A, pars)return A, parsend
setup_and_solve (generic function with 1 method)
Now we write a simulation function. Given the policy function, we draw income shocks and track each individual’s asset and income path.
functionsimulate_panel(A, pars, N_sim; seed=nothing) (;T, Kϵ, Ka, agrid, ϵgrid, Π, μ, r) = parsif !isnothing(seed)Random.seed!(seed)end# Pre-compute CDF for sampling from Markov chain cumΠ =cumsum(Π, dims=1)# Storage assets =zeros(N_sim, T+1) # assets at start of each period income =zeros(N_sim, T) consumption =zeros(N_sim, T) iϵ_sim =zeros(Int, N_sim, T)# Initial conditions: start with zero assets, draw initial ϵ from stationary dist# Use middle state as starting point for simplicity iϵ_sim[:, 1] .= (Kϵ +1) ÷2for n in1:N_sim ia =1# start with zero assetsfor t in1:T iϵ = iϵ_sim[n, t] y =exp(μ[t] + ϵgrid[iϵ]) income[n, t] = y cash = y + agrid[ia]# Look up optimal savings ia_next = A[iϵ, ia, t] c = cash - agrid[ia_next] / (1+ r) consumption[n, t] = c assets[n, t+1] = agrid[ia_next] ia = ia_next# Draw next period's ϵif t < T u_draw =rand() iϵ_next =findfirst(cumΠ[:, iϵ] .>= u_draw) iϵ_sim[n, t+1] = iϵ_nextendendendreturn (;assets, income, consumption)end# Solve and simulateA, pars =setup_and_solve((0.95, 2.0, 0.0))sim =simulate_panel(A, pars, 1000; seed=123)
The hump-shaped asset profile and the smooth consumption path are consistent with the model’s predictions: individuals accumulate assets during working years as a buffer against income risk and draw them down toward the end of life. With no bequest motive (\(\psi=0\)), assets are fully decumulated by the final period.
Example: Simulated Moments for the Savings Model
Example 15.2 Now let’s use the simulation machinery to define a set of moments and construct an MSM estimator for the preference parameters \((\beta,\sigma)\), setting \(\psi=0\) (no bequest motive). We take the income process parameters \((\rho,\sigma_{\eta})\) as given (estimated in Example 12.2).
Our target moments will be:
Mean assets at ages 30, 40, 50, 60 (to pin down the savings profile)
Variance of log consumption at ages 30, 40, 50, 60 (to pin down risk aversion)
# Compute moments from simulated datafunctionsimulated_moments(θ; N_sim=2000, seed=42) A, pars =setup_and_solve(θ) sim =simulate_panel(A, pars, N_sim; seed=seed) target_ages = [6, 16, 26, 36] # ages 30, 40, 50, 60 (relative to t=1 at age 25) m_assets = [mean(sim.assets[:, t]) for t in target_ages] m_var_logc = [var(log.(sim.consumption[:, t])) for t in target_ages]returnvcat(m_assets, m_var_logc)end# "True" parameters and data moments (ψ=0: no bequest motive)θ_true = (0.95, 2.0, 0.0)m_data =simulated_moments(θ_true; N_sim=2_000, seed=1)# MSM objective: estimate (β, σ) with ψ fixed at 0functionmsm_objective(x, m_data) β =0.8+0.19* (1/ (1+exp(-x[1]))) # map to (0.8, 0.99) σ =exp(x[2]) θ = (β, σ, 0.0) m_sim =simulated_moments(θ; N_sim=5_000) diff = m_data .- m_simreturn diff'* diffend
msm_objective (generic function with 1 method)
This estimator is computationally intensive — each evaluation of the objective requires solving the dynamic programming problem and simulating the model.
Let’s check the model fit by simulating at both the true and estimated parameters.
# Simulate at estimated and true parametersθ_hat_msm = (β_hat, σ_hat, 0.0)A_hat, pars_hat =setup_and_solve(θ_hat_msm)sim_hat =simulate_panel(A_hat, pars_hat, 5_000)A_true, pars_true =setup_and_solve(θ_true)sim_true =simulate_panel(A_true, pars_true, 2_000; seed=1)T = pars_true.Tages =25.+ (1:T)target_ages_actual = [30, 40, 50, 60]target_periods = target_ages_actual .-24# periods corresponding to target ages# Mean assets over the life cyclep1 =plot(ages, mean(sim_true.assets[:, 1:T], dims=1)', label="Data (true θ)", linewidth=2, color=MCM.charcoal, xlabel="Age", ylabel="Mean Assets", title="Mean Assets")plot!(p1, ages, mean(sim_hat.assets[:, 1:T], dims=1)', label="Estimated θ", linewidth=2, color=MCM.teal, linestyle=:dash)vline!(p1, target_ages_actual, color=MCM.gray, alpha=0.3, linestyle=:dot, label=false)# Variance of log consumption over the life cyclevar_logc_true = [var(log.(sim_true.consumption[:, t])) for t in1:T]var_logc_hat = [var(log.(sim_hat.consumption[:, t])) for t in1:T]p2 =plot(ages, var_logc_true, label="Data (true θ)", linewidth=2, color=MCM.charcoal, xlabel="Age", ylabel="Var(log c)", title="Variance of Log Consumption")plot!(p2, ages, var_logc_hat, label="Estimated θ", linewidth=2, color=MCM.teal, linestyle=:dash)vline!(p2, target_ages_actual, color=MCM.gray, alpha=0.3, linestyle=:dot, label=false)plot(p1, p2, layout=(1,2), size=(800, 350))
The discrete jumps visible in the estimated profiles are a consequence of the discrete asset grid — the policy function maps to grid points, so small parameter changes can cause the optimal grid point to jump (see Section 14.2.1).
Non-Differentiability of Simulated Moments
Notice that we used the Nelder-Mead algorithm above — a derivative-free optimizer. This is not a coincidence. In the savings model, the policy function \(A(\varepsilon,a,t)\) maps to a discrete asset grid, so the simulated consumption and asset paths are step functions of the parameters \(\theta\). As \(\theta\) changes continuously, the optimal grid point occasionally jumps, producing discontinuities in the simulated moments. This is the same non-differentiability problem discussed in Section 14.2.1, now appearing in the MSM context.
Gradient-based optimizers will fail here because the numerical gradient is zero almost everywhere and undefined at the jumps. Derivative-free methods like Nelder-Mead avoid this issue entirely. Alternatives include using a finer asset grid (which reduces the size of the jumps), interpolating the policy function between grid points to smooth the simulated moments, or using kernel-smoothed simulators.
Fixing Simulation Error
Notice in Example 15.2 that we fixed the seed of the simulation when we call the function simulate_panel. What do you think would happen if we failed to do this inside our optimization routine?
15.2 Indirect Inference
Indirect inference is a simulation-based estimator that works by fitting an auxiliary model to both the real data and to data simulated from the structural model, and then finding the structural parameters that make the two sets of auxiliary estimates as close as possible.
15.2.1 Setup
Let \(\hat{\beta}_{N}\) be a vector of statistics estimated from the data (the “auxiliary parameters”). For example, \(\hat{\beta}\) might be OLS coefficients from a wage regression, or the parameters of a reduced-form probit. The key requirement is that \(\hat{\beta}\) is asymptotically normal:
Now, for each candidate \(\theta\), simulate data from the structural model and compute the same statistic on the simulated data, yielding \(\hat{\beta}^{R}(\theta)\). Let \(\beta(\theta)=\text{plim}\ \hat{\beta}^{R}(\theta)\) denote the “pseudo-true” value of the auxiliary parameter implied by \(\theta\). The indirect inference estimator is:
where \(\nabla_{\theta}\beta_{0}=\frac{\partial\beta(\theta_{0})'}{\partial\theta}\).
The variance formula has the same sandwich structure as minimum distance estimation (Theorem 13.7), which makes sense: indirect inference is a simulated minimum distance estimator where the reduced-form statistics play the role of \(\pi\).
15.2.3 Relationship to MSM
Indirect inference nests MSM as a special case. If the auxiliary model consists of sample moments \(\hat{\beta}=\frac{1}{N}\sum_{n}g(\mathbf{w}_{n})\) and the simulated counterpart is \(\hat{\beta}^{R}(\theta)=\frac{1}{NR}\sum_{r}\sum_{n}g(\mathbf{w}_{n}^{r}(\theta))\), then the indirect inference estimator reduces to MSM. The appeal of indirect inference is that it allows the use of richer auxiliary models — like regressions or multinomial choice models — that can capture complex features of the data.
Discussion: Choosing Auxiliary Statistics
The choice of auxiliary model is both an art and a science. A good auxiliary model should:
Be sensitive to the structural parameters of interest (for efficiency).
Capture the key features of the data that the structural model is designed to explain.
Be computationally cheap to estimate (since it must be re-estimated on each simulated dataset).
In practice, it is useful to think of the auxiliary model as a diagnostic: if the structural model cannot match the auxiliary estimates, it suggests the model is missing something important. This perspective connects indirect inference to the broader goal of model evaluation.
15.3 Practical Considerations
15.3.1 Simulation Noise and Smoothing
When simulation draws are held fixed across evaluations of the objective function, the simulated objective is a smooth function of \(\theta\) (assuming the model itself is smooth in \(\theta\)). This means standard gradient-based optimizers can be used. If simulation draws are re-drawn at each evaluation, the objective becomes noisy and optimization may fail or converge to the wrong point. Always fix the random seed when evaluating the simulated objective across different \(\theta\) values. ### How Many Draws?
For MSM, consistency holds for any fixed \(R\), but efficiency improves with \(R\). A practical approach is to start with a moderate \(R\) for exploration, then increase \(R\) and check that the estimates are stable. If the estimates change substantially, \(R\) is too small.
For MSL, the bias from taking logarithms of simulated probabilities is of order \(1/R\). In practice, \(R\) should be large enough that this bias is negligible relative to the standard error.
15.3.2 Choosing Moments for MSM
In Example 15.2 we chose a small set of moments. In practice, the choice of moments should be guided by:
Identification: the moments should be informative about the parameters. Moments that are insensitive to a parameter will not help estimate it.
Parsimony: more moments improve efficiency (in principle) but increase computational cost and can lead to poorly conditioned weighting matrices.
Model fit: if the model cannot match a particular moment, including it will distort the estimates of other parameters. Start with moments the model should be able to match.
The discussion in the identification chapter on which moments pin down which preference parameters is directly relevant here.
15.3.3 Diagonal Weighting Matrices
When using MSM or minimum distance with many moments, the optimal weighting matrix \(\mathbf{W}^{*}=\hat{S}^{-1}\) can be poorly estimated and lead to erratic results in finite samples. A common and practical alternative is to use a diagonal weighting matrix, where each moment is weighted by the inverse of its variance but cross-moment covariances are ignored. This sacrifices some efficiency but tends to be much more stable in practice.
15.4 Exercises
Exercise
Exercise 15.1 Estimate the preference parameters \((\beta,\sigma)\) of the savings model (with \(\psi=0\)) using the method of simulated moments. Take the income process parameters as given from Example 12.2.
Choose a set of target moments from the PSID data (Example 10.1) that are informative about \((\beta,\sigma)\). Justify your choice based on the identification discussion in the savings identification chapter.
Implement the MSM estimator using the simulation code from Example 15.1.
Report your estimates and plot the model fit for your chosen moments.
Assess sensitivity: how do the estimates change when you use a different set of moments?
Newey, Whitney K, and Daniel McFadden. 1994. “Large Sample Estimation and Hypothesis Testing.”Handbook of Econometrics 4: 2111–2245.