In [1]:
# Make graphs appear within notebook
%matplotlib inline

# Import numerical computations library
import numpy as np

# Import plotting library
import matplotlib.pyplot as plt

# Import dataframe management library
import pandas as pd
In [2]:
# Restore old behavior of rounding default axis ranges
from matplotlib import rcParams

rcParams['axes.autolimit_mode'] = 'round_numbers'
rcParams['axes.xmargin'] = 0
rcParams['axes.ymargin'] = 0
In [3]:
def k_star(s=0.2, δ=0.05, n=0.01, g=0.02, α=1/3):
    return (s/(δ+n+g+n*g))**(1/(1-α))

def f(k, α=1/3):
    return k**α
In [4]:
def c_star(s=0.2, δ=0.05, n=0.01, g=0.02, α=1/3):
    return (1-s)*f(k_star(s, δ, n, g, α), α)

def c_k(k, s=0.2, α=1/3):
    return (1-s)*f(k, α)
In [5]:
δ=0.05
n=0.01
g=0.02
α=1/3

ss = np.linspace(0, 1, 1000)

plt.plot(100*ss, c_star(ss, δ, n, g, α))
plt.vlines(100*α, 0, c_star(α, δ, n, g, α), lw=1, linestyle='--')

plt.title('Steady state consumption as function of saving rate')
plt.ylabel('Steady state consumption')
plt.xlabel('Saving rate (%)')

plt.show()
In [6]:
def k_next(k, s=0.2, δ=0.05, n=0.01, g=0.02, α=1/3):
    return (s*f(k, α)+(1-δ)*k)/((1+n)*(1+g))
In [7]:
T = 100
k_t = np.zeros(T)
c_t = np.zeros(T)

print('Initial saving rate below golden rule saving rate')

s_old = 0.3
s_GR  = α

k_t[:10] = k_star(s=s_old)
c_t[:10] = c_k(k_t[:10], s=s_old)
for t in range(10, T):
    k_t[t] = k_next(k_t[t-1], s=s_GR)
    c_t[t] = c_k(k_t[t], s=s_GR)

plt.plot(k_t)
plt.hlines(k_star(s=s_GR), 0, T, lw=1, linestyle='--')
plt.title('Capital after an increase in saving rate')
plt.show()

plt.plot(c_t)
plt.hlines(c_star(s=s_GR), 0, T, lw=1, linestyle='--')
plt.title('Consumption after an increase in saving rate')
plt.show()
Initial saving rate below golden rule saving rate
In [8]:
T = 100
k_t = np.zeros(T)
c_t = np.zeros(T)

print('Initial saving rate above golden rule saving rate')

s_old = 0.35
s_GR  = α

k_t[:10] = k_star(s=s_old)
c_t[:10] = c_k(k_t[:10], s=s_old)
for t in range(10, T):
    k_t[t] = k_next(k_t[t-1], s=s_GR)
    c_t[t] = c_k(k_t[t], s=s_GR)

plt.plot(k_t)
plt.hlines(k_star(s=s_GR), 0, T, lw=1, linestyle='--')
plt.title('Capital after a decrease in saving rate')
plt.show()

plt.plot(c_t)
plt.hlines(c_star(s=s_GR), 0, T, lw=1, linestyle='--')
plt.title('Consumption after a decrease in saving rate')
plt.show()
Initial saving rate above golden rule saving rate
In [9]:
# Read dataset
pwt = pd.read_stata('PWT/pwt90.dta')

# Modify the dataset so that it is easier to work with

# Store country names and codes for later use
countries = pwt['country']
countries = countries.drop_duplicates()

countrycodes = pwt['countrycode']
countrycodes = countrycodes.drop_duplicates()

# Set MultiIndex
pwt.set_index(['countrycode', 'year'], inplace=True)
In [10]:
(100*pwt.loc['TWN']['csh_i']).plot(lw=2, label='Taiwan')
(100*pwt.loc['KOR']['csh_i']).plot(lw=2, label='South Korea')
(100*pwt.loc['SGP']['csh_i']).plot(lw=2, label='Singapore')
(100*pwt.loc['HKG']['csh_i']).plot(lw=2, label='Hong Kong')

plt.xlim(1950, 2014)
plt.ylim(0, 70)

plt.title('Investment rates in "growth miracle" countries')
plt.xlabel('Year')
plt.ylabel('Investment share of GDP (%)')

plt.legend(loc='lower right', ncol=2, frameon=False)

plt.show()