Loading packages, defining colors and using data

We first clear the workspace using rm(list = ls())and then include all packages we need. If a package is missing in your R distribution (which is quite likely initially), just use install.packages("package_name") with the respective package name to install it on your system. If you execute the code in the file install_packages.R, then all necessary packages will be installed into your R distribution. If the variable export_graphs is set to TRUE, then the graphs will be exported as pdf-files. In addition, we define a set of colors here to make graphs look more beautiful.

rm(list = ls())
library(reshape2)
library(base)
library(ggplot2)
library(grid)
library(scales)
library(stringr)
library(tidyverse)

# should graphs be exported to pdf
export_pdf <- FALSE

# define some colors
mygreen <- "#00BA38"
myblue  <- "#619CFF"
myred   <- "#F8766D"

The Ramsey Model setup

Before being able to simulate the model, we have to set parameters. To do so, we use five data moments. The share of labor compensation in GDP, the share of gross capital formation (investment) in GDP, the gross return to capital and the growth rates of total labor input and labor productivity. From these, we can pin down the parameters of the Ramsey model for the US economy. Having set the parameters, we can determine the balanced growth path, i.e. the steady state of the capital intensity.

# data moments
lab_share = 0.381
inv_share = 0.245
gross_ret = 0.114

# parameter choice
n     <- 0.0122
h     <- 0.0169
g     <- (1+n)*(1+h)-1
alpha <- lab_share
delta <- inv_share*gross_ret/alpha - g
beta  <- (1+g)/(1 + gross_ret - delta)
gamma <- 0.5

# steady state capital intensity under old beta
k_old <- (alpha/((1+g)/beta - 1 + delta))^(1/(1-alpha))
c_old <- k_old^alpha - (g+delta)*k_old

A guessing algorithm for the Ramsey model

In the lecture, we discussed a guessing algorithm for solving for the saddle path of the Ramsey economy. This algorithm is implemented in function `solve_ramsey’.

This function works in exactly the same way as discussed in the first part of this chapter. However, the function now takes two additional input arguments, amount and policy, that define the policy setup. policy can take the values 1, 2, or 3, with (1) denoting a permanent increase in government spending, (2) being a temporary increase in government spending and (3) implementing a change in the capital income tax. The variable amount gives the amount of government spending or the size of the capital income tax.

At the beginning of the function, we now have to set up a path for the extent of fiscal policy. It defines the levels of \(g_t\) and \(\tau_k\) over time. This path is used in the difference equations for simulating the Ramsey economy, see below.

solve_ramsey <- function(k0, amount, policy, g, alpha, delta, gamma, beta) {
  
  # set numerical parameters
  T <- 10000          # number of simulation periods
  itermax <- 1000     # maximum number of iterations
  tol <- 1e-6         # tolerance level for difference to steady state
  
  # determine path of g_t
  g_t <- 0
  tau_k <- 0
  if(policy == 1) {
    g_t[1:T] = amount
    tau_k[1:T] = 0
  } else if (policy == 2) {
    g_t[1:T] = 0
    g_t[1] = amount
    tau_k[1:T] = 0
  } else if (policy == 3) {
    g_t[1:T] = 0
    tau_k[1:T] = amount
  }
  
  # determine steady state capital intensity and consumption
  kstar <- (alpha/(((1+g)/beta - 1)/(1-tau_k[length(tau_k)]) + delta))^(1/(1-alpha))
  cstar <- kstar**alpha - (g+delta)*kstar - g_t[length(g_t)]
  
  # set starting interval depending on k0
  if(k0 <= kstar) {
    c_min <- 0
    c_max <- cstar
  } else {
    c_min <- cstar
    c_max <- k0^alpha + (1-delta)*k0
  }
  
  # start iteration process
  for (i in 1:itermax) {
    
    # start a capital and consumption path
    k <- k0
    c <- (c_min+c_max)/2
    
    # now simulate the economy forward
    for (t in 1:T) {
      
      # calculate difference to steady state
      epsilon <- sqrt((c[t]/cstar-1)^2 + (k[t]/kstar-1)^2)
      
      # if difference is small enough, that's it, we return
      if(epsilon < tol) {
        return(c(c[1], epsilon, i))
      }
      
      # determine next period's capital stock and consumption
      k[t+1] <- max((k[t]**alpha - c[t] - g_t[t] + (1-delta)*k[t])/(1+g), 1e-4)
      c[t+1] <- (beta*(1 + (1-tau_k[t])*(alpha*k[t+1]^(alpha-1) - delta))/(1+g))^gamma*c[t]
      
      #  decision rule for capital
      if(k0 <= kstar & k[t+1] > kstar | k0 > kstar & c[t+1] < cstar) {
        c_min <- c[1]; break;
      }
      
      #  if consumption is too large, then initial consumption level was too small
      if(k0 <= kstar & c[t+1] > cstar | k0 > kstar & k[t+1] < kstar) {
        c_max <- c[1]; break;
      }
    }
  }
  
  # in any case, if you end up here, return c[1] and epsilon
  return(c(c[1], epsilon, i))
}

Simulating the Ramsey model forward

Next, we again provide a function for simulating the economy forward. It works in exactly the same way as in the first part of this chapter. In addition, we have to again specify paths for fiscal policy, i.e. the path of government spending g_t and a path for the capital tax rate tau_k. We then use the equations \[ k_{t+1} = \max\left[\frac{k_t^\alpha - c_t - g_t + (1-\delta)k_t}{1+g}, 10^{-4}\right] \] and \[ c_{t+1} = \left[\beta\cdot \frac{1 + (1-\tau_k)\cdot\left(\alpha k_{t+1}^{\alpha-1} - \delta\right)}{1+g}\right]^\gamma\cdot c_t. \] to simulate the economy forward.

ramsey <- function(T0, T1, c0, k0, g_t, tau_k, g, alpha, delta, gamma, beta) {
  
  # set numerical parameters
  tol <- 1e-6
  
  # determine steady state capital intensity and consumption
  kstar <- (alpha/(((1+g)/beta - 1)/(1-tau_k[length(tau_k)]) + delta))^(1/(1-alpha))
  cstar <- kstar**alpha - (g+delta)*kstar - g_t[length(g_t)]
    
  # start a capital and consumption path
  k <- k0
  c <- 0
  
  # assume economy was in steady state prior to date 0
  k[ind(T0):ind(0)] <- k0
  c[ind(T0):ind(0)] <- k0^alpha - (g+delta)*k0 - g_t[ind(T0):ind(0)]
  
  # then start to simulate new economy path
  c[ind(0)] <- c0
  
  # now simulate the economy forward
  for (t in ind(0):ind(T1-1)) {
    
    # determine next period's capital stock and consumption
    k[t+1] <- max((k[t]**alpha - c[t] - g_t[t] + (1-delta)*k[t])/(1+g), 1e-4)
    c[t+1] <- (beta*(1 + (1-tau_k[t])*(alpha*k[t+1]^(alpha-1) - delta))/(1+g))^gamma*c[t]
    
    #  move to steady state level when you are almost there
    epsilon <- sqrt((c[t+1]/cstar-1)^2 + (k[t+1]/kstar-1)^2)
    if(epsilon < tol) {
      k[(t+1):ind(T1)] = kstar
      c[(t+1):ind(T1)] = cstar
      break
    }
  }
  
  # calculate other macro statistics
  y <- k^alpha
  ir <- (g + delta)*k
  i <- y - c - g_t
  s <- i/y

  # return a data frame with macro path
  res <- data.frame(year=c(T0:T1), k, y, c, g_t, i, ir, s)
  return(res)
}

# indicator management function
ind <- function(t) {
  return(t + 1 + abs(T0))
}

A permanent change in government spending

Lets start with simulating a permanent increase in government spending. To this end, we calculate the capital intensity \(k_{old}\) and consumption level \(c_{old}\) of an economy without fiscal activity. We then assume that government spending amounts to 20 percent of GDP in this economy, i.e. \(g_t = 0.2 k_{old}^\alpha\). We solve for the initial consumption level on the saddle path using function solve_ramsey. Next, we specify the corresponding paths for fiscal policy and simulate the model using function ramsey. As usual, this function returns a data frame with all the important characteristics of the macroeconomy.

# steady state capital intensity without government spending
k_old <- (alpha/((1+g)/beta - 1 + delta))^(1/(1-alpha))
c_old <- k_old^alpha - (g+delta)*k_old

# determine size of government spending (20% of old GDP)
gov_spend <- 0.2*k_old^alpha

# set simulation periods
T0 <- -50
T1 <- 200

# solve transition path
res <- solve_ramsey(k_old, gov_spend, 1, g, alpha, delta, gamma, beta)

# get path of government spending
g_t <- 0
g_t[ind(T0):ind(-1)] = 0
g_t[ind(0):ind(T1)] = gov_spend

# get path of capital tax (not used here)
tau_k <- 0
tau_k[ind(T0):ind(T1)] = 0

# simulate the model for 250 periods
transition <- ramsey(T0, T1, res[1], k_old, g_t, tau_k, g, alpha, delta, gamma, beta)


As discussed in the lecture, a permanent change in government spending does not alter GDP or capital accumulation.

myplot <- ggplot(data = transition) + 
  geom_hline(yintercept=transition$k[ind(T0)], color=myred, linetype="dashed", linewidth=1) + 
  geom_hline(yintercept=transition$k[ind(T1)], color="#00BA38", linetype="dashed", linewidth=1) + 
  geom_line(aes(x=year, y=k), color="darkblue", linewidth=1) +
  coord_cartesian(xlim=c(T0, T1), ylim=c(6, 8)) + 
  scale_x_continuous(breaks=seq(T0, T1, 25), expand=c(0, 0)) +
  labs(x = "Year t",
       y = "Capital Intensity") +
  theme_bw()

# print the plot
print(myplot)


Households just cut their consumption one-to-one and leave investment untouched. As a result, GDP does not move over time. We can see this in the figure below.

myplot <- ggplot(data = transition) + 
  geom_hline(yintercept = c_old, color="#00BA38", linetype="dashed", linewidth=0.5) + 
  geom_ribbon(aes(x=year, ymin=0, ymax=c,    fill= "1c", color="1c") , alpha=0.4) +
  geom_ribbon(aes(x=year, ymin=c, ymax=c+g_t, fill= "3di", color="3di"), alpha=0.4) +
  geom_ribbon(aes(x=year, ymin=c+g_t, ymax=y, fill= "2ir", color="2ir")  , alpha=0.4) +
  geom_line(aes(x=year, y=y), color="darkblue", linewidth=1) +
  coord_cartesian(xlim=c(T0, T1), ylim=c(0, 3)) + 
  scale_x_continuous(breaks=seq(T0, T1, 25), expand=c(0, 0)) +
  labs(x = "Year t",
       y = "GDP and its components per\n effective unit of labor") +
  scale_fill_manual(breaks = c("1c", "2ir", "3di"), name = "", 
                    labels = c("Consumption", "Investment", "Gov. Spending"),
                    values = c(mygreen, myblue, myred)) +
  scale_color_manual(breaks = c("1c", "2ir", "3di"),
                     values = c(mygreen, myblue, myred)) +
  guides(colour = "none") +
  theme_bw() + 
  theme(legend.position="bottom")

# print the plot
print(myplot)

A temporary change in government spending

We now make the same assumptions regarding government spending with the only difference that government spending happens only in one period.

# steady state capital intensity without government spending
k_old <- (alpha/((1+g)/beta - 1 + delta))^(1/(1-alpha))
c_old <- k_old^alpha - (g+delta)*k_old

# determine size of government spending (20% of old GDP)
gov_spend <- 0.2*k_old^alpha

# set simulation periods
T0 <- -50
T1 <- 200

# solve transition path
res <- solve_ramsey(k_old, gov_spend, 2, g, alpha, delta, gamma, beta)

# get path of government spending
g_t <- 0
g_t[ind(T0):ind(T1)] = 0
g_t[ind(0)] = gov_spend

# get path of capital tax (not used here)
tau_k <- 0
tau_k[ind(T0):ind(T1)] = 0

# simulate the model for 250 periods
transition <- ramsey(T0, T1, res[1], k_old, g_t, tau_k, g, alpha, delta, gamma, beta)


A temporary change in government expenditure leads households to smooth the burdens of taxation over time. As a result, they don’t only cut into their consumption but also (and majorly) into investment. This drives down the capital intensity in the short run, and capital only comes back after a while. In the long-run the capital intensity has to stay unchanged.

myplot <- ggplot(data = transition) + 
  geom_hline(yintercept=transition$k[ind(T0)], color=myred, linetype="dashed", linewidth=1) + 
  geom_hline(yintercept=transition$k[ind(T1)], color="#00BA38", linetype="dashed", linewidth=1) + 
  geom_line(aes(x=year, y=k), color="darkblue", linewidth=1) +
  coord_cartesian(xlim=c(T0, T1), ylim=c(6, 8)) + 
  scale_x_continuous(breaks=seq(T0, T1, 25), expand=c(0, 0)) +
  labs(x = "Year t",
       y = "Capital Intensity") +
  theme_bw()

# print the plot
print(myplot)


We can see the cut in investment quite well when we plot the evolution of GDP as well as its components.

myplot <- ggplot(data = transition) + 
  geom_hline(yintercept = c_old, color="#00BA38", linetype="dashed", linewidth=0.5) + 
  geom_ribbon(aes(x=year, ymin=0, ymax=c,    fill= "1c", color="1c") , alpha=0.4) +
  geom_ribbon(aes(x=year, ymin=c, ymax=c+g_t, fill= "3di", color="3di"), alpha=0.4) +
  geom_ribbon(aes(x=year, ymin=c+g_t, ymax=y, fill= "2ir", color="2ir")  , alpha=0.4) +
  geom_line(aes(x=year, y=y), color="darkblue", linewidth=1) +
  coord_cartesian(xlim=c(T0, T1), ylim=c(0, 3)) + 
  scale_x_continuous(breaks=seq(T0, T1, 25), expand=c(0, 0)) +
  labs(x = "Year t",
       y = "GDP and its components per\n effective unit of labor") +
  scale_fill_manual(breaks = c("1c", "2ir", "3di"), name = "", 
                    labels = c("Consumption", "Investment", "Gov. Spending"),
                    values = c(mygreen, myblue, myred)) +
  scale_color_manual(breaks = c("1c", "2ir", "3di"),
                     values = c(mygreen, myblue, myred)) +
  guides(colour = "none") +
  theme_bw() + 
  theme(legend.position="bottom")

# print the plot
print(myplot)


However, since government expenditure only happens in one period, it is worth zooming in on this small episode. We do this on the graph below, where we just adjusted the axis scale in the statement coord_cartesian.

While under permanent government expenditure, households cut their consumption level one-to-one, they now majorly adjust investment. Since the government spending shock is only temporary, this behavior allows households to smooth the consumption burden over time. The cut in consumption in every period is quite small, and since \(\gamma = 0.5\), households value such consumption smoothing. In the long-run, the economy then returns to its original balanced growth path.

myplot <- ggplot(data = transition) + 
  geom_hline(yintercept = c_old, color="#00BA38", linetype="dashed", linewidth=0.5) + 
  geom_ribbon(aes(x=year, ymin=0, ymax=c,    fill= "1c", color="1c") , alpha=0.4) +
  geom_ribbon(aes(x=year, ymin=c, ymax=c+g_t, fill= "3di", color="3di"), alpha=0.4) +
  geom_ribbon(aes(x=year, ymin=c+g_t, ymax=y, fill= "2ir", color="2ir")  , alpha=0.4) +
  geom_line(aes(x=year, y=y), color="darkblue", linewidth=1) +
  coord_cartesian(xlim=c(-10, 50), ylim=c(1.5, 2.25)) + 
  scale_x_continuous(breaks=seq(T0, T1, 25), expand=c(0, 0)) +
  labs(x = "Year t",
       y = "GDP and its components per\n effective unit of labor") +
  scale_fill_manual(breaks = c("1c", "2ir", "3di"), name = "", 
                    labels = c("Consumption", "Investment", "Gov. Spending"),
                    values = c(mygreen, myblue, myred)) +
  scale_color_manual(breaks = c("1c", "2ir", "3di"),
                     values = c(mygreen, myblue, myred)) +
  guides(colour = "none") +
  theme_bw() + 
  theme(legend.position="bottom")

# print the plot
print(myplot)

A capital tax

Our next fiscal policy exercise is to impose a tax on capital income of \(\tau_k = 0.25\). We do this in quite a similar way as our government spending exercises.

# steady state capital intensity without capital tax
k_old <- (alpha/((1+g)/beta - 1 + delta))^(1/(1-alpha))
c_old <- k_old^alpha - (g+delta)*k_old

# determine size of capital tax rate (2.5%)
tax_rate <- 0.25

# set simulation periods
T0 <- -50
T1 <- 200

# solve transition path
res <- solve_ramsey(k_old, tax_rate, 3, g, alpha, delta, gamma, beta)

# get path of government spending (not used)
g_t <- 0
g_t[ind(T0):ind(T1)] = 0

# get path of capital tax
tau_k <- 0
tau_k[ind(T0):ind(-1)] = 0
tau_k[ind(0):ind(T1)] = tax_rate

# simulate the model for 250 periods
transition <- ramsey(T0, T1, res[1], k_old, g_t, tau_k, g, alpha, delta, gamma, beta)


However, this time it is worth thinking about welfare. We use the discounted utility function of households to calculate welfare under two situation:

  1. The case without capital tax, which is just reflected in a constant consumption path at initial levels.

  2. The case of a capital tax of 2.5%.

# calculate welfare number for initial equilibrium
Welfare_0 <- 0
for(t in 0:T1) {
  Welfare_0 <- Welfare_0 + beta^t*(transition$c[ind(T0)]^(1-1/gamma)/(1-1/gamma))
}

# calculate welfare number for raising capital tax
Welfare_1 <- 0
for(t in 0:T1) {
  Welfare_1 <- Welfare_1 + beta^t*(transition$c[ind(t)]^(1-1/gamma)/(1-1/gamma))
}


The resulting path for the capital intensity is quite clear. The capital tax – reimbursed directly back to households – acts like a change in the discount factor. As the long-run capital intensity needs to fall, the economy goes on a transition path to this new balanced growth path.

myplot <- ggplot(data = transition) + 
  geom_hline(yintercept=transition$k[ind(T0)], color=myred, linetype="dashed", linewidth=1) + 
  geom_hline(yintercept=transition$k[ind(T1)], color="#00BA38", linetype="dashed", linewidth=1) + 
  geom_line(aes(x=year, y=k), color="darkblue", linewidth=1) +
  coord_cartesian(xlim=c(T0, T1), ylim=c(4, 8)) + 
  scale_x_continuous(breaks=seq(T0, T1, 25), expand=c(0, 0)) +
  labs(x = "Year t",
       y = "Capital Intensity") +
  theme_bw()

# print the plot
print(myplot)


On the GDP side, the fall in capital intensity is accompanied by a short-run increase in consumption, which is financed by a cut in investment. Since the Ramsey economy is dynamically efficient, however, the fall in capital intensity leads to a drop in long-run consumption.

myplot <- ggplot(data = transition) + 
  geom_hline(yintercept = c_old, color="#00BA38", linetype="dashed", linewidth=0.5) + 
  geom_ribbon(aes(x=year, ymin=0, ymax=c,    fill= "1c", color="1c") , alpha=0.4) +
  geom_ribbon(aes(x=year, ymin=c, ymax=y, fill= "2ir", color="2ir")  , alpha=0.4) +
  geom_line(aes(x=year, y=y), color="darkblue", linewidth=1) +
  coord_cartesian(xlim=c(T0, T1), ylim=c(0, 3)) + 
  scale_x_continuous(breaks=seq(T0, T1, 25), expand=c(0, 0)) +
  labs(x = "Year t",
       y = "GDP and its components per\n effective unit of labor") +
  scale_fill_manual(breaks = c("1c", "2ir"), name = "", 
                    labels = c("Consumption", "Investment"),
                    values = c(mygreen, myblue)) +
  scale_color_manual(breaks = c("1c", "2ir"),
                     values = c(mygreen, myblue)) +
  guides(colour = "none") +
  theme_bw() + 
  theme(legend.position="bottom")

# print the plot
print(myplot)

A capital subsidy

Now lets do the same for a capital subsidy, which is nothing else than a capital tax. Me might think this is a good idea, since the economy is not on the Golden rule path.

# steady state capital intensity without capital tax
k_old <- (alpha/((1+g)/beta - 1 + delta))^(1/(1-alpha))
c_old <- k_old^alpha - (g+delta)*k_old

# determine size of capital tax rate (2.5%)
tax_rate <- -0.25

# set simulation periods
T0 <- -50
T1 <- 200

# solve transition path
res <- solve_ramsey(k_old, tax_rate, 3, g, alpha, delta, gamma, beta)

# get path of government spending (not used)
g_t <- 0
g_t[ind(T0):ind(T1)] = 0

# get path of capital tax
tau_k <- 0
tau_k[ind(T0):ind(-1)] = 0
tau_k[ind(0):ind(T1)] = tax_rate

# simulate the model for 250 periods
transition <- ramsey(T0, T1, res[1], k_old, g_t, tau_k, g, alpha, delta, gamma, beta)

# calculate welfare number for raising capital subsidy
Welfare_2 <- 0
for(t in 0:T1) {
  Welfare_2 <- Welfare_2 + beta^t*transition$c[ind(t)]^(1-1/gamma)/(1-1/gamma)
}


As the capital tax is like an increase in the discount factor, the capital intensity slowly increases.

myplot <- ggplot(data = transition) + 
  geom_hline(yintercept=transition$k[ind(T0)], color=myred, linetype="dashed", linewidth=1) + 
  geom_hline(yintercept=transition$k[ind(T1)], color="#00BA38", linetype="dashed", linewidth=1) + 
  geom_line(aes(x=year, y=k), color="darkblue", linewidth=1) +
  coord_cartesian(xlim=c(T0, T1), ylim=c(6, 12)) + 
  scale_x_continuous(breaks=seq(T0, T1, 25), expand=c(0, 0)) +
  labs(x = "Year t",
       y = "Capital Intensity") +
  theme_bw()

# print the plot
print(myplot)


The rise in capital needs to be accompanied by an increase in investment and, hence, by a drop in short-run consumption. Since the economy is dynamically efficient, the increase in long-run capital intensity causes a rise in long-run consumption.

myplot <- ggplot(data = transition) + 
  geom_hline(yintercept = c_old, color="#00BA38", linetype="dashed", linewidth=0.5) + 
  geom_ribbon(aes(x=year, ymin=0, ymax=c,    fill= "1c", color="1c") , alpha=0.4) +
  geom_ribbon(aes(x=year, ymin=c, ymax=y, fill= "2ir", color="2ir")  , alpha=0.4) +
  geom_line(aes(x=year, y=y), color="darkblue", linewidth=1) +
  coord_cartesian(xlim=c(T0, T1), ylim=c(0, 3)) + 
  scale_x_continuous(breaks=seq(T0, T1, 25), expand=c(0, 0)) +
  labs(x = "Year t",
       y = "GDP and its components per\n effective unit of labor") +
  scale_fill_manual(breaks = c("1c", "2ir"), name = "", 
                    labels = c("Consumption", "Investment"),
                    values = c(mygreen, myblue)) +
  scale_color_manual(breaks = c("1c", "2ir"),
                     values = c(mygreen, myblue)) +
  guides(colour = "none") +
  theme_bw() + 
  theme(legend.position="bottom")

# print the plot
print(myplot)

A Welfare comparison

Is a tax or subsidy on capital income a good idea? To give an answer to this question based on the household optimization problem, we can compare welfare and consumption equivalent variation in the three scenarios. Note that the scenario without capital taxation serves as a benchmark. It is quite clear from these numbers that we should neither have a capital tax nor a subsidy.

The reason for this is easy to understand: households already optimize their consumption path given their level of discounting. A capital tax or subsidy changes the consumption path of households by altering the intertemporal discount factor for resources. But it does not change the discount factor of households. Hence, under a capital tax/subsidy, households have to enter a consumption path that is suboptimal given their subjective level of discounting. And this causes welfare losses in both directions, even if the long-run consumption level increases under capital subsidies.

sprintf('Without capital taxes    : %12.6f %12.6f\n', Welfare_0, 0)
sprintf('With 25p capital tax     : %12.6f %12.6f\n', Welfare_1, ((Welfare_1/Welfare_0)^{1/(1-1/gamma)}-1)*100)
sprintf('With 25p capital subsidy : %12.6f %12.6f\n', Welfare_2, ((Welfare_2/Welfare_0)^{1/(1-1/gamma)}-1)*100)
## [1] "Without capital taxes    :   -16.565306     0.000000\n"
## [1] "With 25p capital tax     :   -16.690665    -0.751075\n"
## [1] "With 25p capital subsidy :   -16.646768    -0.489357\n"