How to read this lecture...

Code should execute sequentially if run in a Jupyter notebook

Optimal Taxation without State-Contingent Debt

Overview

In an earlier lecture we described a model of optimal taxation with state-contingent debt due to Robert E. Lucas, Jr., and Nancy Stokey [LS83].

Aiyagari, Marcet, Sargent, and Seppälä [AMSS02] (hereafter, AMSS) studied optimal taxation in a model without state-contingent debt.

In this lecture, we

  • describe the assumptions and equilibrium concepts
  • solve the model
  • implement the model numerically and
  • conduct some policy experiments
  • compare outcomes with those in a complete-markets model

We begin with an introduction to the model.

A competitive equilibrium with distorting taxes

Many but not all features of the economy are identical to those of the Lucas-Stokey economy.

Let’s start with the things that are identical

For \(t \geq 0\), the history of the state is represented by \(s^t = [s_t, s_{t-1}, \ldots, s_0]\) .

Government purchases \(g(s)\) are an exact time-invariant function of \(s\).

Let \(c_t(s^t)\), \(\ell_t(s^t)\), and \(n_t(s^t)\) denote consumption, leisure, and labor supply, respectively, at history \(s^t\) at time \(t\).

A representative household is endowed with one unit of time each period that can be divided between leisure \(\ell_t\) and labor \(n_t\):

(1)\[n_t(s^t) + \ell_t(s^t) = 1.\]

Output equals \(n_t(s^t)\) and can be divided between consumption \(c_t(s^t)\) and \(g(s_t)\)

(2)\[c_t(s^t) + g(s_t) = n_t(s^t).\]

A representative household’s preferences over \(\{c_t(s^t), \ell_t(s^t)\}_{t=0}^\infty\) are ordered by

(3)\[\sum_{t=0}^\infty\ \ \sum_{s^t} \beta^t \pi_t(s^t) u[c_t(s^t), \ell_t(s^t)] ,\]

where

  • \(\pi_t(s^t)\) is a joint probability distribution over the sequence \(s^t\), and
  • the utility function \(u\) is increasing, strictly concave, and three times continuously differentiable in both arguments

The technology pins down a pre-tax wage rate to unity for all \(t, s^t\)

The government imposes a flat rate tax \(\tau_t(s^t)\) on labor income at time \(t\), history \(s^t\)

Lucas and Stokey assumed that there are complete markets in one-period Arrow securities.

It is at this point that AMSS [AMSS02] modify the Lucas and Stokey economy

AMSS allow the government to issue only one-period risk-free debt each period

Risk-free one-period debt only

In period \(t\) and history \(s^t\), let

  • \(b_{t+1}(s^t)\) be the amount of the time \(t+1\) consumption good that at time \(t\) the government promised to pay
  • \(R_t(s^t)\) be the gross interest rate on risk-free one-period debt between periods \(t\) and \(t+1\)
  • \(T_t(s^t)\) be a nonnegative lump-sum transfer to the representative household [1]

That \(b_{t+1}(s^t)\) is the same for all realizations of \(s_{t+1}\) captures its risk-free character

The market value at time \(t\) of government debt equals \(b_{t+1}(s^t)\) divided by \(R_t(s^t)\).

The government’s budget constraint in period \(t\) at history \(s^t\) is

(4)\[\begin{split}\begin{aligned} b_t(s^{t-1}) & = \tau^n_t(s^t) n_t(s^t) - g_t(s_t) - T_t(s^t) + {b_{t+1}(s^t) \over R_t(s^t )} \\ & \equiv z(s^t) + {b_{t+1}(s^t) \over R_t(s^t )}, \end{aligned}\end{split}\]

where \(z(s^t)\) is the net-of-interest government surplus.

To rule out Ponzi schemes, we assume that the government is subject to a natural debt limit (to be discussed in a forthcoming lecture).

The consumption Euler equation for a representative household able to trade only one-period risk-free debt with one-period gross interest rate \(R_t(s^t)\) is

\[{1 \over R_t(s^t)} = \sum_{s^{t+1}\vert s^t} \beta \pi_{t+1}(s^{t+1} | s^t) { u_c(s^{t+1}) \over u_c(s^{t}) }.\]

Substituting this expression into the government’s budget constraint (4) yields:

(5)\[b_t(s^{t-1}) = z(s^t) + \beta \sum_{s^{t+1}\vert s^t} \pi_{t+1}(s^{t+1} | s^t) { u_c(s^{t+1}) \over u_c(s^{t}) } \; b_{t+1}(s^t).\]

Components of \(z(s^t)\) on the right side depend on \(s^t\), but the left side is required to depend on \(s^{t-1}\) only

This is what it means for one-period government debt to be risk-free

Therefore, the sum on the right side of equation (5) also has to depend only on \(s^{t-1}\)

This feature will give rise to measurability constraints on the Ramsey allocation to be discussed soon

If we replace \(b_{t+1}(s^t)\) on the right side of equation (5) by the right side of next period’s budget constraint (associated with a particular realization \(s_{t}\)) we get

\[b_t(s^{t-1}) = z(s^t) + \sum_{s^{t+1}\vert s^t} \beta \pi_{t+1}(s^{t+1} | s^t) { u_c(s^{t+1}) \over u_c(s^{t}) } \, \left[z(s^{t+1}) + {b_{t+2}(s^{t+1}) \over R_{t+1}(s^{t+1})}\right].\]

After similar repeated substitutions for all future occurrences of government indebtedness, and by invoking the natural debt limit, we arrive at:

(6)\[\begin{aligned} b_t(s^{t-1}) &= \sum_{j=0}^\infty \sum_{s^{t+j} | s^t} \beta^j \pi_{t+j}(s^{t+j} | s^t) { u_c(s^{t+j}) \over u_c(s^{t}) } \;z(s^{t+j}) \end{aligned}\]

Now let’s

  • substitute the resource constraint into the net-of-interest government surplus, and
  • use the household’s first-order condition, \(1-\tau^n_t(s^t)= u_{\ell}(s^t) /u_c(s^t)\), to eliminate the labor tax rate

so that we can express the net-of-interest government surplus \(z(s^t)\) as

(7)\[z(s^t) = \left[1 - {u_{\ell}(s^t) \over u_c(s^t)}\right] \left[c_t(s^t)+g_t(s_t)\right] -g_t(s_t) - T_t(s^t)\,.\]

If we substitute the appropriate versions of right side of (7) for \(z(s^{t+j})\) in equation (6), we obtain a sequence of implementability constraints on a Ramsey allocation in an AMSS economy.

Expression (6) at time \(t=0\) and initial state \(s^0\) was also an implementability constraint on a Ramsey allocation in a Lucas-Stokey economy:

(8)\[b_0(s^{-1}) = \EE_0 \sum_{j=0}^\infty \beta^j { u_c(s^{j}) \over u_c(s^{0}) } \;z(s^{j}).\]

But now we also have a large number of additional implementability constraints

(9)\[ b_t(s^{t-1}) = \EE_t \sum_{j=0}^\infty \beta^j { u_c(s^{t+j}) \over u_c(s^{t}) } \;z(s^{t+j}).\]

Equation (9) must hold for each \(s^t\) for each \(t \geq 1\)

Comparison with Lucas-Stokey economy

The expression on the right side of (9) would in the Lucas-Stokey (1983) economy equal the present value of a continuation stream of government surpluses evaluated at what would be competitive equilbrium Arrow-Debreu prices at date \(t\)

In the Lucas-Stokey economy, that present value is measurable with respect to \(s^t\)

In the AMSS economy, the restriction that government debt be risk-free imposes that same present value be measurable with respect to \(s^{t-1}\)

In a language used in the literature on incomplete markets models, it can be said that the AMSS model requires that what would be the present value of continuation government surpluses in the Lucas-Stokey model has to be the marketable subspace of the AMSS model

Ramsey problem without state-contingent debt

After we have substituted the resource constraint into the utility function, we can express Ramsey problem as choosing an allocation that solves

\[\max_{\{c_t(s^t),b_{t+1}(s^t)\}} \EE_0 \sum_{t=0}^\infty \beta^t u\left(c_t(s^t),1-c_t(s^t)-g_t(s_t)\right)\]

where the maximization is subject to

(10)\[\EE_{0} \sum_{j=0}^\infty \beta^j { u_c(s^{j}) \over u_c(s^{0}) } \;z(s^{j}) \geq b_0(s^{-1})\]

and

(11)\[\EE_{t} \sum_{j=0}^\infty \beta^j { u_c(s^{t+j}) \over u_c(s^{t}) } \; z(s^{t+j}) = b_t(s^{t-1}) \quad \forall \, s^t\]

given \(b_0(s^{-1})\)

Lagrangian formulation

Let \(\gamma_0(s^0)\) be a nonnegative Lagrange multiplier on constraint (10)

As in the Lucas-Stokey economy, this multiplier is strictly positive if the government must resort to distortionary taxation; otherwise it equals zero

A consequence of the assumption that markets in state-contingent securities have been shut down but that a market in a risk-free security remains is that we have to attach stochastic processes \(\{\gamma_t(s^t)\}_{t=1}^\infty\) of Lagrange multipliers to the implementability constraints (11)

Depending on how the constraints bind, these multipliers might be positive or negative,

\[\begin{split}\begin{aligned} \gamma_t(s^t) &\;\geq\; (\leq)\;\, 0 \quad \text{if the constraint binds in this direction } \\ & \EE_{t} \sum_{j=0}^\infty \beta^j { u_c(s^{t+j}) \over u_c(s^{t}) } \;z(s^{t+j}) \;\geq \;(\leq)\;\, b_t(s^{t-1}). \end{aligned}\end{split}\]

A negative multiplier \(\gamma_t(s^t)<0\) means that if we could relax constraint , we would like to increase the beginning-of-period indebtedness for that particular realization of history \(s^t\)

That would let us reduce the beginning-of-period indebtedness for some other history [2]

These features flow from the fact that the government cannot use state-contingent debt and therefore cannot allocate its indebtedness efficiently across future states

Some calculations

Apply two transformations to the Lagrangian.

Multiply constraint by \(u_c(s^0)\) and the constraints by \(\beta^t u_c(s^{t})\).

Then a Lagrangian for the Ramsey problem can be represented as

(12)\[\begin{split}\begin{aligned} J &= \EE_{0} \sum_{t=0}^\infty \beta^t \biggl\{ u\left(c_t(s^t), 1-c_t(s^t)-g_t(s_t)\right)\\ & \qquad + \gamma_t(s^t) \Bigl[ \EE_{t} \sum_{j=0}^\infty \beta^j u_c(s^{t+j}) \,z(s^{t+j}) - u_c(s^{t}) \,b_t(s^{t-1}) \Bigr] \biggr\} \\ &= \EE_{0} \sum_{t=0}^\infty \beta^t \biggl\{ u\left(c_t(s^t), 1-c_t(s^t)-g_t(s_t)\right) \\ & \qquad + \Psi_t(s^t)\, u_c(s^{t}) \,z(s^{t}) - \gamma_t(s^t)\, u_c(s^{t}) \, b_t(s^{t-1}) \Bigr] \biggr\}, \end{aligned}\end{split}\]

where

(13)\[\Psi_t(s^t)=\Psi_{t-1}(s^{t-1})+\gamma_t(s^t) \quad \text{and} \quad \Psi_{-1}(s^{-1})=0.\]

In (12), the second equality uses the law of iterated expectations and Abel’s summation formula.

First-order conditions with respect to \(c_t(s^t)\) can be expressed as

(14)\[\begin{split}\begin{aligned} u_c(s^t)-u_{\ell}(s^t) &+ \Psi_t(s^t)\left\{ \left[ u_{cc}(s^t) - u_{c\ell}(s^{t})\right]z(s^{t}) + u_{c}(s^{t})\,z_c(s^{t}) \right\} \\ & \hspace{35mm} - \gamma_t(s^t)\left[ u_{cc}(s^{t}) - u_{c\ell}(s^{t})\right]b_t(s^{t-1}) =0 \end{aligned}\end{split}\]

and with respect to \(b_t(s^t)\) as

(15)\[\EE_{t} \left[\gamma_{t+1}(s^{t+1})\,u_c(s^{t+1})\right] = 0\]

If we substitute \(z(s^t)\) from (7) and its derivative \(z_c(s^t)\) into first-order condition (14), we find two differences from the corresponding condition for the optimal allocation in a Lucas-Stokey economy with state-contingent government debt.

  1. The term involving \(b_t(s^{t-1})\) in first-order condition (14) does not appear in the corresponding expression for the Lucas-Stokey economy

    • This term reflects the constraint that beginning-of-period government indebtedness must be the same across all realizations of next period’s state, a constraint that would not be present if government debt could be state contingent.
  2. The Lagrange multiplier \(\Psi_t(s^t)\) in first-order condition (14) may change over time in response to realizations of the state, while the multiplier \(\Phi\) in the Lucas-Stokey economy is time invariant.

To analyze the AMSS model, we find it useful to adopt a recursive formulation using techniques like those in the lectures on dynamic stackelberg models and optimal taxation with state-contingent debt

A recursive version of AMSS model

We now describe a recursive version of the AMSS economy.

We have noted that from the point of view of the Ramsey planner, the restriction to one-period risk-free securities

  • leaves intact the single implementability constraint on allocations (8) from the Lucas-Stokey economy, but
  • adds measurability constraints (6) on functions of tails of the allocations at each time and history.

We now explore how these constraints alter Bellman equations for a time \(0\) Ramsey planner and for time \(t \geq 1\), history \(s^t\) continuation Ramsey planners.

Recasting state variables

In the AMSS setting, the government faces a sequence of budget constraints

\[\tau_t(s^t) n_t(s^t) + T_t(s^t) + b_{t+1}(s^t)/ R_t (s^t) = g_t + b_t(s^{t-1}) ,\]

where \(R_t(s^t)\) is the gross risk-free rate of interest between \(t\) and \(t+1\) at history \(s^t\) and \(T_t(s^t)\) are nonnegative transfers.

In most of the remainder of this lecture, we shall set transfers to zero.

In this case, the household faces a sequence of budget constraints

(16)\[b_t(s^{t-1}) + (1-\tau_t(s^t)) n_t(s^t) = c_t(s^t) + b_{t+1}(s^t)/R_t(s^t) .\]

The household’s first-order conditions are \(u_{c,t} = \beta R_t \EE_t u_{c,t+1}\) and \((1-\tau_t) u_{c,t} = u_{l,t}\).

Using these to eliminate \(R_t\) and \(\tau_t\) from budget constraint (16) gives

(17)\[b_t(s^{t-1}) + \frac{u_{l,t}(s^t)}{u_{c,t}(s^t)} n_t(s^t) = c_t(s^t) + {\frac{\beta (\EE_t u_{c,t+1}) b_{t+1}(s^t)}{u_{c,t}(s^t)}}\]

or

(18)\[u_{c,t}(s^t) b_t(s^{t-1}) + u_{l,t}(s^t) n_t(s^t) = u_{c,t}(s^t) c_t(s^t) + \beta (\EE_t u_{c,t+1}) b_{t+1}(s^t)\]

Now define

(19)\[x_t \equiv \beta b_{t+1}(s^t) \EE_t u_{c,t+1} = u_{c,t} (s^t) {\frac{b_{t+1}(s^t)}{R_t(s^t)}}\]

and represent the household’s budget constraint at time \(t\), history \(s^t\) as

(20)\[{\frac{u_{c,t} x_{t-1}}{\beta \EE_{t-1} u_{c,t}}} = u_{c,t} c_t - u_{l,t} n_t + x_t\]

for \(t \geq 1\).

Measurability constraints

Write equation (18) as

(21)\[b_t(s^{t-1}) = c_t(s^t) - { \frac{u_{l,t}(s^t)}{u_{c,t}(s^t)}} n_t(s^t) + {\frac{\beta (\EE_t u_{c,t+1}) b_{t+1}(s^t)}{u_{c,t}}} ,\]

The right side of equation (21) expresses the time \(t\) value of government debt in terms of a linear combination of terms whose individual components are measurable with respect to \(s^t\)

The sum of terms on the right side of equation (21) must equal \(b_t(s^{t-1})\)

That means that is has to be measurable with respect to \(s^{t-1}\)

Equations (21) are the measurablility constraints that the AMSS model adds to the single time \(0\) implementation constraint imposed in the Lucas and Stokey model.

Two Bellman equations

Let \(\Pi(s|s_-)\) be a Markov transition matrix whose entries tell probabilities of moving from state \(s_-\) to state \(s\) in one period

Let

  • \(V(x_-, s_-)\) be the continuation value of a continuation Ramsey plan at \(x_{t-1} = x_-, s_{t-1} =s_-\) for \(t \geq 1\).
  • \(W(b, s)\) be the value of the Ramsey plan at time \(0\) at \(b_0=b\) and \(s_0 = s\).

We distinguish between two types of planners:

For \(t \geq 1\), the value function for a continuation Ramsey planner satisfies the Bellman equation

(22)\[V(x_-,s_-) = \max_{\{n(s), x(s)\}} \sum_s \Pi(s|s_-) \left[ u(n(s) - g(s), 1-n(s)) + \beta V(x(s),s) \right]\]

subject to the following collection of implementability constraints, one for each \(s \in {\cal S}\):

(23)\[{\frac{u_c(s) x_- }{\beta \sum_{\tilde s} \Pi(\tilde s|s_-) u_c(\tilde s) }} = u_c(s) (n(s) - g(s)) - u_l(s) n(s) + x(s) .\]

A continuation Ramsey planner at \(t \geq 1\) takes \((x_{t-1}, s_{t-1}) = (x_-, s_-)\) as given and chooses \((n_t(s_t), x_t(s_t)) = (n(s), x(s))\) for \(s \in {\cal S}\) before \(s\) is realized.

The Ramsey planner takes \((b_0, s_0)\) as given and chooses \((n_0, x_0)\).

The value function \(W(b_0, s_0)\) for the time \(t=0\) Ramsey planner satisfies the Bellman equation

(24)\[W(b_0, s_0) = \max_{n_0, x_0} u(n_0 - g_0, 1-n_0) + \beta V(x_0,s_0)\]

where maximization is subject to

(25)\[u_{c,0} b_0 = u_{c,0} (n_0-g_0) - u_{l,0} n_0 + x_0 .\]

Martingale supercedes state-variable degeneracy

Let \(\mu(s|s_-) \Pi(s|s_-)\) be a Lagrange multiplier on constraint (23) for state \(s\).

After forming an appropriate Lagrangian, we find that the continuation Ramsey planner’s first-order condition with respect to \(x(s)\) is

(26)\[\beta V_x(x(s),s) = \mu(s|s_-) .\]

Applying the envelope theorem to Bellman equation (22) gives

(27)\[V_x(x_-,s_-) = \sum_s \Pi(s|s_-) \mu(s|s_-) {\frac{u_c(s)}{\beta \sum_{\tilde s} \Pi(\tilde s|s_-) u_c(\tilde s) }} .\]

Equations (26) and (27) imply that

(28)\[V_x(x_-, s_-) = \sum_{s} \left( \Pi(s|s_-) {\frac{u_c(s)}{\sum_{\tilde s} \Pi(\tilde s| s_-) u_c(\tilde s)}} \right) V_x(x(s), s) .\]

Equation (28) states that \(V_x(x, s)\) is a risk-adjusted martingale

Saying that \(V_x(x, s)\) is a risk-adjusted martingale means that \(V_x(x, s)\) is a martingale with respect to the probability distribution over \(s^t\) sequences generated by the twisted transition probability matrix:

\[\check \Pi(s|s_-) \equiv \Pi(s|s_-) {\frac{u_c(s)}{\sum_{\tilde s} \Pi(\tilde s| s_-) u_c(\tilde s)}}.\]

Exercise: Please verify that \(\check \Pi(s|s_-)\) is a valid Markov transition density, in particular, that its elements are all nonnegative and that for each \(s_-\), the sum over \(s\) equals unity.

Nonnegative transfers

Suppose that instead of imposing \(T_t = 0\), we impose a nonnegativity constraint \(T_t\geq 0\) on transfers

We also consider the special case of quasi-linear preferences studied by AMSS, \(u(c,l)= c + H(l)\).

In this case, \(V_x(x,s)\leq 0\) is a non-positive martingale.

By the martingale convergence theorem \(V_x(x,s)\) converges almost surely.

Furthermore, when the Markov chain \(\Pi(s| s_-)\) and the government expenditure function \(g(s)\) are such that \(g_t\) is perpetually random, \(V_x(x, s)\) almost surely converges to zero.

For quasi-linear preferences, the first-order condition with respect to \(n(s)\) becomes

\[(1-\mu(s|s_-) ) (1 - u_l(s)) + \mu(s|s_-) n(s) u_{ll}(s) =0 .\]

When \(\mu(s|s_-) = \beta V_x(x(s),x)\) converges to zero, in the limit \(u_l(s)= 1 =u_c(s)\), so that \(\tau(x(s),s) =0\).

Thus, in the limit, if \(g_t\) is perpetually random, the government accumulates sufficient assets to finance all expenditures from earnings on those assets, returning any excess revenues to the household as nonnegative lump sum transfers.

Absence of state-variable degeneracy

Along a Ramsey plan, the state variable \(x_t = x_t(s^t, b_0)\) becomes a function of the history \(s^t\) and also the initial government debt \(b_0\).

In our recursive formulation of the Lucas-Stokey, we found that

  • the counterpart to \(V_x(x,s)\) is time invariant and equal to the Lagrange multiplier on the Lucas-Stokey implementability constraint
  • the time invariance of \(V_x(x,s)\) is the source of a key feature of the Lucas-Stokey model, namely, state variable degeneracy (i.e., \(x_t\) is an exact function of \(s_t\))

That \(V_x(x,s)\) varies over time according to a twisted martingale means that there is no state-variable degeneracy in the AMSS model

In the AMSS model, both \(x\) and \(s\) are needed to describe the state

This property of the AMSS model is what transmits a twisted martingale-like component to consumption, employment, and the tax rate

Special case of AMSS model

That the Ramsey allocation for the AMSS model differs from the Ramsey allocation of the Lucas-Stokey model is a symptom that the measurability constraints (6) bind

Following Bhandari, Evans, Golosov, and Sargent [BEGS13] (henceforth BEGS), we now consider a special case of the AMSS model in which these constraints don’t bind.

Here a Ramsey planner would choose not to issue state-contingent debt even if he were free to do so.

The environment is one in which fluctuations in the risk-free interest rate provide all of the insurance that the Ramsey planner wants.

Following BEGS, we set \(S=2\) and assume that the state \(s_t\) is i.i.d., so that the transition matrix \(\Pi(s'|s) = \Pi(s')\) for \(s=1,2\).

Following BEGS, it is useful to consider the following special case of the implementability constraints evaluated at the constant value of the state variable \(x_-= x(s) = \check x\):

(29)\[{\frac{u_c(s) \check x}{\beta \sum_{\tilde s} \Pi(\tilde s) u_c(\tilde s) }} = u_c(s) (n(s) - g(s) ) - u_l(s) n(s) + \check x, \quad s=1,2.\]

We guess and verify that the scaled Lagrange multiplier \(\mu(s)=\mu\) is a constant that is independent of \(s\).

At a fixed \(x\), because \(V_x(x, s)\) must be independent of \(s_-\), the risk-adjusted martingale equation (28) becomes

\[V_x(\check x) = \sum_{s} \left( \Pi(s) {\frac{u_c(s)}{\sum_{\tilde s} \Pi(\tilde s) u_c(\tilde s)}} \right) V_x(\check x) = V_x(\check x).\]

This confirms that \(\mu(s) = \beta V_x\) is constant at some value \(\mu\).

For the continuation Ramsey planner facing implementability constraints (29), the first-order conditions with respect to \(n(s)\) become

(30)\[\begin{split}\begin{aligned} u_c(s) - u_l(s) &\mu \times \\ &\left\{ \frac{\check x}{\beta \sum_{\tilde s} \Pi(\tilde s) u_c(\tilde s)} (u_{cc}(s) - u_{cl}(s) ) - u_c(s) - n(s) (u_{cc}(s) - u_{cl}(s)) - u_{lc}(s) n(s) + u_l(s) \right\}& \\ &&= 0. \end{aligned}\end{split}\]

Equations (30) and are four equations in the four unknowns \(\check x\), and \(\mu\) and \(n(s), s=1,2\)

Under some regularity conditions on the period utility function \(u(c,l)\), BEGS show that these equations have a unique solution that features a negative value of \(\check x\).

Consumption \(c(s)\) and the flat-rate tax on labor \(\tau(s)\) can then be constructed as history-independent functions of \(s\).

In this AMSS economy, \(\check x = x(s) = u_c(s) {\frac{b_{t+1}(s)}{R_t(s)}}\).

The risk-free interest rate, the tax rate, and the marginal utility of consumption fluctuate with \(s\), but \(x\) does not and neither does \(\mu(s)\).

The labor tax rate and the allocation depend only on the current value of \(s\).

For this special AMSS economy to be in a steady state from time \(0\) onward, it is necessary that initial debt \(b_0\) satisfy the time \(0\) implementability constraint at the value \(\check x\) and the realized value of \(s_0\).

We can solve for this level of \(b_0\) by plugging the \(n(s_0)\) and \(\check x\) that solve our four equation system into

\[u_{c,0} b_0 = u_{c,0} (n_0-g_0) - u_{l,0} n_0 + \check x\]

and solving for \(b_0\).

This \(b_0\) assures that a steady state \(\check x\) prevails from time \(0\) on.

Relationship to a Lucas-Stokey economy

The constant value of the Lagrange multiplier \(\mu(s)\) in the Ramsey plan for our special AMSS economy is a tell tale sign that the measurability restrictions imposed on the Ramsey allocation by the requirement that government debt must be risk free are slack.

When they bind, those measurability restrictions cause the AMSS tax policy and allocation to be history dependent — that’s what activates flucations in the risk-adjusted martingale.

Because those measurability conditions are slack in this special AMSS economy, we can also view this as a Lucas-Stokey economy that starts from a particular initial government debt.

The setting of \(b_0\) for the corresponding Lucas-Stokey implementability constraint solves

\[u_{c,0} b_0 = u_{c,0}(n_0 - g_0) - u_{l,0} + \beta \check x.\]

In this Lucas-Stokey economy, although the Ramsey planner is free to issue state-contingent debt, it chooses not to and instead issues only risk-free debt.

It achieves the risk-sharing it wants with the private sector by altering the amounts of one-period risk-free debt it issues at each current state, while understanding the equilibrium interest rate fluctuations that its tax policy induces.

Convergence to the special case

In an i.i.d., \(S=2\) AMSS economy in which the initial \(b_0\) does not equal the special value described in the previous subsection, \(x\) fluctuates and is history-dependent.

The Lagrange multiplier \(\mu_s(s^t)\) is a non trivial risk-adjusted martingale and the allocation and distorting tax rate are both history dependent, as is true generally in an AMSS economy.

However, BEGS describe conditions under which such an i.i.d., \(S=2\) AMSS economy in which the representative agent dislikes consumption risk converges to a Lucas-Stokey economy in the sense that \(x_t \rightarrow \check x\) as \(t \rightarrow \infty\).

The following subsection displays a numerical example that exhibits convergence.

Examples

We now turn to some computations

First we need to some code execute from our an earlier lecture on optimal taxation with state-contingent debt

#=

Author: Shunsuke Hori

=#

module LS

using QuantEcon

using NLsolve
using NLopt

mutable struct Para{TF <: AbstractFloat,
                    TM <: AbstractMatrix{TF},
                    TV <: AbstractVector{TF}}
    beta::TF
    Pi::TM
    G::TV
    Theta::TV
    transfers::Bool
    U::Function
    Uc::Function
    Ucc::Function
    Un::Function
    Unn::Function
    n_less_than_one::Bool
end

"""
Class returns planner's allocation as a function of the multiplier
on the implementability constraint mu
"""
struct Planners_Allocation_Sequential{TP <: Para,
                                      TI <: Integer,
                                      TV <: AbstractVector}
    para::TP
    mc::MarkovChain
    S::TI
    cFB::TV
    nFB::TV
    XiFB::TV
    zFB::TV
end

"""
Initializes the class from the calibration Para
"""
function Planners_Allocation_Sequential(para::Para)
    beta, Pi, G, Theta =
        para.beta, para.Pi, para.G, para.Theta
    mc = MarkovChain(Pi)
    S = size(Pi, 1) # number of states
    #now find the first best allocation
    cFB, nFB, XiFB, zFB = find_first_best(para, S, 1)

    return Planners_Allocation_Sequential(para, mc, S, cFB, nFB, XiFB, zFB)
end

"""
Find the first best allocation
"""
function find_first_best(para::Para, S::Integer, version::Integer)
    if version != 1 && version != 2
        throw(ArgumentError("version must be 1 or 2"))
    end
    beta, Theta, Uc, Un, G, Pi =
        para.beta, para.Theta, para.Uc, para.Un, para.G, para.Pi
    function res!(z, out)
        c = z[1:S]
        n = z[S+1:end]
        out[1:S] = Theta.*Uc(c, n)+Un(c, n)
        out[S+1:end] = Theta.*n - c - G
    end
    res = nlsolve(res!, 0.5*ones(2*S))

    if converged(res) == false
        error("Could not find first best")
    end

    if version == 1
        cFB = res.zero[1:S]
        nFB = res.zero[S+1:end]
        XiFB = Uc(cFB, nFB) #multiplier on the resource constraint.
        zFB = vcat(cFB, nFB, XiFB)
        return cFB, nFB, XiFB, zFB
    elseif version == 2
        cFB = res.zero[1:S]
        nFB = res.zero[S+1:end]
        IFB = Uc(cFB, nFB).*cFB + Un(cFB, nFB).*nFB
        xFB = \(eye(S) - beta*Pi, IFB)
        zFB = [vcat(cFB[s], xFB[s], xFB) for s in 1:S]
        return cFB, nFB, IFB, xFB, zFB
    end
end

"""
Computes optimal allocation for time ``t\geq 1`` for a given ``\mu``
"""
function time1_allocation(pas::Planners_Allocation_Sequential, mu::Real)
    para, S = pas.para, pas.S
    Theta, beta, Pi, G, Uc, Ucc, Un, Unn =
        para.Theta, para.beta, para.Pi, para.G,
        para.Uc, para.Ucc, para.Un, para.Unn
    function FOC!(z::Vector, out)
        c = z[1:S]
        n = z[S+1:2S]
        Xi = z[2S+1:end]
        out[1:S] = Uc(c,n) - mu*(Ucc(c,n).*c+Uc(c,n)) -Xi #foc c
        out[S+1:2S] = Un(c,n) - mu*(Unn(c,n).*n+Un(c,n)) + Theta.*Xi #foc n
        out[2S+1:end] = Theta.*n - c - G #resource constraint
        return out
    end
    #find the root of the FOC
    res = nlsolve(FOC!, pas.zFB)
    if res.f_converged == false
        error("Could not find LS allocation.")
    end
    z = res.zero
    c, n, Xi = z[1:S], z[S+1:2S], z[2S+1:end]
    #now compute x
    I  = Uc(c,n).*c +  Un(c,n).*n
    x = \(eye(S) - beta*para.Pi, I)
    return c, n, x, Xi
end

"""
Finds the optimal allocation given initial government debt `B_` and state `s_0`
"""
function time0_allocation(pas::Planners_Allocation_Sequential,
                          B_::AbstractFloat, s_0::Integer)
    para = pas.para
    Pi, Theta, G, beta =
        para.Pi, para.Theta, para.G, para.beta
    Uc, Ucc, Un, Unn =
        para.Uc, para.Ucc, para.Un, para.Unn
    #first order conditions of planner's problem
    function FOC!(z, out)
        mu, c, n, Xi = z[1], z[2], z[3], z[4]
        xprime = time1_allocation(pas, mu)[3]
        out .= vcat(
        Uc(c, n).*(c-B_) + Un(c, n).*n + beta*dot(Pi[s_0, :], xprime),
        Uc(c, n) - mu*(Ucc(c, n).*(c-B_) + Uc(c, n)) - Xi,
        Un(c, n) - mu*(Unn(c, n).*n+Un(c, n)) + Theta[s_0].*Xi,
        (Theta.*n - c - G)[s_0]
        )
    end
    #find root
    res = nlsolve(FOC!, [0.0, pas.cFB[s_0], pas.nFB[s_0], pas.XiFB[s_0]])
    if res.f_converged == false
        error("Could not find time 0 LS allocation.")
    end
    return (res.zero...)
end

"""
Find the value associated with multiplier `mu`
"""
function time1_value(pas::Planners_Allocation_Sequential, mu::Real)
    para = pas.para
    c, n, x, Xi = time1_allocation(pas, mu)
    U_val = para.U.(c, n)
    V = \(eye(pas.S) - para.beta*para.Pi, U_val)
    return c, n, x, V
end

"""
Computes Tau given `c`, `n`
"""
function Tau(para::Para, c::Union{Real,Vector}, n::Union{Real,Vector})
    Uc, Un = para.Uc.(c, n), para.Un.(c, n)
    return 1+Un./(para.Theta .* Uc)
end

"""
Simulates planners policies for `T` periods
"""
function simulate(pas::Planners_Allocation_Sequential,
                  B_::AbstractFloat, s_0::Integer, T::Integer,
                  sHist::Union{Vector, Void}=nothing)
    para = pas.para
    Pi, beta, Uc = para.Pi, para.beta, para.Uc
    if sHist == nothing
        sHist = QuantEcon.simulate(pas.mc, T, init=s_0)
    end
    cHist = zeros(T)
    nHist = zeros(T)
    Bhist = zeros(T)
    TauHist = zeros(T)
    muHist = zeros(T)
    RHist = zeros(T-1)
    #time0
    mu, cHist[1], nHist[1], _  = time0_allocation(pas, B_, s_0)
    TauHist[1] = Tau(pas.para, cHist[1], nHist[1])[s_0]
    Bhist[1] = B_
    muHist[1] = mu
    #time 1 onward
    for t in 2:T
        c, n, x, Xi = time1_allocation(pas,mu)
        u_c = Uc(c,n)
        s = sHist[t]
        TauHist[t] = Tau(pas.para, c, n)[s]
        Eu_c = dot(Pi[sHist[t-1],:], u_c)
        cHist[t], nHist[t], Bhist[t] = c[s], n[s], x[s]/u_c[s]
        RHist[t-1] = Uc(cHist[t-1], nHist[t-1])/(beta*Eu_c)
        muHist[t] = mu
    end
    return cHist, nHist, Bhist, TauHist, sHist, muHist, RHist
end

"""
Bellman equation for the continuation of the Lucas-Stokey Problem
"""
mutable struct BellmanEquation{TP <: Para,
                               TI <: Integer,
                               TV <: AbstractVector,
                               TM <: AbstractMatrix{TV},
                               TVV <: AbstractVector{TV}}
    para::TP
    S::TI
    xbar::TV
    time_0::Bool
    z0::TM
    cFB::TV
    nFB::TV
    xFB::TV
    zFB::TVV
end

"""
Initializes the class from the calibration `Para`
"""
function BellmanEquation(para::Para, xgrid::AbstractVector, policies0::Vector)
    S = size(para.Pi, 1) # number of states
    xbar = [minimum(xgrid), maximum(xgrid)]
    time_0 = false
    cf, nf, xprimef = policies0
    z0 = [vcat(cf[s](x), nf[s](x), [xprimef[s, sprime](x) for sprime in 1:S])
                        for x in xgrid, s in 1:S]
    cFB, nFB, IFB, xFB, zFB = find_first_best(para, S, 2)
    return BellmanEquation(para, S, xbar, time_0, z0, cFB, nFB, xFB, zFB)
end

"""
Finds the optimal policies
"""
function get_policies_time1(T::BellmanEquation,
                        i_x::Integer, x::AbstractFloat,
                        s::Integer, Vf::AbstractArray)
    para, S = T.para, T.S
    beta, Theta, G, Pi = para.beta, para.Theta, para.G, para.Pi
    U, Uc, Un = para.U, para.Uc, para.Un

    function objf(z::Vector, grad)
        c, xprime = z[1], z[2:end]
        n=c+G[s]
        Vprime = [Vf[sprime](xprime[sprime]) for sprime in 1:S]
        return -(U(c, n) + beta * dot(Pi[s, :], Vprime))
    end
    function cons(z::Vector, grad)
        c, xprime = z[1], z[2:end]
        n=c+G[s]
        return x - Uc(c, n)*c-Un(c, n)*n - beta*dot(Pi[s, :], xprime)
    end
    lb = vcat(0, T.xbar[1]*ones(S))
    ub = vcat(1-G[s], T.xbar[2]*ones(S))
    opt = Opt(:LN_COBYLA, length(T.z0[i_x, s])-1)
    min_objective!(opt, objf)
    equality_constraint!(opt, cons)
    lower_bounds!(opt, lb)
    upper_bounds!(opt, ub)
    maxeval!(opt, 300)
    maxtime!(opt, 10)
    init = vcat(T.z0[i_x, s][1], T.z0[i_x, s][3:end])
    for (i, val) in enumerate(init)
        if val > ub[i]
            init[i] = ub[i]
        elseif val < lb[i]
            init[i] = lb[i]
        end
    end
    (minf, minx, ret) = optimize(opt, init)
    T.z0[i_x, s] = vcat(minx[1], minx[1]+G[s], minx[2:end])
    return vcat(-minf, T.z0[i_x, s])
end
"""
Finds the optimal policies
"""
function get_policies_time0(T::BellmanEquation,
                        B_::AbstractFloat, s0::Integer, Vf::Array)
    para, S = T.para, T.S
    beta, Theta, G, Pi = para.beta, para.Theta, para.G, para.Pi
    U, Uc, Un = para.U, para.Uc, para.Un
    function objf(z, grad)
        c, xprime = z[1], z[2:end]
        n = c+G[s0]
        Vprime = [Vf[sprime](xprime[sprime]) for sprime in 1:S]
        return -(U(c, n) + beta*dot(Pi[s0, :], Vprime))
    end
    function cons(z::Vector, grad)
        c, xprime = z[1], z[2:end]
        n = c+G[s0]
        return -Uc(c, n)*(c-B_)-Un(c, n)*n - beta*dot(Pi[s0, :], xprime)
    end
    lb = vcat(0, T.xbar[1]*ones(S))
    ub = vcat(1-G[s0], T.xbar[2]*ones(S))
    opt = Opt(:LN_COBYLA, length(T.zFB[s0])-1)
    min_objective!(opt, objf)
    equality_constraint!(opt, cons)
    lower_bounds!(opt, lb)
    upper_bounds!(opt, ub)
    maxeval!(opt, 300)
    maxtime!(opt, 10)
    init = vcat(T.zFB[s0][1], T.zFB[s0][3:end])
    for (i, val) in enumerate(init)
        if val > ub[i]
            init[i] = ub[i]
        elseif val < lb[i]
            init[i] = lb[i]
        end
    end
    (minf, minx, ret) = optimize(opt, init)
    return vcat(-minf, vcat(minx[1], minx[1]+G[s0], minx[2:end]))
end


"""
Compute the planner's allocation by solving Bellman
equation.
"""
struct Planners_Allocation_Bellman{TP <: Para, TI <: Integer,
                                   TVg <: AbstractVector, TVv <: AbstractVector,
                                   TVp <: AbstractArray}
    para::TP
    mc::MarkovChain
    S::TI
    T::BellmanEquation
    mugrid::TVg
    xgrid::TVg
    Vf::TVv
    policies::TVp
end

"""
Initializes the class from the calibration `Para`
"""
function Planners_Allocation_Bellman(para::Para, mugrid::AbstractArray)
    mc = MarkovChain(para.Pi)
    G = para.G
    S = size(para.Pi, 1) # number of states
    #now find the first best allocation
    Vf, policies, T, xgrid = solve_time1_bellman(para, mugrid)
    T.time_0 = true #Bellman equation now solves time 0 problem
    return Planners_Allocation_Bellman(para, mc, S, T, mugrid, xgrid, Vf, policies)
end

"""
Solve the time 1 Bellman equation for calibration `Para` and initial grid `mugrid0`
"""
function solve_time1_bellman{TF <: AbstractFloat}(para::Para{TF}, mugrid::AbstractArray)
    mugrid0 = mugrid
    S = size(para.Pi, 1)
    #First get initial fit
    PP = Planners_Allocation_Sequential(para)
    c = Matrix{TF}(length(mugrid), 2)
    n = Matrix{TF}(length(mugrid), 2)
    x = Matrix{TF}(length(mugrid), 2)
    V = Matrix{TF}(length(mugrid), 2)
    for (i, mu) in enumerate(mugrid0)
        c[i, :], n[i, :], x[i, :], V[i, :] = time1_value(PP, mu)
    end
    Vf = Vector{LinInterp}(2)
    cf = Vector{LinInterp}(2)
    nf = Vector{LinInterp}(2)
    xprimef = Array{LinInterp}(2, S)
    for s in 1:2
        cf[s] = LinInterp(x[:, s][end:-1:1], c[:, s][end:-1:1])
        nf[s] = LinInterp(x[:, s][end:-1:1], n[:, s][end:-1:1])
        Vf[s] = LinInterp(x[:, s][end:-1:1], V[:, s][end:-1:1])
        for sprime in 1:S
            xprimef[s, sprime] = LinInterp(x[:, s][end:-1:1], x[:, s][end:-1:1])
        end
    end
    policies = [cf, nf, xprimef]
    #create xgrid
    xbar = [maximum(minimum(x, 1)), minimum(maximum(x, 1))]
    xgrid = linspace(xbar[1], xbar[2], length(mugrid0))
    #Now iterate on bellman equation
    T = BellmanEquation(para, xgrid, policies)
    diff = 1.0
    while diff > 1e-6
        if T.time_0 == false
            Vfnew, policies =
                fit_policy_function(PP,
                (i_x, x, s) -> get_policies_time1(T, i_x, x, s, Vf), xgrid)
        elseif T.time_0 == true
            Vfnew, policies =
                fit_policy_function(PP,
                (i_x, B_, s0) -> get_policies_time0(T, i_x, B_, s0, Vf), xgrid)
        else
            error("T.time_0 is $(T.time_0), which is invalid")
        end
        diff = 0.0
        for s in 1:S
            diff = max(diff, maximum(abs, (Vf[s].(xgrid)-Vfnew[s].(xgrid))./Vf[s].(xgrid)))
        end
        print("diff = $diff \n")
        Vf = Vfnew
    end
    # store value function policies and Bellman Equations
    return Vf, policies, T, xgrid
end

"""
Fits the policy functions PF using the points `xgrid` using interpolation
"""
function fit_policy_function(PP::Planners_Allocation_Sequential,
                            PF::Function, xgrid::AbstractArray)
    S = PP.S
    Vf = Vector{LinInterp}(S)
    cf = Vector{LinInterp}(S)
    nf = Vector{LinInterp}(S)
    xprimef = Array{LinInterp}(S, S)
    for s in 1:S
        PFvec = Array{typeof(PP.para).parameters[1]}(length(xgrid), 3+S)
        for (i_x, x) in enumerate(xgrid)
            PFvec[i_x, :] = PF(i_x, x, s)
        end
        Vf[s] = LinInterp(xgrid, PFvec[:, 1])
        cf[s] = LinInterp(xgrid, PFvec[:, 2])
        nf[s] = LinInterp(xgrid, PFvec[:, 3])
        for sprime in 1:S
            xprimef[s, sprime] = LinInterp(xgrid, PFvec[:, 3+sprime])
        end
    end
    return Vf, [cf, nf, xprimef]
end

"""
Finds the optimal allocation given initial government debt `B_` and state `s_0`
"""
function time0_allocation(pab::Planners_Allocation_Bellman,
                          B_::AbstractFloat, s0::Integer)
    xgrid = pab.xgrid
    if pab.T.time_0 == false
        z0 = get_policies_time1(pab.T, i_x, x, s, pab.Vf)
    elseif pab.T.time_0 == true
        z0 = get_policies_time0(pab.T, B_, s0, pab.Vf)
    else
        error("T.time_0 is $(T.time_0), which is invalid")
    end
    c0, n0, xprime0 = z0[2], z0[3], z0[4:end]
    return c0, n0, xprime0
end

"""
Simulates Ramsey plan for `T` periods
"""
function simulate(pab::Planners_Allocation_Bellman,
                B_::AbstractFloat, s_0::Integer, T::Integer,
                sHist::Vector=QuantEcon.simulate(mc, s_0, T))
    para, S, policies = pab.para, pab.S, pab.policies
    beta, Pi, Uc = para.beta, para.Pi, para.Uc
    cf, nf, xprimef = policies[1], policies[2], policies[3]
    TF = typeof(para).parameters[1]
    cHist = Vector{TF}(T)
    nHist = Vector{TF}(T)
    Bhist = Vector{TF}(T)
    TauHist = Vector{TF}(T)
    muHist = Vector{TF}(T)
    RHist = Vector{TF}(T-1)
    #time0
    cHist[1], nHist[1], xprime = time0_allocation(pab, B_, s_0)
    TauHist[1] = Tau(pab.para, cHist[1], nHist[1])[s_0]
    Bhist[1] = B_
    muHist[1] = 0.0
    #time 1 onward
    for t in 2:T
        s, x = sHist[t], xprime[sHist[t]]
        n = nf[s](x)
        c = [cf[shat](x) for shat in 1:S]
        xprime = [xprimef[s, sprime](x) for sprime in 1:S]
        TauHist[t] = Tau(pab.para, c, n)[s]
        u_c = Uc(c, n)
        Eu_c = dot(Pi[sHist[t-1], :], u_c)
        muHist[t] = pab.Vf[s](x)
        RHist[t-1] = Uc(cHist[t-1], nHist[t-1])/(beta*Eu_c)
        cHist[t], nHist[t], Bhist[t] = c[s], n, x/u_c[s]
    end
    return cHist, nHist, Bhist, TauHist, sHist, muHist, RHist
end
end

We also need the following parameterizations and utilities

#=

Author: Shunsuke Hori

=#

module CES

using LS

function baseline(;
    beta = 0.9,
    sigma = 2.0,
    gamma = 2.0,
    Pi = 0.5 *ones(2,2),
    G = [0.1, 0.2],
    Theta = ones(Float64, 2),
    transfers = false
    )
    function U(c,n)
        if sigma == 1.0
            U = log(c)
        else
            U = (c.^(1.0-sigma)-1.0)/(1.0-sigma)
        end
        return U - n.^(1+gamma)/(1+gamma)
    end
    #derivatives of utiltiy function
    Uc(c,n) =  c.^(-sigma)
    Ucc(c,n) = -sigma*c.^(-sigma-1.0)
    Un(c,n) = -n.^gamma
    Unn(c,n) = -gamma*n.^(gamma-1.0)
    n_less_than_one = false
    return LS.Para(beta, Pi, G, Theta, transfers,
                    U, Uc, Ucc, Un, Unn, n_less_than_one)
end

#Model 1
M1 = baseline()

#Model 2

M2 = baseline(G=[0.15], Pi=ones(1,1), Theta=[1.0])

#Model 3 with time varying

M_time_example = baseline(G=[0.1, 0.1, 0.1, 0.2, 0.1, 0.1],
                            Theta = ones(6)# Theta can in principle be random
                            )

M_time_example.Pi = [0.0 1.0 0.0 0.0 0.0 0.0;
                     0.0 0.0 1.0 0.0 0.0 0.0;
                     0.0 0.0 0.0 0.5 0.5 0.0;
                     0.0 0.0 0.0 0.0 0.0 1.0;
                     0.0 0.0 0.0 0.0 0.0 1.0;
                     0.0 0.0 0.0 0.0 0.0 1.0]
end
#=

Author: Shunsuke Hori

=#

module BGP
using LS
function baseline(;
    beta = 0.9,
    psi = 0.69,
    Pi = 0.5 *ones(2,2),
    G = [0.1,0.2],
    Theta = ones(2),
    transfers = false)
    #derivatives of utiltiy function
    U(c,n) = log(c) + psi*log(1-n)
    Uc(c,n) = 1./c
    Ucc(c,n) = -c.^(-2.0)
    Un(c,n) = -psi./(1.0-n)
    Unn(c,n) = -psi./(1.0-n).^2.0
    n_less_than_one = true
    return LS.Para(beta, Pi, G, Theta, transfers,
                    U, Uc, Ucc, Un, Unn, n_less_than_one)
end

#Model 1
M1 = baseline()

#Model 2

M2 = baseline()
M2.G = [0.15]
M2.Pi = ones(1,1)
M2.Theta = [1.0]
end
#=

Author: Shunsuke Hori

=#

include("lucas_stokey.jl")
using LS

using QuantEcon
using NLopt
using NLsolve
using Dierckx

Para=LS.Para
Planners_Allocation_Sequential = LS.Planners_Allocation_Sequential
"""
Bellman equation for the continuation of the Lucas-Stokey Problem
"""
type BellmanEquation{TI<:Integer,TF<:AbstractFloat}
    para::Para
    S::TI
    xbar::Array{TF}
    time_0::Bool
    z0::Array{Array}
    cFB::Vector{TF}
    nFB::Vector{TF}
    xFB::Vector{TF}
    zFB::Vector{Array}
end

"""
Compute the planner's allocation by solving Bellman
equation.
"""
type Planners_Allocation_Bellman
    para::Para
    mc::MarkovChain
    S::Integer
    T::BellmanEquation
    mugrid::Vector
    xgrid::Vector
    Vf::Array
    policies
end

"""
Initializes the type from the calibration Para
"""
function Planners_Allocation_Bellman(para::Para,mugrid::AbstractArray)
    G = para.G
    S = size(para.Pi,1) # number of states
    mc=MarkovChain(para.Pi)
    mugrid = collect(mugrid)
    #now find the first best allocation
    Vf, policies, T, xgrid = solve_time1_bellman(para, mugrid)
    T.time_0 = true #Bellman equation now solves time 0 problem
    return Planners_Allocation_Bellman(para,mc,S,T,mugrid,xgrid, Vf, policies)
end

"""
Solve the time  1 Bellman equation for calibration Para and initial grid mugrid
"""
function solve_time1_bellman{TR<:Real}(para::Para,mugrid::AbstractArray{TR})
    Pi = para.Pi
    S = size(para.Pi,1)

    #First get initial fit from lucas stockey solution.
    #Need to change things to be ex_ante
    PP = LS.Planners_Allocation_Sequential(para)

    function incomplete_allocation(PP::LS.Planners_Allocation_Sequential,
                                    mu_::AbstractFloat, s_::Integer)
        c,n,x,V = LS.time1_value(PP,mu_)
        return c,n,dot(Pi[s_,:], x), dot(Pi[s_,:], V)
    end
    cf = Array{Function}(S,S)
    nf = Array{Function}(S,S)
    xprimef = Array{Function}(S,S)
    Vf = Array{Function}(S)
    # TR=Float64
    xgrid = Array{TR}(S,length(mugrid))
    for s_ in 1:S
        c = Array{TR}(length(mugrid),S)
        n = Array{TR}(length(mugrid),S)
        x = Array{TR}(length(mugrid))
        V = Array{TR}(length(mugrid))
        for (i_mu, mu) in enumerate(mugrid)
            c[i_mu,:], n[i_mu,:], x[i_mu], V[i_mu] =
                incomplete_allocation(PP, mu, s_)
        end
        xprimes = repmat(x,1,S)
        xgrid[s_,:] = x
        for sprime = 1:S
            splc = Spline1D(x[end:-1:1],c[:,sprime][end:-1:1],k=3)
            spln = Spline1D(x[end:-1:1],n[:,sprime][end:-1:1],k=3)
            splx = Spline1D(x[end:-1:1],xprimes[:,sprime][end:-1:1],k=3)
            cf[s_,sprime] = y -> splc(y)
            nf[s_,sprime] = y -> spln(y)
            xprimef[s_,sprime] = y -> splx(y)
        end
        splV = Spline1D(x[end:-1:1],V[end:-1:1],k=3)
        Vf[s_] = y -> splV(y)
    end

    policies = [cf,nf,xprimef]

    #create xgrid
    xbar = [maximum(minimum(xgrid)), minimum(maximum(xgrid))]
    xgrid = collect(linspace(xbar[1],xbar[2],length(mugrid)))

    #Now iterate on Bellman equation
    T = BellmanEquation(para,xgrid,policies)
    diff = 1.0
    while diff > 1e-6
        PF = (i_x, x,s) -> get_policies_time1(T, i_x, x, s, Vf, xbar)
        Vfnew, policies = fit_policy_function(T, PF, xgrid)

        diff = 0.0
        for s=1:S
            diff = max(diff,maxabs((Vf[s].(xgrid)-Vfnew[s].(xgrid))./Vf[s].(xgrid)))
        end

        println("diff = $diff")
        Vf = copy(Vfnew)
    end

    return Vf, policies, T, xgrid
end

"""
Fits the policy functions
"""
function fit_policy_function{TF<:AbstractFloat}(
                    T::BellmanEquation,
                    PF::Function, xgrid::AbstractArray{TF})
    S = T.S
    # preallocation
    # TF = Float64
    PFvec = Array{TF}(4S+1,length(xgrid))
    cf = Array{Function}(S,S)
    nf = Array{Function}(S,S)
    xprimef = Array{Function}(S,S)
    TTf = Array{Function}(S,S)
    Vf = Array{Function}(S)
    # fit policy fuctions
    for s_ in 1:S
        for (i_x, x) in enumerate(xgrid)
            PFvec[:,i_x] = PF(i_x,x,s_)
        end
        splV = Spline1D(xgrid, PFvec[1,:], k=3)
        Vf[s_] = y -> splV(y)
        for sprime=1:S
            splc = Spline1D(xgrid, PFvec[1+sprime,:], k=3)
            spln = Spline1D(xgrid, PFvec[1+S+sprime,:], k=3)
            splxprime = Spline1D(xgrid, PFvec[1+2S+sprime,:], k=3)
            splTT = Spline1D(xgrid, PFvec[1+3S+sprime,:], k=3)
            cf[s_,sprime] = y -> splc(y)
            nf[s_,sprime] = y -> spln(y)
            xprimef[s_,sprime] = y -> splxprime(y)
            TTf[s_,sprime] = y -> splTT(y)
        end
    end
    policies = (cf, nf, xprimef, TTf)
    return Vf, policies
end

"""
Computes Tau given c,n
"""
function Tau(pab::Planners_Allocation_Bellman,
            c::Array,n::Array)
    para = pab.para
    Uc, Un = para.Uc(c,n), para.Un(c,n)
    return 1+Un./(para.Theta .* Uc)
end

Tau(pab::Planners_Allocation_Bellman, c::AbstractFloat,n::AbstractFloat) =
    Tau(pab, [c], [n])

"""
Finds the optimal allocation given initial government debt B_ and state s_0
"""
function time0_allocation(pab::Planners_Allocation_Bellman,
                           B_::Real,s0::Integer)
    T, Vf = pab.T, pab.Vf
    xbar = T.xbar
    z0 = get_policies_time0(T, B_, s0, Vf, xbar)

    c0, n0, xprime0, T0 = z0[2], z0[3], z0[4], z0[5]
    return c0, n0, xprime0, T0
end

"""
Simulates planners policies for T periods
"""
function simulate{TI<:Integer,TF<:AbstractFloat}(pab::Planners_Allocation_Bellman,
                   B_::TF,s_0::TI,T::TI,sHist=nothing)
    para, mc, Vf, S = pab.para, pab.mc, pab.Vf, pab.S
    Pi, Uc = para.Pi, para.Uc
    cf,nf,xprimef,TTf = pab.policies

    if sHist == nothing
        sHist = QuantEcon.simulate(mc,T,init=s_0)
    end

    cHist=Array{TF}(T)
    nHist=Array{TF}(T)
    Bhist=Array{TF}(T)
    xHist=Array{TF}(T)
    TauHist=Array{TF}(T)
    THist=Array{TF}(T)
    muHist=Array{TF}(T)

    #time0
    cHist[1],nHist[1],xHist[1],THist[1]  =
        time0_allocation(pab, B_,s_0)
    TauHist[1] = Tau(pab,cHist[1],nHist[1])[s_0]
    Bhist[1] = B_
    muHist[1] = Vf[s_0](xHist[1])

    #time 1 onward
    for t in 2:T
        s_, x, s = sHist[t-1], xHist[t-1], sHist[t]
        c = Array{TF}(S)
        n = Array{TF}(S)
        xprime = Array{TF}(S)
        TT = Array{TF}(S)
        for sprime=1:S
            c[sprime], n[sprime], xprime[sprime], TT[sprime] =
                cf[s_,sprime](x), nf[s_,sprime](x),
                xprimef[s_,sprime](x), TTf[s_,sprime](x)
        end

        Tau_val = Tau(pab, c, n)[s]
        u_c = Uc(c,n)
        Eu_c = dot(Pi[s_,:], u_c)

        muHist[t] = Vf[s](xprime[s])

        cHist[t], nHist[t], Bhist[t], TauHist[t] = c[s], n[s], x/Eu_c, Tau_val
        xHist[t],THist[t] = xprime[s],TT[s]
    end
    return cHist,nHist,Bhist,xHist,TauHist,THist,muHist,sHist
end

"""
Initializes the class from the calibration Para
"""
function BellmanEquation{TF<:AbstractFloat}(para::Para,
        xgrid::AbstractVector{TF}, policies0::Array)
    S = size(para.Pi,1) # number of states
    xbar = [minimum(xgrid),maximum(xgrid)]
    time_0 = false
    z0 = Array{Array}(length(xgrid),S)
    cf, nf, xprimef =
        policies0[1], policies0[2], policies0[3]
    for s in 1:S
        for (i_x, x) in enumerate(xgrid)
            cs=Array{TF}(S)
            ns=Array{TF}(S)
            xprimes=Array{TF}(S)
            for j=1:S
                cs[j], ns[j], xprimes[j] =
                    cf[s,j](x), nf[s,j](x), xprimef[s,j](x)
            end
            z0[i_x,s] =
                vcat(cs,ns,xprimes,zeros(S))
        end
    end
    cFB, nFB, IFB, xFB, zFB = LS.find_first_best(para, S, 2)
    return BellmanEquation(para,S,xbar,time_0,z0,cFB,nFB,xFB,zFB)
end


"""
Finds the optimal policies
"""
function get_policies_time1{TF<:AbstractFloat}(T::BellmanEquation,
        i_x::Integer, x::TF, s_::Integer, Vf::Array{Function}, xbar::Vector)
    para, S = T.para, T.S
    beta, Theta, G, Pi = para.beta, para.Theta, para.G, para.Pi
    U,Uc,Un = para.U, para.Uc, para.Un

    S_possible = sum(Pi[s_,:].>0)
    sprimei_possible = find(Pi[s_,:].>0)

    function objf(z,grad)
        c, xprime = z[1:S_possible], z[S_possible+1:2S_possible]
        n=(c+G[sprimei_possible])./Theta[sprimei_possible]
        Vprime = Vector{TF}(S_possible)
        for (si, s) in enumerate(sprimei_possible)
            Vprime[si] = Vf[s](xprime[si])
        end
        return -dot(Pi[s_,sprimei_possible], U(c,n)+beta*Vprime)
    end

    function cons(out,z,grad)
        c, xprime, TT =
            z[1:S_possible], z[S_possible+1:2S_possible], z[2S_possible+1:3S_possible]
        n=(c+G[sprimei_possible])./Theta[sprimei_possible]
        u_c = Uc(c,n)
        Eu_c = dot(Pi[s_,sprimei_possible], u_c)
        out .= x*u_c/Eu_c - u_c.*(c-TT)-Un(c,n).*n - beta*xprime
    end
    function cons_no_trans(out,z,grad)
        c, xprime =
            z[1:S_possible], z[S_possible+1:2S_possible]
        n=(c+G[sprimei_possible])./Theta[sprimei_possible]
        u_c = Uc(c,n)
        Eu_c = dot(Pi[s_,sprimei_possible], u_c)
        out .= x*u_c/Eu_c - u_c.*c-Un(c,n).*n - beta*xprime
    end

    if para.transfers == true
        lb = vcat(zeros(S_possible), ones(S_possible)*xbar[1], zeros(S_possible))
        if para.n_less_than_one == true
            ub = vcat(100*ones(S_possible)-G[sprimei_possible], ones(S_possible)*xbar[2], 100*ones(S_possible))
        else
            ub = vcat(100*ones(S_possible), ones(S_possible)*xbar[2], 100*ones(S_possible))
        end
            init = vcat(T.z0[i_x,s_][sprimei_possible],
                T.z0[i_x,s_][2S+sprimei_possible], T.z0[i_x,s_][3S+sprimei_possible])
        opt = Opt(:LN_COBYLA, 3S_possible)
        equality_constraint!(opt, cons, zeros(S_possible))
    else
        lb = vcat(zeros(S_possible), ones(S_possible)*xbar[1])
        if para.n_less_than_one == true
            ub = vcat(ones(S_possible)-G[sprimei_possible], ones(S_possible)*xbar[2])
        else
            ub = vcat(ones(S_possible), ones(S_possible)*xbar[2])
        end
        init = vcat(T.z0[i_x,s_][sprimei_possible],
                    T.z0[i_x,s_][2S+sprimei_possible])
        opt = Opt(:LN_COBYLA, 2S_possible)
        equality_constraint!(opt, cons_no_trans, zeros(S_possible))
    end
    init[init.> ub] = ub[init.> ub]
    init[init.< lb] = lb[init.< lb]

    min_objective!(opt, objf)
    lower_bounds!(opt, lb)
    upper_bounds!(opt, ub)
    maxeval!(opt, 10000000)
    maxtime!(opt, 10)
    ftol_rel!(opt, 1e-8)
    ftol_abs!(opt, 1e-8)

    (minf,minx,ret) = optimize(opt, init)

    if ret != :SUCCESS && ret != :ROUNDOFF_LIMITED && ret != :MAXEVAL_REACHED &&
         ret != :FTOL_REACHED && ret != :MAXTIME_REACHED
        error("optimization failed: ret = $ret")
    end

    T.z0[i_x,s_][sprimei_possible] = minx[1:S_possible]
    T.z0[i_x,s_][S+sprimei_possible] = minx[1:S_possible]+G[sprimei_possible]
    T.z0[i_x,s_][2S+sprimei_possible] = minx[S_possible+1:2S_possible]
    if para.transfers == true
        T.z0[i_x,s_][3S+sprimei_possible] = minx[2S_possible+1:3S_possible]
    else
        T.z0[i_x,s_][3S+sprimei_possible] = zeros(S)
    end

    return vcat(-minf, T.z0[i_x,s_])
end

"""
Finds the optimal policies
"""
function get_policies_time0(T::BellmanEquation,
        B_::Real,s0::Integer,Vf::Array{Function},xbar::Vector)
    para = T.para
    beta, Theta, G = para.beta, para.Theta, para.G
    U, Uc, Un = para.U, para.Uc, para.Un

    function objf(z,grad)
        c, xprime = z[1], z[2]
        n=(c+G[s0])/Theta[s0]
        return -(U(c,n)+beta*Vf[s0](xprime))
    end

    function cons(z,grad)
        c, xprime, TT = z[1], z[2], z[3]
        n=(c+G[s0])/Theta[s0]
        return -Uc(c,n)*(c-B_-TT)-Un(c,n)*n - beta*xprime
    end
    cons_no_trans(z,grad) = cons(vcat(z,0.0), grad)

    if para.transfers == true
        lb = [0.0, xbar[1], 0.0]
        if para.n_less_than_one == true
            ub = [1-G[s0], xbar[2], 100]
        else
            ub = [100.0, xbar[2], 100.0]
        end
        init = vcat(T.zFB[s0][1], T.zFB[s0][3], T.zFB[s0][4])
        init = [0.95124922, -1.15926816,  0.0]
        opt = Opt(:LN_COBYLA, 3)
        equality_constraint!(opt, cons)
    else
        lb = [0.0, xbar[1]]
        if para.n_less_than_one == true
            ub = [1-G[s0], xbar[2]]
        else
            ub = [100, xbar[2]]
        end
        init = vcat(T.zFB[s0][1], T.zFB[s0][3])
        init = [0.95124922, -1.15926816]
        opt = Opt(:LN_COBYLA, 2)
        equality_constraint!(opt, cons_no_trans)
    end
    init[init.> ub] = ub[init.> ub]
    init[init.< lb] = lb[init.< lb]


    min_objective!(opt, objf)
    lower_bounds!(opt, lb)
    upper_bounds!(opt, ub)
    maxeval!(opt, 100000000)
    maxtime!(opt, 30)
    # ftol_rel!(opt, 1e-16)
    # ftol_abs!(opt, 1e-16)

    (minf,minx,ret) = optimize(opt, init)

    if ret != :SUCCESS && ret != :ROUNDOFF_LIMITED && ret != :MAXEVAL_REACHED && ret != :FTOL_REACHED
        error("optimization failed: ret = $ret")
    end

    if para.transfers == true
        return -minf, minx[1], minx[1]+G[s0], minx[2], minx[3]
    else
        return -minf, minx[1], minx[1]+G[s0], minx[2], 0.0
    end
end
#=

Author: Shunsuke Hori

=#

include("CES.jl")
include("BGP.jl")
using CES
using BGP

#initialize mugrid for value function iteration
muvec = linspace(-0.7,0.01,200)

#Time Varying Example

CES.M_time_example.transfers = true #Government can use transfers
PP_seq_time = LS.Planners_Allocation_Sequential(CES.M_time_example) #solve sequential problem

PP_im_time = Planners_Allocation_Bellman(CES.M_time_example,muvec)

sHist_h = [1,2,3,4,6,6,6]
sHist_l = [1,2,3,5,6,6,6]

sim_seq_h = LS.simulate(PP_seq_time,1.,1,7,sHist_h)
sim_im_h = simulate(PP_im_time,1.,1,7,sHist_h)
sim_seq_l = LS.simulate(PP_seq_time,1.,1,7,sHist_l)
sim_im_l = simulate(PP_im_time,1.,1,7,sHist_l)

using Plots
pyplot()
p=plot(size = (700,500),layout =(3,2),
        xaxis=(0:6), grid=false, titlefont=Plots.font("sans-serif", 10))
title!(p[1],"Consumption")
plot!(p[1],0:6,sim_seq_l[1],marker=:circle,color=:black,legend=false)
plot!(p[1],0:6,sim_im_l[1],marker=:circle,color=:red,legend=false)
plot!(p[1],0:6,sim_seq_h[1],marker=:utriangle,color=:black,legend=false)
plot!(p[1],0:6,sim_im_h[1],marker=:utriangle,color=:red,legend=false)
title!(p[2],"Labor")
plot!(p[2],0:6,sim_seq_l[2],marker=:circle,color=:black,lab="Complete Markets")
plot!(p[2],0:6,sim_im_l[2],marker=:circle,color=:red,lab="Incomplete Markets")
plot!(p[2],0:6,sim_seq_h[2],marker=:utriangle,color=:black,lab="")
plot!(p[2],0:6,sim_im_h[2],marker=:utriangle,color=:red,lab="")
title!(p[3],"Government Debt")
plot!(p[3],0:6,sim_seq_l[3],marker=:circle,color=:black,legend=false)
plot!(p[3],0:6,sim_im_l[3],marker=:circle,color=:red,legend=false)
plot!(p[3],0:6,sim_seq_h[3],marker=:utriangle,color=:black,legend=false)
plot!(p[3],0:6,sim_im_h[3],marker=:utriangle,color=:red,legend=false)
title!(p[4],"Tax Rate")
plot!(p[4],0:6,sim_seq_l[4],marker=:circle,color=:black,legend=false)
plot!(p[4],0:6,sim_im_l[5],marker=:circle,color=:red,legend=false)
plot!(p[4],0:6,sim_seq_h[4],marker=:utriangle,color=:black,legend=false)
plot!(p[4],0:6,sim_im_h[5],marker=:utriangle,color=:red,legend=false)
title!(p[5],"Government Spending", ylims=(0.05,0.25))
plot!(p[5],0:6,CES.M_time_example.G[sHist_l],marker=:circle,color=:black,legend=false)
plot!(p[5],0:6,CES.M_time_example.G[sHist_l],marker=:circle,color=:red,legend=false)
plot!(p[5],0:6,CES.M_time_example.G[sHist_h],marker=:utriangle,color=:black,legend=false)
plot!(p[5],0:6,CES.M_time_example.G[sHist_h],marker=:utriangle,color=:red,legend=false)
title!(p[6],"Output")
plot!(p[6],0:6,CES.M_time_example.Theta[sHist_l].*sim_seq_l[2],marker=:circle,color=:black,legend=false)
plot!(p[6],0:6,CES.M_time_example.Theta[sHist_l].*sim_im_l[2],marker=:circle,color=:red,legend=false)
plot!(p[6],0:6,CES.M_time_example.Theta[sHist_h].*sim_seq_h[2],marker=:utriangle,color=:black,legend=false)
plot!(p[6],0:6,CES.M_time_example.Theta[sHist_h].*sim_im_h[2],marker=:utriangle,color=:red,legend=false)
savefig("TaxSequence_time_varying_AMSS.png")
p1=p

#=
BGP Example
=#
BGP.M1.transfers = false   #Government can use transfers
PP_seq = LS.Planners_Allocation_Sequential(BGP.M1) #solve sequential problem
PP_bel = LS.Planners_Allocation_Bellman(BGP.M1,muvec) #solve recursive problem
PP_im = Planners_Allocation_Bellman(BGP.M1,muvec)

T = 20
#sHist = utilities.simulate_markov(M1.Pi,0,T)
sHist = [1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1]

#simulate
sim_seq = LS.simulate(PP_seq,0.5,1,T,sHist)
#sim_bel = PP_bel.simulate(0.5,0,T,sHist)
sim_im = simulate(PP_im,0.5,1,T,sHist)

#plot policies
p=plot(size = (700,500), layout = grid(3,2),
        xaxis=(0:T), grid=false, titlefont=Plots.font("sans-serif", 10))
title!(p[1], "Consumption")
plot!(p[1], sim_seq[1], marker=:circle, color=:black, lab="Complete Markets")
#plt[:plot](sim_bel[0],"-xk")
plot!(p[1], sim_im[1], marker=:utriangle, color=:black, lab="Incomplete Markets")
title!(p[2], "Labor")
plot!(p[2], sim_seq[1], marker=:circle, color=:black, legend=false)
#plt.plot(sim_bel[1],"-xk")
plot!(p[2], sim_im[1], marker=:utriangle, color=:black, legend=false)
title!(p[3], "Government Debt")
plot!(p[3], sim_seq[2], marker=:circle, color=:black, legend=false)
#plt.plot(sim_bel[2],"-xk")
plot!(p[3], sim_im[2], marker=:utriangle, color=:black, legend=false)
title!(p[4], "Tax Rate")
plot!(p[4], sim_seq[4], marker=:circle, color=:black, legend=false)
#plt.plot(sim_bel[3],"-xk")
plot!(p[4], sim_im[5], marker=:utriangle, color=:black, legend=false)
title!(p[5], "Government Spending", ylims=(0.05,0.25))
plot!(p[5], BGP.M1.G[sHist], marker=:circle, color=:black, legend=false)
#plt.plot(M1.G[sHist],"-^k")
title!(p[6], "Output")
plot!(p[6], BGP.M1.Theta[sHist].*sim_seq[2], marker=:circle,
        color=:black, legend=false)
#plt.plot(M1.Theta[sHist]*sim_bel[1],"-xk")
plot!(p[6], BGP.M1.Theta[sHist].*sim_im[2], marker=:utriangle,
        color=:black, legend=false)
savefig("TaxSequence_AMSS.png")
p2=p

#Now long simulations
T_long = 200
sim_seq_long = LS.simulate(PP_seq, 0.5,1,T_long)
sHist_long = sim_seq_long[end-2]
sim_im_long = simulate(PP_im, 0.5,1,T_long,sHist_long)

p=plot(size = (700,500), layout = (3,2), xaxis=(0:50:T_long), grid=false,
        titlefont=Plots.font("sans-serif", 10))
title!(p[1],"Consumption")
plot!(p[1], sim_seq_long[1], color=:black, linestyle=:solid, lab="Complete Markets")
plot!(p[1], sim_im_long[1], color=:black, linestyle=:dot, lab="Incomplete Markets")
title!(p[2],"Labor")
plot!(p[2], sim_seq_long[1], color=:black, linestyle=:solid, legend=false)
plot!(p[2], sim_im_long[1], color=:black, linestyle=:dot, legend=false)
title!(p[3],"Government Debt")
plot!(p[3], sim_seq_long[2], color=:black, linestyle=:solid, legend=false)
plot!(p[3], sim_im_long[2], color=:black, linestyle=:dot, legend=false)
title!(p[4],"Tax Rate")
plot!(p[4], sim_seq_long[3], color=:black, linestyle=:solid, legend=false)
plot!(p[4], sim_im_long[4], color=:black, linestyle=:dot, legend=false)
title!(p[5],"Government Spending",ylims=(0.05,0.25))
plot!(p[5], BGP.M1.G[sHist_long], color=:black, linestyle=:solid, legend=false)
plot!(p[5], BGP.M1.G[sHist_long], color=:black, linestyle=:dot, legend=false)
title!(p[6],"Output")
plot!(p[6],BGP.M1.Theta[sHist_long].*sim_seq_long[2],
    color=:black, linestyle=:solid, legend=false)
plot!(p[6],BGP.M1.Theta[sHist_long].*sim_im_long[2],
    color=:black, linestyle=:dot, legend=false)
# plt[:tight_layout]()
savefig("Long_SimulationAMSS.png")
p3=p

#=
Show Convergence example
=#
M_convergence = CES.M1
muvec = linspace(-0.15,0.0,100) #change
PP_C = Planners_Allocation_Bellman(M_convergence,muvec)
xgrid = PP_C.xgrid
xf = PP_C.policies[end-1] #get x policies
p= plot()
for s in 1:2
    plot!(p,xgrid,xf[1,s].(xgrid)-xgrid)
end
p4=p

sim_seq_convergence = simulate(PP_C,0.5,1,2000)
sHist_long = sim_seq_convergence[end]

p=plot(size = (700,500),layout = grid(3,2), xaxis=(0:200:2000),
        grid=false, titlefont=Plots.font("sans-serif", 10))
title!("Consumption")
plot!(sim_seq_convergence[1],color=:black,
    lab=["Complete Markets" "Incomplete Markets"])
title!(p[2],"Labor")
plot!(p[2],sim_seq_convergence[2],color=:black,legend=false)
title!(p[3],"Government Debt")
plot!(p[3],sim_seq_convergence[3],color=:black,legend=false)
title!(p[4],"Tax Rate")
plot!(p[4],sim_seq_convergence[4],color=:black,legend=false)
title!(p[5],"Government Spending",ylims=(0.05,0.25))
plot!(p[5],M_convergence.G[sHist_long],color=:black,legend=false)
title!(p[6],"Output")
plot!(p[6],M_convergence.Theta[sHist_long].*sim_seq_convergence[2],color=:black,legend=false)
savefig("Convergence_SimulationAMSS.png")
p5=p

Anticipated One-Period War

In our lecture on optimal taxation with state contingent debt we studied how the government manages uncertainty in a simple setting

As in that lecture, we assume the one-period utility function

\[u(c,n) = {\frac{c^{1-\sigma}}{1-\sigma}} - {\frac{n^{1+\gamma}}{1+\gamma}}\]

Note

For convenience in matching our computer code, we have expressed utility as a function of \(n\) rather than leisure \(l\)

We consider the same government expenditure process studied in the lecture on optimal taxation with state contingent debt

Government expenditures are known for sure in all periods except one

  • For \(t<3\) or \(t > 3\) we assume that \(g_t = g_l = 0.1\).
  • At \(t = 3\) a war occurs with probability 0.5.
    • If there is war, \(g_3 = g_h = 0.2\)
    • If there is no war \(g_3 = g_l = 0.1\).

A useful trick is to define the components of the state vector as the following six \((t,g)\) pairs:

\[(0,g_l), (1,g_l), (2,g_l), (3,g_l), (3,g_h), (t\geq 4,g_l).\]

We think of these 6 states as corresponding to \(s=1,2,3,4,5,6\)

The transition matrix is

\[\begin{split}P = \begin{pmatrix} 0 & 1 & 0 & 0 & 0 & 0\\ 0 & 0 & 1 & 0 & 0 & 0\\ 0 & 0 & 0 & 0.5 & 0.5 & 0\\ 0 & 0 & 0 & 0 & 0 & 1\\ 0 & 0 & 0 & 0 & 0 & 1\\ 0 & 0 & 0 & 0 & 0 & 1 \end{pmatrix}\end{split}\]

The government expenditure at each state is

\[\begin{split}g = \left(\begin{matrix} 0.1\\0.1\\0.1\\0.1\\0.2\\0.1 \end{matrix}\right).\end{split}\]

We assume the same utility parameters as the Lucas-Stokey economy

The following figure plots the Ramsey tax policy under both complete and incomplete markets for both possible realizations of the state at time \(t=3\).

Optimal policies when the goverhment has access to state contingent debt are represented by black lines, while the optimal policies when there is only a risk free bond are in red.

Paths with circles are histories in which there is peace, while those with triangle denote war

p1
../_images/TaxSequence_time_varying_AMSS.png

How the Ramsey planner responds to war depends on the structure of the asset market.

If it is able to trade state-contingent debt, then at time \(t=2\), it increases its debt burden in the states when there is peace

That helps it to reduce the debt burden when there is war

This pattern facilities smoothing tax rates across states

The government without state contingent debt cannot do this

Instead, it must enter with the same level of debt at all possible states of the world at time \(t=3\).

It responds to this constraint by smoothing tax rates across time

To finance a war it raises taxes and issues more debt

To service the additional debt burden, it raises taxes in all future periods

The absence of state contingent debt leads to an important difference in the optimal tax policy

When the Ramsey planner has access to state contingent debt, the optimal tax policy is history independent

  • the tax rate is a function of the current level of government spending only, given the Lagrange multiplier on the implementability constraint

Without state contingent debt, the optimal tax rate is history dependent.

  • A war at time \(t=3\) causes a permanent increase in the tax rate

Perpetual War Alert

History dependence occurs more dramatically in a case where the government perpetually faces the prospect of war

This case was studied in the final example of the lecture on optimal taxation with state-contingent debt

There, each period the government faces a constant probability, \(0.5\), of war.

In addition, this example features the following preferences

\[u(c,n) = \log(c) + 0.69 \log(1-n)\]

With these preferences, Ramsey tax rates will vary even in the Lucas-Stokey model with state-contingent debt

The figure below plots the optimal tax policies for both the economy with state contingent debt (circles) and the economy with only a risk-free bond (triangles).

p2
../_images/TaxSequence_AMSS.png

When the government experiences a prolonged period of peace, it is able to reduce government debt and set permanently lower tax rates.

However, the government must finance a long war by borrowing and raising taxes.

This results in a drift away from policies with state contingent debt that depends on the history of shocks received.

This is even more evident in the following figure that plots the evolution of the two policies over 200 periods.

p3
../_images/Long_SimulationAMSS.png

Footnotes

[1]In an allocation that solves the Ramsey problem and that levies distorting taxes on labor, why would the government ever want to hand revenues back to the private sector? Not in an economy with state-contingent debt, since any such allocation could be improved by lowering distortionary taxes rather than handing out lump-sum transfers. But without state-contingent debt there can be circumstances when a government would like to make lump-sum transfers to the private sector.
[2]We will soon see from the first-order conditions of the Ramsey problem, there would then exist another realization \(\tilde s^t\) with the same history up until the previous period, i.e., \(\tilde s^{t-1}= s^{t-1}\), but where the multiplier on constraint takes on a positive value \(\gamma_t(\tilde s^t)>0\).