Compared to NRLS the two-step estimator of Class 12 trades efficiency for speed. Aguirregabiria & Mira (2002) provides the middle ground: the estimation algorithm that allows the researcher to decide how much of the model to solve, and how much to rely on the data. The main idea: use the Bellman equation as a fixed point in the space of choice probabilities, and iterate on it only as many times as the data requires.
Running the code for this lecture
The code for this class is in the folder session14-npl/ of the course code
repository. The module ccp.py there collects the two-step CCP estimator of
Class 13, the first-stage CCPs and the second-stage logit, and it
reuses zurcher.py, nfxp.py and the bus data from session10-11/, so keep both
folders side by side.
You should have cloned that repository already β if not, the instructions are in the algorithms and complexity lecture.
Update your copy before the class. Editing a file in place makes git pull refuse to
update it, so discard whatever you changed while experimenting:
cd sb-dse-code
git reset --hard HEAD
git pullNothing in this repository is submitted, so experiment freely β but copy anything you want to keep out of it first, or commit that to a branch of your own.
Setting up the Python environment is covered in Python.
Homework theta_npl: iterating the two-step CCP estimator
Graded homework: task theta_npl in the class repository. Collect it and work on a
copy in your own repository:
git pull upstream main # collect the task
cp -r tasks/theta_npl solutions/theta_npl # work on the copyTake the two-step CCP estimator of Class 13 and turn it into an iterative procedure similar to NPL.
The notebook npl_iterated_ccp.ipynb in the task folder fetches the code of the
NFXP estimator and of the two-step CCP estimator, ccp.py, and carries
the details of the task.
Submit it as a pull request, following the git workflow. One of you presents a solution at the start of the next Tuesday class.
From value space to probability spaceΒΆ
Like all CCP-based methods, pseudo-likelihood estimation starts with the consistent estimation of the CCPs and transition probabilities from the data. Letβs focus on the specification of the statistical criterion for the second stage. Return to the representation of the integrated value function through the correction terms,
Using the definition of the choice-specific value functions
we have
which is linear in once the CCPs are held fixed. Again assuming a discrete state space and stacking , , and across the state space to form column vectors, we can write the last equation for every point of the state space in matrix form,
where is the element-wise (Hadamard) product of vectors. Let
be the unconditional transition matrix, the same Markov chain whose
stationary distribution was computed in homework zeta_zurcher, and denote by
again the identity matrix of the same size. Then the linear system solves as
This is the policy evaluation step of policy iterations, where the policy is given by the CCPs. Recall that the correction term is a function of the CCPs only, and therefore we can introduce an operator
that maps the CCPs into the integrated value functions. Finally, denote by
the mapping from the integrated value functions to the CCPs given by the choice probability formulas of Class 12, which in the simple EV1 case take the form of the multinomial logit
We have encountered Policy Iteration (or Howard ) just before talking about the NewtonβKantorovich iterations in Class 9. Compare the definition of operator and the operations required to evaluate it to the definition of the Howard policy iteration to convince yourself that is the Howard operator in the CCP space (and so the maximum is replaced by the logit formula).
Note that depends on the structural parameters of the model through and , so we write when the dependence matters.
The original fixed point problem in value space is thereby reformulated as a fixed point problem in probability space. One application of is one policy evaluation, a linear solve, followed by one policy improvement, a logit formula, so successive approximations converge as fast as policy iterations do.
Pseudo-maximum likelihood estimationΒΆ
The operator turns any first-stage CCP estimate into a set of model-implied choice probabilities, and those can be put into a likelihood.
The pseudo-likelihood function is the log-likelihood of the observed choices evaluated at rather than at the solution of the model,
and the pseudo-maximum likelihood estimator is its maximizer,
The pseudo-likelihood is the likelihood of a model that has been solved for one policy iteration only, starting from the data. The resulting algorithm is a two-step estimator in the sense of Class 12, with a particular choice of criterion:
Input: panel data (x_it, d_it)
Algorithm:
1. First stage: estimate PΜ(d|x) and Ξ Μ(d) for all x and d
2. Specify the pseudo-likelihood β_n(ΞΈ) = Ξ£ log Ξ¨(PΜ,ΞΈ)(d_it|x_it)
using the estimated CCPs and transition probabilities
3. Maximize β_n(ΞΈ) over ΞΈ
Output: ΞΈΜ_PMLEvery evaluation of costs one application of , which is one linear solve, instead of a full solution of the model. Because is held fixed inside the maximization, the gradient of is the gradient of a static logit with the value function differences treated as a fixed regressor, and BHHH from Class 10 applies unchanged.
Where it breaks: in finite samples, exactly where the two-step estimator breaks. The criterion is a likelihood only in name, since the probabilities are computed at and not at the modelβs own fixed point, and the first-stage noise passes through into every term.
Asymptotically nothing is lost, though, against the conventional wisdom of the time: Aguirregabiria & Mira (2002) show that has the same limiting distribution as the MLE. The price is paid in finite samples, where its error is several times that of the MLE.
Swapping the nested fixed pointΒΆ
Aguirregabiria and Mira take this idea a step further and develop the nested pseudo-likelihood (NPL) estimator, which is nothing else but the iteration of the pseudo-maximum likelihood estimator, with the CCPs updated by at the current parameter estimate after every maximization:
The name says what happened to NFXP. There, the outer loop climbs the likelihood and the inner loop solves the model to convergence at every step. Here the loops are swapped: the outer loop takes one policy iteration step on the CCPs, and the inner loop maximizes a pseudo-likelihood in which the CCPs are fixed.
Input: panel data (x_it, d_it), first-stage estimates PΜ_0 and Ξ Μ(d)
Algorithm:
for K = 1, 2, ...
1. ΞΈΜ_K = argmax_ΞΈ Ξ£ log Ξ¨(PΜ_{K-1},ΞΈ)(d_it|x_it) # pseudo-likelihood step
2. PΜ_K = Ξ¨(PΜ_{K-1}, ΞΈΜ_K) # policy iteration step
3. stop when βPΜ_K - PΜ_{K-1}β < tol
Output: ΞΈΜ_K for the chosen K, and the NPL fixed point (ΞΈΜ, PΜ) in the limitThis is an intuitive definition of the NPL operator, the fixed point of which provides the NPL estimator.
The pair at convergence satisfies two conditions: , so is the solution of the model at , and the first order conditions of the pseudo-likelihood at , which at this fixed point coincide with the likelihood equations of NFXP (shown below).
The sequence of estimatorsΒΆ
Stopping the iteration after steps gives a whole class of estimators, which Aguirregabiria & Mira (2002) call the -stage policy iteration estimators. They bridge the gap between the two-step CCP estimator and NFXP:
is the pseudo-maximum likelihood estimator above. It is a HotzβMiller CCP estimator whose moment conditions use the scores of the pseudo-likelihood, , as instruments
: if the iterations converge, the limit is a root of the likelihood equations, that is, the NFXP estimator when the likelihood has a single root
every in between is -consistent, asymptotically normal and asymptotically equivalent to the MLE, as shown below
each stage costs one policy iteration, a linear solve of the size of the state space, plus one pseudo-likelihood maximization, in which is fixed and no matrix is inverted again
The last point is the computational case for NPL. With EV1 shocks and utility linear in the parameters, , the pseudo-likelihood is a static logit with fixed regressors: globally concave in , so Newton or BHHH converges from any starting value.
Why the first stage washes outΒΆ
All the econometric results of Aguirregabiria & Mira (2002) rest on one property of the policy iteration operator.
The intuition is an envelope argument. Treat the CCPs as the controls of a reformulated problem, with the value of following them. At the optimal the value is maximized, so a small change in the CCPs changes values, and hence , only to second order. The second bullet answers the question put above about the cost of : one application of is one NewtonβKantorovich step.
What does the zero Jacobian buy? Differentiate the fixed point with respect to by the implicit function theorem, which applies because the matrix in brackets is the identity at :
so the pseudo-score evaluated at equals the score of the likelihood, . Two results follow:
NPL is NFXP at convergence (Proposition 3). Suppose the pseudo-likelihood maximization in step 1 has a unique interior solution for any sample and any . If the NPL iterations converge to , then and is a root of the likelihood equations. This holds for the full likelihood as well as the partial one.
Convergence itself is not proved. The paper only shows that NPL converges locally with probability approaching one as grows. Neither NFXP nor NPL guarantees the global maximum, so both should be started from several points.
Asymptotics of the -stage estimatorsΒΆ
The paper follows the partial likelihood strategy of NFXP: the transition probabilities are estimated first from the observed transitions, is known, and is estimated given .
The first stage drops out because of the zero Jacobian. In a Taylor expansion of the first order conditions of , the first-stage error enters as
and the bracket converges to zero by the zero Jacobian and the information matrix equality, while stays bounded in probability. Therefore:
the precision of the first stage does not matter asymptotically, so any -consistent first stage will do: the frequency estimator, with empty cells set to zero, nearest neighbors or a kernel
standard errors need no fixed point: is estimated with in place of
a CCP estimator need not be inefficient. What costs efficiency is the representation of the value function used in the second stage, not the two-step structure
The representation matters because Hotz and Miller also proposed a cheaper one for models with a terminating action, which equals only at the fixed point and has no zero Jacobian. CCP estimators built on it are not asymptotically equivalent to the MLE. The one-period finite dependence of Class 13 is of the same kind: it uses the CCPs one period ahead instead of the full , which is consistent with the standard error of found there, 5.4 against 0.3 for NFXP.
Finite sample evidenceΒΆ
Asymptotic equivalence says nothing about finite samples, which is where one-stage estimators earned their bad reputation. The Monte Carlo of the paper uses Rustβs bus model at the ML estimates, , , , on a 201-point grid: 1000 samples of 1000 observations each, with a kernel first stage.
| 1-PI | 2-PI | 3-PI | MLE | |
|---|---|---|---|---|
| mean absolute error, vs MLE | +4.7% | +1.6% | +0.3% | 2.08 |
| mean absolute error, vs MLE | +18.7% | +1.5% | +0.2% | 0.17 |
| standard deviation, vs MLE | +11.0% | +1.3% | +0.2% | 0.16 |
| estimated s.e. / Monte Carlo s.d. | 0.80 | 1.01 | 1.03 | 1.02 |
| estimated s.e. / Monte Carlo s.d. | 0.67 | 1.04 | 1.08 | 1.07 |
The MLE column gives the levels; the other entries in the first three rows are differences relative to the MLE. The table says:
precision improves monotonically with , and almost all of the gain comes from the second stage
the 1-stage standard errors are too small, by 20% for and a third for , so inference after one stage overstates precision
On speed, policy iterations take almost all of the estimation time once the grid exceeds 200 points, and their number does not depend on the grid size.
NFXP needed 5.5 times as many policy iterations as NPL with 2 parameters and 9 times with 4, starting both from the HotzβMiller estimate, and 10 and 15 times from arbitrary starting values.
Their NFXP solved the inner problem by policy iterations, which are NewtonβKantorovich steps, warm-started at the previous CCPs and with an analytical gradient, so this is a comparison with a strong NFXP.
Where it breaks: the NPL iterations are successive approximations on , and nothing guarantees that this map is a contraction.
In single-agent models it usually is, since alone is a policy iteration step, but the parameter update can push it out of the contraction region when the first stage is poor.
In dynamic games is not a contraction in general, the NPL fixed point need not be unique, and the iterations can converge to a fixed point that is not the MLE, or fail to converge at all, see Pesendorfer & Schmidt-Dengler (2010).
NPL at convergence solves the same fixed point as NFXP. Where does the computational saving come from, then?
Why does the asymptotic distribution not depend on , while the finite sample distribution does?
NFXP versus -stage NPL: what actually differsΒΆ
Same first-order asymptotics under correct specification (Proposition 4). The differences:
Finite samples depend on the first stage: large error at small , close to NFXP after 2β3 stages Kasahara & Shimotsu, 2008
Standard errors at are too small, accurate from
-stage NPL needs a -consistent first stage: every state observed, no zero CCPs, no unobserved heterogeneity
Misspecification breaks the equivalence: different have different probability limits, none equal to that of NFXP
The NPL limit is a root of the likelihood equations, not necessarily the maximum; in games it can be inconsistent Pesendorfer & Schmidt-Dengler, 2010
NFXP is the MLE; -stage NPL approximates it.
In the end the model is solved anywayΒΆ
Estimation is not the goal. A structural model is estimated to run counterfactuals, such as the demand for engine replacement as a function of its price in Rustβs paper, and a counterfactual needs the solution of the model under the counterfactual scenario.
Why can the CCP shortcut not be used there too?
The first-stage CCPs describe the status quo only. A counterfactual changes a primitive, or or the transitions, and with it the behavior. Data on behavior under the new primitives do not exist, so cannot stand in for it.
The counterfactual CCPs are a fixed point, at the counterfactual parameters , which is the model solved in probability space. The demand curve of Class 10 is one such solution per point of the price grid.
The baseline must come from the model as well. After a full NPL run is already the modelβs fixed point at . After or 2 stages it is not, and comparing a model-generated counterfactual with a data-generated baseline mixes the effect of the policy with the misfit of the model.
What the CCP and NPL methods save, then, is the repeated solution of the model inside the estimation loop, hundreds of fixed points in NFXPβs outer iterations, not the solution itself. The machinery of this class is reused for it: by Proposition 1 iterating from converges to the counterfactual fixed point at the speed of NewtonβKantorovich.
The counterfactual also needs everything the CCP estimators sidestep. has to be known, and the normalization of the flow utilities, harmless for estimation, is not harmless for every counterfactual: see the identification discussion of Class 12 and Kalouptsidi et al. (2021).
NFXP, two-step CCP and NPL on Zurcherβs dataΒΆ
The three estimators on the bus data of Rust (groups 1β4, 175 mileage bins), with the transition probabilities fixed at their frequency estimates. Both CCP-based estimators start from the same first stage, a logit in Chebyshev polynomials of degree 3, and NPL is shown at every step until the CCPs stop changing.
Source
import sys, pathlib, tempfile, urllib.request
import numpy as np
for folder, files in (('session10-11', ('zurcher.py', 'nfxp.py', 'busdata1234.csv')),
('session14-npl', ('ccp.py',))):
path = pathlib.Path('../gh-code') / folder # the code of Classes 10-11 and of this class
if not path.exists(): # otherwise fetch it from the code repository
path = pathlib.Path(tempfile.mkdtemp())
url = f'https://raw.githubusercontent.com/fediskhakov/sb-dse-code/main/{folder}/'
for f in files:
urllib.request.urlretrieve(url + f, path / f)
sys.path.insert(0, str(path))
import nfxp, ccp
def npl_regressors(model, pk):
'''Policy valuation at pk = P(keep|x): v(x,keep) - v(x,replace) = h[x] @ (RC, c) + e[x]'''
n, beta = model.n, model.beta
Fk = model.trpr # transitions after keep
Fr = np.tile(model.trpr[0], (n, 1)) # after replace: row 0 for every x
FU = Fr + pk[:, None] * (Fk - Fr) # unconditional transitions under pk
Hk = np.column_stack([np.zeros(n), -0.001 * model.grid]) # u(x,keep) = Hk @ (RC, c)
Hr = np.column_stack([-np.ones(n), np.zeros(n)]) # u(x,replace) = Hr @ (RC, c)
ent = -pk * np.log(pk) - (1 - pk) * np.log(1 - pk) # sum_d P(d) e(d), gamma dropped
rhs = np.column_stack([Hr + pk[:, None] * (Hk - Hr), ent])
W = np.linalg.solve(np.eye(n) - beta * FU, rhs) # policy valuation, linear in (RC, c)
Z = np.column_stack([Hk - Hr, np.zeros(n)]) + beta * (Fk - Fr) @ W
return Z[:, :2], Z[:, 2]
def npl_estimate(model, pk, tol=1e-8, maxiter=100, callback=None):
'''NPL from the first-stage pk = P(keep|x); returns theta, se, loglik, pk at the fixed point'''
keep = (model.d == 0).astype(float)
for k in range(maxiter):
h, e = npl_regressors(model, pk)
theta, se, ll = ccp.logit_mle(h[model.x], keep, e[model.x]) # pseudo-likelihood step
pk1 = ccp.logit_binary(h @ theta + e) # policy iteration step
err = np.abs(pk1 - pk).max()
if callback is not None:
callback(K=k+1, theta=theta, se=se, loglik=ll, pk=pk1, err=err)
if err < tol: break
pk = pk1
else:
raise RuntimeError('Failed to converge in %d iterations' % maxiter)
return theta, se, ll, pk1
data = nfxp.read_busdata() # bus groups 1-4, 175 bins
model = nfxp.estim_zurcher(data) # p from the transition frequencies
r = nfxp.estim_zurcher(data).estimate(full=False) # NFXP partial likelihood, same p
ccp_theta, ccp_se, ccp_ll = ccp.ccp_second_stage(model, ccp.flexible_logit(model, 3))
rows = {'NFXP': (r.theta, r.se, r.stages[0]['loglik_choice'], None),
'Two-step CCP, degree 3': (ccp_theta, ccp_se, ccp_ll, None)}
def add_kstage(K, theta, se, loglik, err, **kwargs):
'''Callback: one row of the table per NPL step'''
rows[f'NPL, K = {K}'] = (theta, se, loglik, err)
npl_estimate(model, ccp.flexible_logit(model, 3, keep=True), callback=add_kstage)
print(f'{"":<24}{"RC (s.e.)":>17}{"c (s.e.)":>17}{"loglik":>10}{"max dP":>10}')
for name, (t, s, ll, e) in rows.items():
print(f'{name:<24}{f"{t[0]:.3f} ({s[0]:.3f})":>17}{f"{t[1]:.3f} ({s[1]:.3f})":>17}'
f'{ll:10.2f}' + ('' if e is None else f'{e:10.1e}')) RC (s.e.) c (s.e.) loglik max dP
NFXP 9.769 (1.226) 1.343 (0.315) -300.57
Two-step CCP, degree 3 17.471 (0.499) 1.324 (5.423) -296.77
NPL, K = 1 9.627 (0.904) 1.245 (0.238) -301.03 4.6e-01
NPL, K = 2 9.749 (0.927) 1.321 (0.263) -300.80 2.2e-01
NPL, K = 3 9.786 (0.918) 1.342 (0.255) -300.67 8.2e-02
NPL, K = 4 9.791 (0.899) 1.349 (0.244) -300.59 2.2e-02
NPL, K = 5 9.775 (0.884) 1.345 (0.235) -300.57 2.7e-03
NPL, K = 6 9.769 (0.880) 1.343 (0.233) -300.57 1.6e-04
NPL, K = 7 9.769 (0.880) 1.343 (0.233) -300.57 1.1e-05
NPL, K = 8 9.769 (0.880) 1.343 (0.233) -300.57 7.5e-07
NPL, K = 9 9.769 (0.880) 1.343 (0.233) -300.57 5.2e-08
NPL, K = 10 9.769 (0.880) 1.343 (0.233) -300.57 3.6e-09
The last column is the largest change in the CCPs between consecutive NPL steps.
The NPL fixed point is the NFXP estimate, to the last digit of , and the log-likelihood, after 10 policy iterations, as Proposition 3 says.
One NPL step already lands close: moves from 9.63 to 9.77 over the remaining steps, while the two-step CCP estimator of Class 13, started from the same first stage, puts at 17.5. The difference is the representation of the future: against the CCPs one period ahead.
The standard error of is 5.4 for the two-step CCP estimator against 0.2β0.3 for the others, the efficiency loss of a representation without the zero Jacobian.
The log-likelihood of the two-step CCP estimator is the highest, because nothing ties its first-stage CCPs to the estimated parameters, so it is not a better fit.
NFXP and NPL report different standard errors for the same estimate: NFXP uses the outer product of the scores (BHHH), NPL the Hessian of the pseudo-likelihood, which at the fixed point is the information matrix. The Hessian-based standard errors of NFXP are close to those of NPL.
- Aguirregabiria, V., & Mira, P. (2002). Swapping the Nested Fixed Point Algorithm: A Class of Estimators for Discrete Markov Decision Models. Econometrica, 70(4), 1519β1543. 10.1111/1468-0262.00340
- Aguirregabiria, V., & Mira, P. (2007). Sequential Estimation of Dynamic Discrete Games. Econometrica, 75(1), 1β53. 10.1111/j.1468-0262.2007.00731.x
- Pesendorfer, M., & Schmidt-Dengler, P. (2010). Sequential Estimation of Dynamic Discrete Games: A Comment. Econometrica, 78(2), 833β842. 10.3982/ECTA7633
- Kasahara, H., & Shimotsu, K. (2008). Pseudo-likelihood estimation and bootstrap inference for structural discrete Markov decision models. Journal of Econometrics, 146(1), 92β106. 10.1016/j.jeconom.2008.07.004
- Kalouptsidi, M., Scott, P. T., & Souza-Rodrigues, E. (2021). Identification of counterfactuals in dynamic discrete choice models. Quantitative Economics, 12(2), 351β403. 10.3982/QE1253
- Aguirregabiria, V., & Marcoux, M. (2021). Imposing equilibrium restrictions in the estimation of dynamic discrete games. Quantitative Economics, 12(4), 1223β1271. 10.3982/QE1735
- Aguirregabiria, V., & Mira, P. (2010). Dynamic discrete choice structural models: A survey. Journal of Econometrics, 156(1), 38β67. 10.1016/j.jeconom.2009.09.007