Code should execute sequentially if run in a Jupyter notebook

# Optimal Taxation with State-Contingent Debt¶

## Overview¶

This lecture describes a celebrated model of optimal fiscal policy by Robert E. Lucas, Jr., and Nancy Stokey [LS83].

The model revisits classic issues about how to pay for a war

The model features

• a government that must finance an exogenous stream of government expenditures with either

• a flat rate tax on labor, or
• purchases and sales of some a full array of Arrow state contingent securities
• a representative consumer who values consumption and leisure

• a linear production function mapping labor into a single good

• a Ramsey planner who at time $$t=0$$ chooses a plan for taxes and trades of Arrow securities for all $$t \geq 0$$

After first presenting the model in a space of sequences, we shall represent it recursively in terms of two Bellman equations formulated along lines that we encountered in Dynamic Stackelberg models

As in Dynamic Stackelberg models, to apply dynamic programming we shall define the state vector artfully

In particular, we shall include forward-looking variables that summarize optimal responses of private agents to a Ramsey plan

See Optimal taxation for an analysis within a linear-quadratic setting

## A competitive equilibrium with distorting taxes¶

For $$t \geq 0$$, a history $$s^t = [s_t, s_{t-1}, \ldots, s_0]$$ of an exogenous state $$s_t$$ has joint probability density $$\pi_t(s^t)$$

We begin by assuming that government purchases $$g_t(s^t)$$ at time $$t \geq 0$$ depend on $$s^t$$

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$$ and date $$t$$

A representative household is endowed with one unit of time 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 $$c_t(s^t)$$ and $$g_t(s^t)$$

(2)$c_t(s^t) + g_t(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 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$$

There are complete markets in one-period Arrow securities

One unit of an Arrow security issued at time $$t$$ at history $$s^t$$ and promising to pay one unit of time $$t+1$$ consumption in state $$s_{t+1}$$ costs $$p_t(s_{t+1}|s^t)$$

The government issues one-period Arrow securities each period

The government has a sequence of budget constraints whose time $$t \geq 0$$ component is

(4)$g_t(s^t) = \tau_t(s^t) n_t(s^t) + \sum_{s_{t+1}} p_t(s_{t+1} | s^t) b_{t+1}(s_{t+1} | s^t) - b_t(s_t | s^{t-1})$

where

• $$p_t(s_{t+1}|s^t)$$ is a competitive equilibrium price of one unit of consumption at date $$t+1$$ in state $$s_{t+1}$$ at date $$t$$ and history $$s^t$$
• $$b_t(s_t|s^{t-1})$$ is government debt falling due at time $$t$$, history $$s^t$$.

Here $$p_t(s_{t+1}|s^t)$$ is the price of an Arrow security

Government debt $$b_0(s_0)$$ is an exogenous initial condition

The representative household has a sequence of budget constraints whose time $$t\geq 0$$ component is

(5)$c_t(s^t) + \sum_{s_{t+1}} p_t(s_{t+1} | s^t) b_{t+1}(s_{t+1} | s^t) = \left[1-\tau_t(s^t)\right] n_t(s^t) + b_t(s_t | s^{t-1}) \quad \forall t \geq 0.$

A government policy is an exogenous sequence $$\{g(s_t)\}_{t=0}^\infty$$, a tax rate sequence $$\{\tau_t(s^t)\}_{t=0}^\infty$$, and a government debt sequence $$\{b_{t+1}(s^{t+1})\}_{t=0}^\infty$$

A feasible allocation is a consumption-labor supply plan $$\{c_t(s^t), n_t(s^t)\}_{t=0}^\infty$$ that satisfies (2) at all $$t, s^t$$

A price system is a sequence of Arrow securities prices $$\{p_t(s_{t+1} | s^t) \}_{t=0}^\infty$$

The household faces the price system as a price-taker and takes the government policy as given.

The household chooses $$\{c_t(s^t), \ell_t(s^t)\}_{t=0}^\infty$$ to maximize (3) subject to (5) and (1) for all $$t, s^t$$

A competitive equilibrium with distorting taxes is a feasible allocation, a price system, and a government policy such that

• Given the price system and the government policy, the allocation solves household’s optimization problem.
• Given the allocation, government policy, and price system, the government’s budget constraint is satisfied for all $$t, s^t$$

Note

There is a large number of competitive equilibria with distorting taxes, indexed by different government policies.

The Ramsey problem or optimal taxation problem is to choose a competitive equilibrium with distorting taxes that maximizes (3)

### Arrow-Debreu version of price system¶

We find it convenient sometimes to work with the Arrow-Debreu price system implied by a sequence of Arrow securities prices

Let $$q_t^0(s^t)$$ be the price at time $$0$$, measured in time $$0$$ consumption goods, of one unit of consumption at time $$t$$, history $$s^t$$

The following recursion relates Arrow-Debreu prices $$\{q_t^0(s^t)\}_{t=0}^\infty$$ to the Arrow securities prices $$\{p_{t}(s_{t+1}|s^t)\}_{t=0}^\infty$$

(6)$q^0_{t+1}(s^{t+1}) = p_t(s_{t+1}|s^t) q^0_t(s^t)$

subject to $$q_0^0(s^0) = 1$$

These Arrow-Debreu prices are useful when we want to compress a sequence of budget constraints into a single intertemporal budget constraint, as we shall find it convenient to do below.

### Primal approach¶

We apply a popular approach to solving a Ramsey problem, called the primal approach

The idea is to use first-order conditions for household optimization to eliminate taxes and prices in favor of quantities, then pose an optimum problem cast entirely in terms of quantities

After Ramsey quantities have been found, taxes and prices can then be unwound from the allocation

The primal approach uses four steps:

1. Obtain the first-order conditions of the household’s problem and solve these conditions for $$\{q^0_t(s^t), \tau_t(s^t)\}_{t=0}^\infty$$ as functions of the allocation $$\{c_t(s^t), n_t(s^t)\}_{t=0}^\infty$$.

2. Substitute these expressions for taxes and prices in terms of the allocation into the household’s present-value budget constraint

• This intertemporal constraint involves only the allocation and is regarded as an implementability constraint.
3. Find the allocation that maximizes the utility of the representative consumer (3) subject to the feasibility constraints (1) and (2) and the implementability condition derived in step 2.

• This optimal allocation is called the Ramsey allocation.
4. Use the Ramsey allocation together with the formulas from step 1 to find taxes and prices.

### The implementability constraint¶

By sequential substitution of one one-period budget constraint (5) into another, we can obtain the household’s present-value budget constraint:

(7)$\sum_{t=0}^\infty\ \sum_{s^t} q^0_t(s^t) c_t(s^t) = \sum_{t=0}^\infty\ \sum_{s^t} q^0_t(s^t) [1-\tau_t(s^t)] w_t(s^t) n_t(s^t) + b_0$

Here $$\{q^0_t(s^t)\}_{t=1}^\infty$$ can be interpreted as a time $$0$$ Arrow-Debreu price system

To approach the Ramsey problem, we study the household’s optimization problem

First-order conditions for the household’s problem for $$\ell_t(s^t)$$ and $$b_t(s_{t+1}| s^t)$$, respectively, imply

(8)$(1 - \tau_t(s^t)) = {\frac{u_l(s^t)}{u_c(s^t)}}$

and

(9)$p_{t+1}(s_{t+1}| s^t) = \beta \pi(s_{t+1} | s^t) \left({\frac{u_c(s^{t+1})}{u_c({s^t})}} \right)$

where $$\pi(s_{t+1} | s^t)$$ is the probability distribution of $$s_{t+1}$$ conditional on history $$s^t$$

Equation (9) implies that the Arrow-Debreu price system satisfies

(10)$q_t^0(s^t) = \beta^{t} \pi_{t}(s^{t}) {u_c(s^{t}) \over u_c(s^0)}$

Use the first-order conditions (8) and (9) to eliminate taxes and prices from (7) to derive the implementability condition

(11)$\sum_{t=0}^\infty\ \sum_{s^t} \beta^t \pi_t(s^t) [u_c(s^t) c_t(s^t) - u_\ell(s^t) n_t(s^t)] - u_c(s^0) b_0 = 0.$

The Ramsey problem is to choose a feasible allocation that maximizes

(12)$\sum_{t=0}^\infty\ \ \sum_{s^t} \beta^t \pi_t(s^t) u[c_t(s^t), 1 - n_t(s^t)]$

subject to (11)

### Solution details¶

First define a “pseudo utility function”

(13)$V\left[c_t(s^t), n_t(s^t), \Phi\right] = u[c_t(s^t),1-n_t(s^t)] + \Phi \left[ u_c(s^t) c_t(s^t) - u_\ell(s^t) n_t(s^t) \right],$

where $$\Phi$$ is a Lagrange multiplier on the implementability condition (7).

Next form the Lagrangian

(14)$J = \sum_{t=0}^\infty \sum_{s^t} \beta^t \pi_t(s^t) \Bigl\{ V[c_t(s^t), n_t(s^t), \Phi] + \theta_t(s^t) \Bigl[ n_t(s^t) - c_t(s^t) - g_t(s_t) \Bigr] \Bigr\} - \Phi u_c(0) b_0$

where $$\{\theta_t(s^t); \forall s^t\}_{t\geq0}$$ is a sequence of Lagrange multipliers on the feasible conditions (2)

For given initial government debt $$b_0$$, we want to maximize $$J$$ with respect to $$\{c_t(s^t), n_t(s^t); \forall s^t \}_{t\geq0}$$ and to minimize with respect to $$\{\theta(s^t); \forall s^t \}_{t\geq0}$$.

The first-order conditions for the Ramsey problem for periods $$t \geq 1$$ and $$t=0$$, respectively, are

(15)\begin{split} \begin{aligned} c_t(s^t)\rm{:} & \; (1+\Phi) u_c(s^t) + \Phi \left[u_{cc}(s^t) c_t(s^t) - u_{\ell c}(s^t) n_t(s^t) \right] - \theta_t(s^t) = 0, \quad t \geq 1, \\ n_t(s^t)\rm{:} & \; -(1+\Phi) u_{\ell}(s^t) - \Phi \left[u_{c\ell}(s^t) c_t(s^t) - u_{\ell \ell}(s^t) n_t(s^t) \right] + \theta_t(s^t) = 0, \quad t \geq 1 \end{aligned}\end{split}

and

(16)\begin{split}\begin{aligned} c_0(s^0, b_0)\rm{:} & \; (1+\Phi) u_c(s^0, b_0) + \Phi \left[u_{cc}(s^0, b_0) c_0(s^0, b_0) - u_{\ell c}(s^0, b_0) n_0(s^0, b_0) \right] - \theta_0(s^0, b_0) \\ & \quad \quad \quad \quad \quad \quad - \Phi u_{cc}(s^0, b_0) b_0 = 0, \\ n_0(s^0, b_0)\rm{:} & \; -(1+\Phi) u_{\ell}(s^0, b_0) - \Phi \left[u_{c\ell}(s^0, b_0) c_0(s^0, b_0) - u_{\ell \ell}(s^0, b_0) n_0(s^0, b_0) \right] + \theta_0(s^0, b_0) \\ & \quad \quad \quad \quad \quad \quad + \Phi u_{c \ell}(s^0, b_0) b_0 = 0. \end{aligned}\end{split}

It is instructive to use first-order conditions (15) for $$t \geq 1$$ to eliminate the multipliers $$\theta_t(s^t)$$

For convenience, we suppress the time subscript and the index $$s^t$$ and obtain

(17)\begin{split}\begin{aligned} (1+\Phi) &u_c(c,1-c-g) + \Phi \bigl[c u_{cc}(c,1-c-g) - (c+g) u_{\ell c}(c,1-c-g) \bigr] \\ &= (1+\Phi) u_{\ell}(c,1-c-g) + \Phi \bigl[c u_{c\ell}(c,1-c-g) - (c+g) u_{\ell \ell}(c,1-c-g) \bigr], \end{aligned}\end{split}

where we have imposed conditions (1) and (2)

Equation (17) is one equation that can be solved to express the unknown $$c$$ as a function of the exogenous variable $$g$$

Notice that a counterpart to $$b_t(s_t|s^{t-1})$$ does not appear in (17), so $$c$$ does not depend on it for $$t \geq 1$$

But things are different for time $$t=0$$

An analogous argument for the $$t=0$$ equations (16) leads to one equation that can be solved for $$c_0$$ and a function of the pair $$(g(s_0), b_0)$$

These outcomes mean that the following statement would be true even when government purchases are history-dependent functions $$g_t(s^t)$$ of the history of $$s^t$$

Proposition: If government purchases are equal after two histories $$s^t$$ and $$\tilde s^\tau$$ for $$t,\tau\geq0$$, i.e., if

$g_t(s^t) = g^\tau(\tilde s^\tau)=g,$

then it follows from (17) that the Ramsey choices of consumption and leisure, $$(c_t(s^t),\ell_t(s^t))$$ and $$(c_j(\tilde s^\tau),\ell_j(\tilde s^\tau))$$, are identical.

The proposition asserts that the optimal allocation is a function of the currently realized quantity of government purchases $$g$$ only and does not depend on the specific history preceding that realization of $$g$$

### The Ramsey allocation for a given $$\Phi$$¶

Temporarily take $$\Phi$$ as given.

We shall compute $$c_0(s^0, b_0)$$ and $$n_0(s^0, b_0)$$ from the first-order conditions (16).

Evidently, for $$t \geq 1$$, $$c$$ and $$n$$ depend on the time $$t$$ realization of $$g$$ only.

But for $$t=0$$, $$c$$ and $$n$$ depend on both $$g_0$$ and the government’s initial debt $$b_0$$.

Thus, while $$b_0$$ influences $$c_0$$ and $$n_0$$, there appears no analogous variable $$b_t$$ that influences $$c_t$$ and $$n_t$$ for $$t \geq 1$$.

The absence of $$b_t$$ as a determinant of the Ramsey allocation for $$t \geq 1$$ and its presence for $$t=0$$ is a symptom of the time-inconsistency of a Ramsey plan.

$$\Phi$$ has to take a value that assures that the consumer’s and the government’s budget constraints are both satisfied at a candidate Ramsey allocation and price system associated with that $$\Phi$$.

### Further specialization¶

At this point, it is useful to specialize the model in the following ways.

We assume that $$s$$ is governed by a finite state Markov chain with states $$s\in [1, \ldots, S]$$ and transition matrix $$\Pi$$, where

$\Pi(s'|s) = {\rm Prob}(s_{t+1} = s'| s_t =s).$

Also, assume that government purchases $$g$$ are an exact time-invariant function $$g(s)$$ of $$s$$.

We maintain these assumptions throughout the remainder of this lecture.

### Determining $$\Phi$$¶

We complete the Ramsey plan by computing the Lagrange multiplier $$\Phi$$ on the implementability constraint (11)

Government budget balance restricts $$\Phi$$ via the following line of reasoning

The household’s first-order conditions imply

(18)$(1 - \tau_t(s^t)) = {\frac{u_l(s^t)}{u_c(s^t)} }$

and the implied one-period Arrow securities prices

(19)$p_{t+1}(s_{t+1}| s^t) = \beta \Pi(s_{t+1} | s_t) {\frac{u_c(s^{t+1})}{u_c({s^t})}} .$

Substituting from (18), (19), and the feasibility condition (2) into the recursive version (5) of the household budget constraint gives

(20)\begin{split}\begin{aligned} u_c(s^t) [ n_t(s^t) - g_t(s^t)] + \beta \sum_{s_{t+1}} \Pi (s_{t+1}| s_t) u_c(s^{t+1}) b_{t+1}(s_{t+1} | s^t) \\ = u_l (s^t) n_t(s^t) + u_c(s^t) b_t(s_t | s^{t-1}). \end{aligned}\end{split}

Define the product $$x_t(s^t) = u_c(s^t) b_t(s_t | s^{t-1})$$

Notice that $$x_t(s^t)$$ appears on the right side of while $$\beta$$ times the conditional expectation of $$x_{t+1}(s^{t+1})$$ appears on the left side

Hence the equation shares much of the structure of a simple asset pricing equation with $$x_t$$ being analogous to the price of the asset at time $$t$$.

We learned earlier that for a Ramsey allocation, $$c_t(s^t), n_t(s^t)$$ and $$b_t(s_t|s^{t-1})$$, and therefore also $$x_t(s^t)$$, are each functions of $$s_t$$ only, being independent of the history $$s^{t-1}$$ for $$t \geq 1$$.

That means that we can express equation (20) as

(21)$u_c(s) [ n(s) - g(s)] + \beta \sum_{s'} \Pi(s' | s) x'(s') = u_l(s) n(s) + x(s),$

where $$s'$$ denotes a next period value of $$s$$ and $$x'(s')$$ denotes a next period value of $$x$$.

Equation (21) is easy to solve for $$x(s)$$ for $$s = 1, \ldots , S$$.

If we let $$\vec n, \vec g, \vec x$$ denote $$S \times 1$$ vectors whose $$i$$th elements are the respective $$n, g$$, and $$x$$ values when $$s=i$$, and let $$\Pi$$ be the transition matrix for the Markov state $$s$$, then we can express as the matrix equation

(22)$\vec u_c(\vec n - \vec g) + \beta \Pi \vec x = \vec u_l \vec n + \vec x .$

This is a system of $$S$$ linear equations in the $$S \times 1$$ vector $$x$$, whose solution is

(23)$\vec x= (I - \beta \Pi )^{-1} [ \vec u_c (\vec n-\vec g) - \vec u_l \vec n] .$

In these equations, by $$\vec u_c \vec n$$, for example, we mean element-by-element multiplication of the two vectors.

After solving for $$\vec x$$, we can find $$b(s_t|s^{t-1})$$ in Markov state $$s_t=s$$ from $$b(s) = {\frac{x(s)}{u_c(s)}}$$ or the matrix equation

(24)$\vec b = {\frac{ \vec x }{\vec u_c}} ,$

where division here means element-by-element division of the respective components of the $$S \times 1$$ vectors $$\vec x$$ and $$\vec u_c$$.

Here is a computational algorithm:

1. Start with a guess for the value for $$\Phi$$, then use the first-order conditions and the feasibility conditions to compute $$c(s_t), n(s_t)$$ for $$s \in [1,\ldots, S]$$ and $$c_0(s_0,b_0)$$ and $$n_0(s_0, b_0)$$, given $$\Phi$$. These are $$2 (S+1)$$ equations in $$2 (S+1)$$ unknowns.

2. Solve the $$S$$ equations (23) for the $$S$$ elements of $$\vec x$$. These depend on $$\Phi$$.

3. Find a $$\Phi$$ that satisfies

(25)$u_{c,0} b_0 = u_{c,0} (n_0 - g_0) - u_{l,0} n_0 + \beta \sum_{s=1}^S \Pi(s | s_0) x(s)$

by gradually raising $$\Phi$$ if the left side of (25) exceeds the right side and lowering $$\Phi$$ if the left side is smaller.

4. After computing a Ramsey allocation, recover the flat tax rate on labor from (8) and the implied one-period Arrow securities prices from (9)

In summary, when $$g_t$$ is a time invariant function of a Markov state $$s_t$$, a Ramsey plan can be constructed by solving $$3S +3$$ equations in $$S$$ components each of $$\vec c$$, $$\vec n$$, and $$\vec x$$ together with $$n_0, c_0$$, and $$\Phi$$.

### Time inconsistency¶

Let $$\{\tau_t(s^t)\}_{t=0}^\infty, \{b_{t+1}(s_{t+1}| s^t)\}_{t=0}^\infty$$ be a time $$0$$, state $$s_0$$ Ramsey plan.

Then $$\{\tau_j(s^j)\}_{j=t}^\infty, \{b_{j+1}(s_{j+1}| s^j)\}_{j=t}^\infty$$ is a time $$t$$, history $$s^t$$ continuation of a time $$0$$, state $$s_0$$ Ramsey plan.

A time $$t$$, history $$s^t$$ Ramsey plan is a Ramsey plan that starts from initial conditions $$s^t, b_t(s_t|s^{t-1})$$.

A time $$t$$, history $$s^t$$ continuation of a time $$0$$, state $$0$$ Ramsey plan is not a time $$t$$, history $$s^t$$ Ramsey plan.

The means that a Ramsey plan is not time consistent

Another way to say the same thing is that a Ramsey plan is time inconsistent

The reason is that the continuation Ramsey plan takes $$u_{ct} b_t(s_t|s^{t-1})$$ as given, not $$b_t(s_t|s^{t-1})$$

We shall discuss this more below

## Recursive formulation of the Ramsey problem¶

$$x_t(s^t) = u_c(s^t) b_t(s_t | s^{t-1})$$ in equation (20) appears to be a purely “forward-looking” variable.

But $$x_t(s^t)$$ is also a natural candidate for a state variable in a recursive formulation of the Ramsey problem

### Intertemporal delegation¶

To express a Ramsey plan recursively, we imagine that a time $$0$$ Ramsey planner is followed by a sequence of continuation Ramsey planners at times $$t = 1, 2, \ldots$$.

A “continuation Ramsey planner” has a different objective function and faces different constraints than a Ramsey planner.

A key step in representing a Ramsey plan recursively is to regard the marginal utility scaled government debts $$x_t(s^t) = u_c(s^t) b_t(s_t|s^{t-1})$$ as predetermined quantities that continuation Ramsey planners at times $$t \geq 1$$ are obligated to attain.

Continuation Ramsey planners do this by choosing continuation policies that induce the representative household to make choices that imply that $$u_c(s^t) b_t(s_t|s^{t-1})= x_t(s^t)$$

Each time $$t\geq 1$$ continuation Ramsey planner delivers $$x_t$$ by choosing a suitable $$n_t, c_t$$ pair and a list of $$s_{t+1}$$-contingent continuation quantities $$x_{t+1}$$ to bequeath to a time $$t+1$$ continuation Ramsey planner.

A time $$t \geq 1$$ continuation Ramsey planner faces $$x_t, s_t$$ as state variables.

But the time $$0$$ Ramsey planner faces $$b_0$$, not $$x_0$$, as a state variable.

Furthermore, the Ramsey planner cares about $$(c_0(s_0), \ell_0(s_0))$$, while continuation Ramsey planners do not.

The time $$0$$ Ramsey planner hands $$x_1$$ as a function of $$s_1$$ to a time $$1$$ continuation Ramsey planner.

These lines of delegated authorities and responsibilities across time express the continuation Ramsey planners’ obligations to implement their parts of the original Ramsey plan, designed once-and-for-all at time $$0$$.

### Two Bellman equations¶

After $$s_t$$ has been realized at time $$t \geq 1$$, the state variables confronting the time $$t$$ continuation Ramsey planner are $$(x_t, s_t)$$.

• Let $$V(x, s)$$ be the value of a continuation Ramsey plan at $$x_t = x, s_t =s$$ for $$t \geq 1$$.
• Let $$W(b, s)$$ be the value of a Ramsey plan at time $$0$$ at $$b_0=b$$ and $$s_0 = s$$.

We work backwards by presenting a Bellman equation for $$V(x,s)$$ first, then a Bellman equation for $$W(b,s)$$.

### The continuation Ramsey problem¶

The Bellman equation for a time $$t \geq 1$$ continuation Ramsey planner is

(26)$V(x, s) = \max_{n, \{x'(s')\}} u(n-g(s), 1-n) + \beta \sum_{s'\in S} \Pi(s'| s) V(x', s')$

where maximization over $$n$$ and the $$S$$ elements of $$x'(s')$$ is subject to the single implementability constraint for $$t \geq 1$$

(27)$x = u_c(n-g(s)) - u_l n + \beta \sum_{s' \in {\cal S}} \Pi(s' | s) x'(s')$

Here $$u_c$$ and $$u_l$$ are today’s values of the marginal utilities.

For each given value of $$x, s$$, the continuation Ramsey planner chooses $$n$$ and an $$x'(s')$$ for each $$s' \in {\cal S}$$ .

Associated with a value function $$V(x,s)$$ that solves Bellman equation are $$S+1$$ time-invariant policy functions

(28)\begin{split}\begin{aligned} n_t & = f(x_t, s_t), \quad t \geq 1 \\ x_{t+1}(s_{t+1}) & = h(s_{t+1}; x_t, s_t), \, s_{t+1} \in {\cal S}, \, t \geq 1. \end{aligned}\end{split}

### The Ramsey problem¶

The Bellman equation for the time $$0$$ Ramsey planner is

(29)$W(b_0, s_0) = \max_{n_0, \{x'(s_1)\}} u(n_0 - g_0, 1 - n_0) + \beta \sum_{s_1 \in {\cal S}} \Pi(s_1| s_0) V( x'(s_1), s_1)$

where maximization over $$n_0$$ and the $$S$$ elements of $$x'(s_1)$$ is subject to the time $$0$$ implementability constraint

(30)$u_{c,0} b_0 = u_{c,0} (n_0 - g_0) - u_{l,0} n_0 + \beta \sum_{s_1\in {\cal S}} \Pi(s_1 | s_0) x'(s_1)$

coming from restriction (25)

Associated with a value function $$W(b_0, n_0)$$ that solves Bellman equation are $$S +1$$ time $$0$$ policy functions

(31)\begin{aligned} n_0 & = f_0(b_0, s_0) \cr x_1(s_1) & = h_0(s_1; b_0, s_0). \end{aligned}

Notice the appearance of state variables $$(b_0, s_0)$$ in the time $$0$$ policy functions for the Ramsey planner as compared to $$(x_t, s_t)$$ in the policy functions (28) for the time $$t \geq 1$$ continuation Ramsey planners.

The value function $$V(x_t, s_t)$$ of the time $$t$$ continuation Ramsey planner equals $$E_t \sum_{\tau = t}^\infty \beta^{\tau - t} u(c_t, l_t)$$, where the consumption and leisure processes are evaluated along the original time $$0$$ Ramsey plan.

### First-order conditions¶

Attach a Lagrange multiplier $$\Phi_1(x,s)$$ to constraint (27) and a Lagrange multiplier $$\Phi_0$$ to constraint (25).

Working backwards, the first-order conditions for the time $$t \geq 1$$ constrained maximization problem on the right side of the continuation Ramsey planner’s Bellman equation (26) are

(32)$\beta \Pi(s' | s) V_x (x', s') - \beta \Pi(s' | s) \Phi_1 = 0$

for $$x'(s')$$ and

(33)$(1 + \Phi_1) (u_c - u_l ) + \Phi_1 \left[ n (u_{ll} - u_{lc}) + (n-g(s)) (u_{cc} - u_{lc}) \right] = 0$

for $$n$$.

Given $$\Phi_1$$, equation (33) is one equation to be solved for $$n$$ as a function of $$s$$ (or of $$g(s)$$).

Equation (32) implies $$V_x(x', s')= \Phi_1$$, while an envelope condition is $$V_x(x,s) = \Phi_1$$, so it follows that

(34)$V_x(x', s') = V_x(x,s) = \Phi_1(x,s) .$

For the time $$0$$ problem on the right side of the Ramsey planner’s Bellman equation (29), the first-order conditions are

(35)$V_x(x(s_1), s_1) = \Phi_0$

for $$x(s_1), s_1 \in {\cal S}$$, and

(36)\begin{split}\begin{aligned} (1 + \Phi_0) (u_{c,0} - u_{n,0}) & + \Phi_0 \bigl[ n_0 (u_{ll,0} - u_{lc,0} ) + (n_0 - g(s_0)) (u_{cc,0} - u_{cl,0}) \Bigr] \\ & \quad \quad \quad - \Phi_0 (u_{cc,0} - u_{cl,0}) b_0 = 0 \end{aligned}\end{split}

Notice similarities and differences between the first-order conditions for $$t \geq 1$$ and for $$t=0$$.

An additional term is present in (36) except in three special cases in which

• $$b_0 = 0$$, or
• $$u_c$$ is constant (i.e., preferences are quasi-linear in consumption), or
• initial government assets are sufficiently large to finance all government purchases with interest earned those assets, so that $$\Phi_0= 0$$.

Except in these special cases, the allocation and the labor tax rate as functions of $$s_t$$ differ between dates $$t=0$$ and subsequent dates $$t \geq 1$$.

Naturally, the first order conditions in this recursive formulation of the Ramsey problem agree with the first-order conditions derived when we first formulated the Ramsey plan in the space of sequences

### State variable degeneracy¶

Equations (35) and (36) imply that $$\Phi_0 = \Phi_1$$ and that

(37)$V_x(x_t, s_t) = \Phi_0$

for all $$t \geq 1$$.

When $$V$$ is concave in $$x$$, this implies state-variable degeneracy along a Ramsey plan in the sense that for $$t \geq 1$$, $$x_tis a time-invariant function of :math:s_t$$.

Given $$\Phi_0$$, this function mapping $$s_t$$ into $$x_t$$ can be expressed as a vector $$\vec x$$ that solves equation (30) for $$n$$ and $$c$$ as functions of $$g$$ that are associated with $$\Phi = \Phi_0$$.

### Manifestations of time inconsistency¶

While the marginal utility adjusted level of government debt $$x_t$$ is a key state variable for the continuation Ramsey planners at $$t \geq 1$$, it is not a state variable at time $$0$$.

The time $$0$$ Ramsey planner faces $$b_0$$, not $$x_0 = u_{c,0} b_0$$, as a state variable.

The discrepancy in state variables faced by the time $$0$$ Ramsey planner and the time $$t \geq 1$$ continuation Ramsey planners captures the differing obligations and incentives faced by the time $$0$$ Ramsey planner and the time $$t \geq 1$$ continuation Ramsey planners.

• The time $$0$$ Ramsey planner is obligated to honor government debt $$b_0$$ measured in time $$0$$ consumption goods
• The time $$0$$ Ramsey planner can manipulate the value of government debt as measured by $$u_{c,0} b_0$$.
• In contrast, time $$t \geq 1$$ continuation Ramsey planners are obligated not to alter values of debt, as measured by $$u_{c,t} b_t$$, that they inherit from a preceding Ramsey planner or continuation Ramsey planner.

When government expenditures $$g_t$$ are a time invariant function of a Markov state $$s_t$$, a Ramsey plan and associated Ramsey allocation feature marginal utilities of consumption $$u_c(s_t)$$ that, given $$\Phi$$, for $$t \geq 1$$ depend only on $$s_t$$, but that for $$t=0$$ depend on $$b_0$$ as well.

This means that $$u_c(s_t)$$ will be a time invariant function of $$s_t$$ at $$t \geq 1$$, but except when $$b_0 = 0$$, a different function at $$t=0$$.

This in turn means that prices of one period Arrow securities $$p_t(s_{t+1} | s_t) = p(s_{t+1}|s_t)$$ are the same time invariant functions of $$(s_{t+1}, s_t)$$ for $$t \geq 1$$, but a different function $$p_0(s_1|s_0)$$ for $$t=0$$, except when $$b_0=0$$.

The differences between these time $$0$$ and time $$t \geq 1$$ objects reflect the Ramsey planner’s incentive to manipulate Arrow security prices and, through them, the value of initial government debt $$b_0$$.

## Examples¶

### Anticipated One Period War¶

This example illustrates in a simple setting how a Ramsey planner manages risk

Government expenditures are known for sure in all periods except one

• For $$t<3$$ and $$t > 3$$ we assume that $$g_t = g_l = 0.1$$.
• At $$t = 3$$ a war occcurs 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$$

We 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 = \left(\begin{matrix}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{matrix}\right)\end{split}$

Government expenditures at each state are

$\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 that the representative agent has utility function

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

and set $$\sigma = 2$$, $$\gamma = 2.$$, and the discount factor $$\beta = 0.9$$

Note

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

We set initial government debt $$b_0 = 1$$

The following figure plots the Ramsey tax under both realizations of time $$t=3$$ government expenditures

• black when $$g_3 = .1$$, and
• red when $$g_3 = .2$$

Tax smoothing

• the tax rate is constant for all $$t\geq 1$$

• For $$t \geq 1, t \neq 3$$, this is a consequence of $$g_t$$ being the same at all those dates
• For $$t = 3$$, it is a consequence of the special one-period utility function that we have assumed
• Under other one-period utility functions, the time $$t=3$$ tax rate could be either higher or lower than at dates $$t \geq 1, t \neq 3$$
• the tax rate is the same at $$t=3$$ for both the high $$g_t$$ outcome and the low $$g_t$$ outcome

We have assumed that at $$t=0$$, the government owes positive debt $$b_0$$

It sets the time $$t=0$$ tax rate partly with an eye to reducing the value $$u_{c,0} b_0$$ of $$b_0$$

It does this by increasing consumption at time $$t=0$$ relative to consumption in later periods

This has the consequence of raising the time $$t=0$$ value of the gross interest rate on risk-free loans between periods $$t$$ and $$t+1$$, which equals

$R_t = \frac{u_{c,t}}{\beta\mathbb E_{t}[u_{c,t+1}]}$

A tax policy that makes time $$t=0$$ consumption be higher than time $$t=1$$ consumption evidently increases the gross risk-free rate one-period interest rate, $$R_t$$, at $$t=0$$

Raising the time $$t=0$$ risk-free interest rate makes time $$t=0$$ consumption goods cheaper relative to consumption goods at later dates, thereby lowering the value $$u_{c,0} b_0$$ of initial government debt $$b_0$$

We see this in a figure below that plots the time path for the risk free interest rate under both realizations of the time $$t=3$$ government expenditure shock

The figure illustrates how the government lowers the interest rate at time 0 by raising consumption.

### Government saving¶

At time $$t=0$$ the government evidently dissaves since $$b_1> b_0$$

• This is a consequence of it setting a lower tax rate at $$t=0$$, implying more consumption at $$t=0$$

At time $$t=1$$, the government evidently saves since it has set the tax rate sufficiently high to allow it to set $$b_2 < b_1$$

• Its motive for doing this is that it anticipates a possible but uncertain war at $$t=3$$

At time $$t=2$$ the government then trades state-contingent Arrow securities to hedge against war at $$t=3$$.

• It purchases a security that pays off when $$g_3 = g_h$$
• It sells a security that pays off when $$g_3 = g_l$$
• These purchases are designed in such a way that regardless of whether or not there is a war at $$t=3$$, the government begins period $$t=4$$ with the same government debt
• The time $$t=4$$ debt level can be serviced with revenues from the constant tax rate set at times $$t\geq 1$$

At times $$t \geq 4$$ the government rolls over its debt, knowing that the tax rate is set at level required to pay both government expenditures and interest on government debt

### Time 0 manipulation of interest rate¶

We have seen that when $$b_0>0$$, the Ramsey plan sets the time $$t=0$$ tax rate partly with an eye toward raising a risk-free interest rate for one-period loans between times $$t=0$$ and $$t=1$$

By raising this interest rate, the plan makes time $$t=0$$ goods cheap relative to consumption goods at later times

By doing this, it lowers the value of time $$t=0$$ debt that it has inherited and must finance

### Time 0 and Time Inconsistency¶

In the preceding example, the Ramsey tax rate at time 0 differs from its value at time 1

To explore what is going on here, let’s simplify things by removing the possibility of war at time $$t=3$$

The Ramsey problem then includes no randomness because $$g_t = g_l$$ for all $$t$$

The figure below plots the Ramsey tax rates at time $$t=0$$ and time $$t\geq1$$ as functions of the initial government debt

The figure indicates that if the government enters with positive debt, it sets a tax rate at $$t=0$$ that is less than all later tax rates

By setting a lower tax rate at $$t = 0$$, the government raises consumption, which reduces the value $$u_{c,0} b_0$$ of its initial debt

It does this by increasing $$c_0$$ and thereby lowering $$u_{c,0}$$

Conversely, if $$b_{0} < 0$$, the Ramsey planner sets the tax rate at $$t=0$$ higher than in subsequent periods.

A side effect of lowering time $$t=0$$ consumption is that it raises the one-period interest rate at time 0 above that of subsequent periods.

There are only two values of initial government debt at which the tax rate is constant for all $$t \geq 0$$

The first is $$b_{0} = 0$$.

• Here the government can’t use the $$t=0$$ tax rate to alter the value of the initial debt

The second occurs when the government enters with sufficiently large assets that the Ramsey planner can achieve first best and sets $$\tau_t = 0$$ for all $$t$$

It is only for these two values of initial government debt that the Ramsey plan is time consistent.

Another way of saying this is that, except for these two values of initial government debt, a continuation of a Ramsey plan is not a Ramsey plan

To illustrate this, consider a Ramsey planner who starts with an initial government debt $$b_1$$ associated with one of the Ramsey plans computed above

Call $$\tau_1^R$$ the time $$t=0$$ tax rate chosen by the Ramsey planner confronting this value for initial government debt government

The figure below shows both the tax rate at time 1 chosen by our original Ramsey planner and what the new Ramsey planner would choose for its time $$t=0$$ tax rate

The tax rates in the figure are equal for only two values of initial government debt.

### Tax Smoothing and non-CES preferences¶

The complete tax smoothing for $$t \geq 1$$ in the preceding example is a consequence of our having assumed CES preferences

To see what drives this outcome, we begin by noting that the tax rate will be a time invariant function $$\tau(\Phi,g)$$ of the Lagrange multiplier $$\Phi$$ on the implementability constraint and government expenditures $$g$$

For CES preferences, we can exploit the relations $$U_{cc}c = -\sigma U_c$$ and $$U_{nn} n = \gamma U_n$$ to derive

$\frac{(1+(1-\sigma)\Phi)U_c}{1+(1-\gamma)\Phi)U_n} = 1$

from the first-order conditions for the Ramsey problem

This equation immediately implies that the tax rate is constant

For other preferences, the tax rate may not be constant

For example, let the period utility function be

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

and suppose that $$g_t$$ follows a two state i.i.d. process with equal weights on $$g_l$$ and $$g_h$$

The figure below plots a sample path of the Ramsey tax rate

We computed the tax rate by using both the sequential and recursive approaches described above

As should be expected, allocations obtained via the recursive and sequential computational approaches are virtually identical

Unlike outcomes with CES preferences, the tax rate is not perfectly smoothed

Instead the government raises the tax rate when $$g_t$$ is high

## Implementation¶

The following code implements the examples above

The module lucas_stokey.jl solves and simulates a Ramsey plan using both the recursive and sequential techniques.

We implement both techniques with types that take as an input an type called Para

Para sets numbers defining an economy, including a discount factor, a transition matrix, and a vector of government expenditures

It also contains the utility function $$U$$ and its derivatives, which allows us easily to alter the period utility function

#=

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

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
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
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
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


Numbers defining economies are in CES.jl and BGP.jl

#=

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


The file main_LS.jl solves and plots the examples.

#=

Author: Shunsuke Hori

=#
using LS
using CES
using BGP

"""
Time Varying Example
"""
PP_seq_time = LS.Planners_Allocation_Sequential(CES.M_time_example) #solve sequential problem

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.0, 1, 7, sHist_h)
sim_seq_l = LS.simulate(PP_seq_time, 1.0, 1, 7, sHist_l)

using PyPlot

plt[:figure](figsize=[14, 10])
plt[:subplot](3, 2, 1)
plt[:title]("Consumption")
plt[:plot](sim_seq_l[1], "-ok")
plt[:plot](sim_seq_h[1], "-or")
plt[:subplot](3, 2, 2)
plt[:title]("Labor Supply")
plt[:plot](sim_seq_l[2], "-ok")
plt[:plot](sim_seq_h[2], "-or")
plt[:subplot](3, 2, 3)
plt[:title]("Government Debt")
plt[:plot](sim_seq_l[3], "-ok")
plt[:plot](sim_seq_h[3], "-or")
plt[:subplot](3, 2, 4)
plt[:title]("Tax Rate")
plt[:plot](sim_seq_l[4], "-ok")
plt[:plot](sim_seq_h[4], "-or")
plt[:subplot](3, 2, 5)
plt[:title]("Government Spending")
plt[:plot](CES.M_time_example.G[sHist_l], "-ok")
plt[:plot](CES.M_time_example.G[sHist_h], "-or")
plt[:subplot](3, 2, 6)
plt[:title]("Output")
plt[:plot](CES.M_time_example.Theta[sHist_l].*sim_seq_l[2], "-ok")
plt[:plot](CES.M_time_example.Theta[sHist_h].*sim_seq_h[2], "-or")

plt[:tight_layout]()
plt[:savefig]("TaxSequence_time_varying.png")

plt[:figure](figsize=[8, 5])
plt[:title]("Gross Interest Rate")
plt[:plot](sim_seq_l[end], "-ok")
plt[:plot](sim_seq_h[end], "-or")
plt[:tight_layout]()
plt[:savefig]("InterestRate_time_varying.png")

"""
Time 0 example
"""
PP_seq_time0 = LS.Planners_Allocation_Sequential(CES.M2) #solve sequential problem

B_vec = linspace(-1.5, 1.0, 100)
taxpolicy = hcat([LS.simulate(PP_seq_time0, B_, 1, 2)[4] for B_ in B_vec]...)'
interest_rate = hcat([LS.simulate(PP_seq_time0, B_, 1, 3)[end] for B_ in B_vec]...)'

plt[:figure](figsize=(14, 6))
plt[:subplot](211)
plt[:plot](B_vec,taxpolicy[:, 1], linewidth=2.)
plt[:plot](B_vec,taxpolicy[:, 2], linewidth=2.)

plt[:title]("Tax Rate")
plt[:legend]((latexstring("Time ", "t=0"),
latexstring("Time ", L"t \geq 1")), loc=2, shadow=true)
plt[:subplot](212)
plt[:title]("Gross Interest Rate")
plt[:plot](B_vec,interest_rate[:, 1], linewidth=2.)
plt[:plot](B_vec,interest_rate[:, 2], linewidth=2.)
plt[:xlabel]("Initial Government Debt")
plt[:tight_layout]()

plt[:savefig]("Time0_taxpolicy.png")

#compute the debt entered with at time 1
B1_vec = hcat([LS.simulate(PP_seq_time0, B_, 1, 2)[3][2] for B_ in B_vec]...)'
#now compute the optimal policy if the government could reset
tau1_reset = hcat([LS.simulate(PP_seq_time0, B1, 1, 1)[4] for B1 in B1_vec]...)'

plt[:figure](figsize=[10, 6])
plt[:plot](B_vec, taxpolicy[:, 2], linewidth=2.)
plt[:plot](B_vec, tau1_reset, linewidth=2.)
plt[:xlabel]("Initial Government Debt")
plt[:title]("Tax Rate")
plt[:tight_layout]()

plt[:savefig]("Time0_inconsistent.png")

"""
BGP Example
"""
#initialize mugrid for value function iteration
muvec = linspace(-0.6, 0.0, 200)

PP_seq = LS.Planners_Allocation_Sequential(BGP.M1) #solve sequential problem

PP_bel = LS.Planners_Allocation_Bellman(BGP.M1,muvec) #solve recursive problem

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 = LS.simulate(PP_bel, 0.5, 1, T, sHist)

#plot policies
plt[:figure](figsize=[14, 10])
plt[:subplot](3, 2, 1)
plt[:title]("Consumption")
plt[:plot](sim_seq[1], "-ok")
plt[:plot](sim_bel[1], "-xk")
plt[:legend](("Sequential", "Recursive"), loc="best")
plt[:subplot](3, 2, 2)
plt[:title]("Labor Supply")
plt[:plot](sim_seq[2], "-ok")
plt[:plot](sim_bel[2], "-xk")
plt[:subplot](3, 2, 3)
plt[:title]("Government Debt")
plt[:plot](sim_seq[3], "-ok")
plt[:plot](sim_bel[3], "-xk")
plt[:subplot](3, 2, 4)
plt[:title]("Tax Rate")
plt[:plot](sim_seq[4], "-ok")
plt[:plot](sim_bel[4], "-xk")
plt[:subplot](3, 2, 5)
plt[:title]("Government Spending")
plt[:plot](BGP.M1.G[sHist], "-ok")
plt[:plot](BGP.M1.G[sHist], "-xk")
plt[:plot](BGP.M1.G[sHist], "-^k")
plt[:subplot](3, 2, 6)
plt[:title]("Output")
plt[:plot](BGP.M1.Theta[sHist].*sim_seq[2], "-ok")
plt[:plot](BGP.M1.Theta[sHist].*sim_bel[2], "-xk")

plt[:tight_layout]()
plt[:savefig]("TaxSequence_LS.png")

plt[:figure](figsize=[8, 5])
plt[:title]("Gross Interest Rate")
plt[:plot](sim_seq[end], "-ok")
plt[:plot](sim_bel[end], "-xk")
plt[:legend](("Sequential", "Recursive"), loc="best")
plt[:tight_layout]()