# Analyzing the Solow model 

## Introduction

In this project we will examine the standard Solow model with technological growth (A). We solve for steady state and use interactive figures to examine how different parameter values affects the steady state capital. Later, we extend the model by adding the exogenous variable, land, to our model. Here we examine how parameter values affects the steady steate capital-output ratio. 

Imports and set magics:


```python
from __future__ import print_function
import numpy as np
from scipy import optimize
import sympy as sm
import matplotlib.pyplot as plt
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets

# autoreload modules when code is run
%load_ext autoreload
%autoreload 2
```

# The standard Solow model

We consider the standard Solow model with a Cobb-Douglas production function: 
$$ Y_t=K_t^{\alpha}(A_tL_t)^{1-\alpha}, 0<\alpha<1 $$

* $Y_t$ is GDP
* $K_t$ is capital 
* $L_t$ is labor 
 * growing with a constant rate of $n$: $L_{t+1}=(1+n)L_t, n\geq0$
* $A_t$ is technology 
 * growing with a constant rate of $g$: $A_{t+1}=(1+g)A_t, g\geq0$ 





Saving is a constant fraction of GDP

$$ 
S_t = sY_t, 0<s<1
$$

such that capital accumulation is savings and undepreciated capital: 

$$
K_{t+1}=S_t+(1-\delta)K_t, 0<\delta<1
$$


We define the technology adjusted capital-labour ratio as 

$$\tilde{k_{t+1}}=\frac{K_{t+1}}{L_{t+1}A_{t+1}} $$

The transition equation becomes:
$$
\tilde{k_{t+1}}=\frac{1}{(1+n)(1+g)}*(s\tilde{k_t^\alpha}+(1-\delta)\tilde{k_t})
$$

We know that steady state requires $k_{t+1}=k_t$

## Solving steady state analytical

We will now solve for the techonolgy adjusted capital intensity steady state using sympy

We define our symbols: 


```python
k = sm.symbols('\tilde{k_t}')
k1 = sm.symbols('\tilde{k_{t+1}}')
kstar = sm.symbols("k^*")
g = sm.symbols('g')
n = sm.symbols('n')
alpha = sm.symbols('alpha')
delta = sm.symbols('delta')
s = sm.symbols('s')
```

To find steady state we set
$\tilde{k_{t+1}}=\tilde{k_t}$
in the **Solow** equation


```python
SS_capital = sm.solve((s*kstar**(alpha)-(n+g+delta+n*g)*kstar)/((1+n)*(1+g)),kstar)
sm.Eq(kstar, SS_capital[0])
```




$\displaystyle k^{*} = \left(\frac{\delta + g n + g + n}{s}\right)^{\frac{1}{\alpha - 1}}$



We will now examine the **Solow** diagram and illustrate what happens, when we change the parameters. 

## Graphical analysis 

First we plot the **Solow** diagram with fixed parameter values


```python
# a. create function for generating solow diagram
def solow(c,alpha,delta,s,n,g):
    '''Function for creating the solow diagram

    input:
    c = capital
    alpha = share of capital
    delta = deprication rate
    s = savings rate
    n = population growth rate
    g = technologic growth rate

    output:
    Depriciation of capital 
    Kapital growth
    '''

    #i. create empty lists
    Deprication = []
    Capital = []

    # ii. create loop which adds values for deprication of capital
    for c in range(1,c):
        Deprication.append((n+g+delta+n*g)*c)
        
    # iii. create loop which adds values for growth of capital
    for c in range(1,c):
        Capital.append(s*(c**alpha))

    # iv. plot in figure
    plt.style.use('seaborn') 
    plt.figure(figsize=(5,5))
    plt.plot(Deprication, label = '$(n+g+\delta+n+ng)k_t$', color = 'g')
    plt.plot(Capital, label = '$sk_t^\\alpha$', color = 'r')
    plt.grid(True)
    plt.ylim(0,5)
    plt.xlim(0,c)
    plt.xlabel('$k_t$')
    plt.legend()
    plt.legend()
    return plt.show()

# # b. call function with fixed parameters
solow(200,1/3,0.05,0.101,0.025,0.02)
```

By using the interactive figure below **you** can examine the steady state capital for different values of depreciation, saving, population growth and techology growth. 


```python
widgets.interact(solow,
    c = widgets.fixed(200),
    alpha = widgets.fixed(1/3), 
    delta = widgets.FloatSlider(description = 'd' , min = 0.01, max = 0.1, step=0.01, value=0.05), 
    s = widgets.FloatSlider(description = 's', min=0.1, max=0.9, step = 0.1, value= 0.1),  
    n = widgets.FloatSlider(description = 'n', min = 0.01, max = 0.1, step = 0.01, value = 0.025),
    g = widgets.FloatSlider(description = 'g', min = 0.01, max = 0.1, step = 0.01, value = 0.02))
```


    interactive(children=(FloatSlider(value=0.05, description='d', max=0.1, min=0.01, step=0.01), FloatSlider(valu…





    <function __main__.solow(c, alpha, delta, s, n, g)>



The figure shows, that an increase in the savings rate, s, results in an increase in the SS level. With a higher savings rate it is possible to accumulate more capital, since capital next period is equal to the amount of capital last period and the savings from the present period. 

From an increase in N, we find a lower SS level. This is due to and increase in the population wears the capital, and thus lower the SS level.

# Model extension

We consider the Solow model with land. 

We assume the production function is Cobb-Douglas: 
$$Y_t=K_t^{\alpha}(A_tL_t)^{\beta}X^{\kappa}, \alpha>0, \beta>0, \kappa>0, \alpha+\beta+\kappa=1$$
where: 
* $Y_t$ is GDP
* $K_t$ is capital 
* $L_t$ is labor 
 * growing with a constant rate of $n$: $L_{t+1}=(1+n)L_t, n\geq0$
* $A_t$ is technology 
 * growing with a constant rate of $g$: $A_{t+1}=(1+g)A_t, g\geq0$
* $X$ is land
 * constant

Saving is a constant fraction of GDP:

$$ 
S_t = sY_t,\,s\in(0,1)
$$

such that capital accumulation is savings and undepreciated capital: 

$$
K_{t+1}=S_t+(1-\delta)K_t, 0<\delta<1
$$

We assume that economy converges towards a steady state in which the capital-output ratio is constant: 
$$
z_t=\frac{K_t}{Y_t}=\frac{k_t}{y_t}
$$

The trasition equation is:
$$
z_{t+1}=\frac{1}{((1+g)(1+n))^\beta} [s+z_t(1-\delta)]^{1-\alpha}z_t^{\alpha}
$$

## Steady state
We solve the steady state capital-output ratio **analytical** and **numerical**. 


We define our symbols: 


```python
alpha = sm.symbols('alpha')
delta = sm.symbols('delta')
beta = sm.symbols('beta')
kappa = sm.symbols('kappa')
s = sm.symbols('s')
g = sm.symbols('g')
n = sm.symbols('n')
z = sm.symbols('z')
```

### Analytical solution
The steady state solution is: 
$$
z^*=\frac{s}{[(1+n)(1+g)]^{\frac{\beta}{\beta+\kappa}}-(1-\delta)}
$$

We turn the solution into a sympy equation: 


```python
ss = sm.Eq(z, s/((((1+n)*(1+g))**(beta/(beta+kappa)))-(1-delta))) #Turns SS into a sympy equation
ss_capital_ratio = sm.solve(ss,z)[0] #Solve it by sympy
ss_func = sm.lambdify((s,g,n,beta,kappa,delta),ss_capital_ratio) # Turns it into a Python function
```

We solve for steady state using the analytical expression and inserting plausible parameter values: 


```python
print(f'The steady state for capital-output ratio is: {ss_func(0.2,0.02,0.01,0.6,0.2,0.05):.3f}')
```

    The steady state for capital-output ratio is: 2.756


### Numerical analysis
We can also solve with numerical optimization: 

If we rewrite the transition equation it clearly becomes a root-finding problem: 

$$
0=\frac{1}{((1+g)(1+n))^\beta} [s+z^*(1-\delta)]^{1-\alpha}z^{*\alpha}-z^*
$$

We state the same parameter values: 


```python
alpha = 0.2
beta = 0.6
kappa = 0.2
delta = 0.05
g = 0.02
n = 0.01
s = 0.2
```

To solve we need an objective function: 


```python
obj_zss = lambda z: z - ((s + z*(1-delta))**(1-alpha)*z**alpha)/(((1+n)*(1+g))**beta)
interval = [0.1,100]
```

We choose to apply the Brentq method as it is seen as one of most safe rootfinding methods in the scipy package. The method simply finds a zero of the function given an interval $[a,b]$. Using Brentq we find the optimal level of capital-output ratio for our parameters:


```python
res  = optimize.root_scalar(obj_zss,bracket=interval,method='brentq')
print(res)
```

    converged: True
               flag: 'converged'
     function_calls: 7
         iterations: 6
               root: 2.7561286078149587


We can see it took 6 iterations and 7 function calls, which is relatively quick. 

We call the two solutions and compare: 


```python
print(f'analytical solution is: {ss_func(s,g,n,beta,kappa,delta):.3f}')
print(f'numerical solution is: {res.root:.3f}')
```

    analytical solution is: 2.756
    numerical solution is: 2.756


As we can see the solutions are identical (3 decimals).

## Graphical analysis

We want to analyze capital-ratio output over time so we create the following function:


```python
# a. generate function for transition equation for the capital-output ratio
def trans_eq(Z0,alpha,beta,delta,s,g,n,t):

    '''Function creates a graph based on the transition equation 
    
    input:
    Z0 = capital-ratio output in first period
    alpha = share of capital
    beta = share of effective labor
    delta = deprication rate
    s = savings rate
    g = technology growth rate
    n = population growth rate
    t = periods
    
    output:
    Z_t1 = capital-ratio output in next period

    '''

     # i. create two empty list 
    Z_t = [Z0]
    Z_t1 = []

    i = 1

    # ii. create a loop which generates two lists for both z_t1 and z_t
    while i <= t:
        Z_t.append(((s+Z_t[-1]*(1-delta))**(1-alpha)*Z_t[-1]**alpha)/(((1+n)*(1+g))**beta)) # Adds to list for z_t
        Z_t1.append(((s+Z_t[-1]*(1-delta))**(1-alpha)*Z_t[-1]**alpha)/(((1+n)*(1+g))**beta)) # Adds to list for z_t1

        i += 1

    # iii. generate plot
    plt.style.use('seaborn')
    fig = plt.figure(figsize=(5,5))
    ax = fig.add_subplot(1,1,1)
    ax.plot(Z_t1)
    ax.set_title('Growth in capital-output ratio over time')
    ax.set_xlabel('time')
    ax.set_ylabel('$z_{t+1}$')
    return plt.show()
```


```python
# a. call the function for 200 periods
trans_eq(1,alpha,beta,delta,s,g,n,200)
```

We want to include an interactive element to our graph so we create the following:


```python
widgets.interact(trans_eq,
    Z0 = widgets.fixed(1),
    alpha = widgets.fixed(0.2), 
    beta = widgets.fixed(0.6), 
    delta = widgets.FloatSlider(description = 'd' , min = 0.01, max = 0.1, step=0.01, value=0.05), 
    s = widgets.FloatSlider(description = 's', min=0.1, max=0.9, step = 0.1, value= 0.2), 
    g = widgets.FloatSlider(description = 'g', min=0.01, max=0.1, step= 0.01, value=0.02), 
    n = widgets.FloatSlider(description = 'n', min = 0.01, max = 0.1, step = 0.01, value = 0.01), 
    t = widgets.fixed(200))
```


    interactive(children=(FloatSlider(value=0.05, description='d', max=0.1, min=0.01, step=0.01), FloatSlider(valu…





    <function __main__.trans_eq(Z0, alpha, beta, delta, s, g, n, t)>



An increase in s is displacing the SS upwards, since the capital/output ratio is increasing. 
A decrease in n results in less thinning out of capital, thus capital/worker is increasing and thereby the capital/output relationship, which also increases the SS level.

These effects are plottet in the figures below.


```python
# a. creates a list for savings rate and a list for population growth
s_list = np.linspace(0.1,1,num=10, endpoint=True)
results_s = []

n_list = np.linspace(0.01,0.05,num=10, endpoint=True)
results_n = []

# b. create two loops which makes a steady state for each value of savings rate and population growth
for s in s_list:
    res  = optimize.root_scalar(obj_zss,bracket=interval,method='brentq')
    results_s.append(res.root)

for n in n_list:
    res  = optimize.root_scalar(obj_zss,bracket=interval,method='brentq')
    results_n.append(res.root)

# c. create figure for both results
plt.style.use('seaborn')
fig = plt.figure(figsize=(10,4))

# d. figure based on savings
ax_s = fig.add_subplot(1,2,1)
ax_s.scatter(s_list,results_s)
ax_s.set_title('Steady state based on rate of savings')
ax_s.set_xlabel('s')
ax_s.set_ylabel('$z^*$')
ax_s.grid(True)

# e. figure based on population growth
ax_n = fig.add_subplot(1,2,2)
ax_n.scatter(n_list,results_n)
ax_n.set_title('Steady state based on population growth')
ax_n.set_xlabel('n')
ax_n.set_ylabel('$z^*$')
ax_n.grid(True)
```

The figures clearly shows how an increase in the saving rate results in a larger capital-output ratio, where an incresase in the population growth results in a lower capital-output ratio, all other things held equal. 

# Conclusion

The project examined the standard Solow model with technological growth and the extended Solow model with land. Here we saw how different parameter values affected the steady state level of capital (model 1) and capital-output ratio (model 2). Futhermore, we showed how the numerical solution and the analytical solution were identical, which means that our numerical optimization worked as it should. 


```python

```

7dc104229de0e78badfea36d2900945771dac73a
ipynb
Jupyter Notebook
modelproject/modelproject.ipynb
NumEconCopenhagen/projects-2020-jop
e779383ad53a47f2202e4540821f274d3026df73
MIT
modelproject/modelproject.ipynb
NumEconCopenhagen/projects-2020-jop
e779383ad53a47f2202e4540821f274d3026df73
MIT
2020-04-08T21:08:56.000Z
2020-05-11T21:53:47.000Z
modelproject/modelproject.ipynb
NumEconCopenhagen/projects-2020-jop
e779383ad53a47f2202e4540821f274d3026df73
MIT
Qwen/Qwen-72B
1. YES
2. YES