ECON : Coding Assignment # Aaron Betz abc University Write your own IRF code Suppose you have the following solution to a model from Dolo Problem is just a Python exercise, you will not actually be using Dolo You will generate impulse response functions with these formulas. ztztrho rho bar zlont ktktdelta ztktdelta Capital and Z impulses Where rho bar z and delta You can solve forward to time t from time tsteady state when zbar z and kbar k given some initial shock lon To continue to solve forward assume lon and that every following lont is zero. Write a Python function to generate an impulse of length n given an initial shock, lon Show your code and graph impulses for both capital and z of length with an initial shock lon Labor and output impulse Now that you have a period series of all the necessary state variables, kt and zt solve for nt and then yt given the following formulas from Dolo. ntztkt ytztntkt Keep in mind you will need to solve for labor, nt before you solve for output, yt Once you have solved all periods graph both labor and output over time use separate graphs
Sure! Let's break down the task and walk through each part step-by-step. We will write Python code to generate impulse response functions for the given model.
Given formulas:
We'll start with a function to generate the impulse response for and .
import numpy as np
import matplotlib.pyplot as plt
def generate_impulses(n, lon_0):
# Initialize parameters
rho = 0.9
bar_z = 1
delta = 0.025
# Initial conditions
z_t = [1]
k_t = [9.354]
lon = [lon_0] + [0] * (n - 1)
# Generate the series for z_t and k_t
for t in range(1, n):
z_t_next = z_t[-1] * rho + (1 - rho) * bar_z + lon[t]
z_t.append(z_t_next)
k_t_next = k_t[-1] * (1 - delta) + 2.16 * (z_t[-2] - 1) + 0.017 * (k_t[-1] - 9.354) + delta * 9.354
k_t.append(k_t_next)
return z_t, k_t
# Generate 40 periods with an initial shock lon_0 = 0.01
n = 40
lon_0 = 0.01
z_t, k_t = generate_impulses(n, lon_0)
# Plot the impulses
plt.figure(figsize=(12, 6))
plt.subplot(1, 2, 1)
plt.plot(z_t, label="z_t")
plt.title("Impulse Response of z_t")
plt.xlabel("Periods")
plt.ylabel("z_t")
plt.legend()
plt.subplot(1, 2, 2)
plt.plot(k_t, label="k_t")
plt.title("Impulse Response of k_t")
plt.xlabel("Periods")
plt.ylabel("k_t")
plt.legend()
plt.tight_layout()
plt.show()
Given formulas:
We'll calculate these and plot them.
def calculate_labor_and_output(z_t, k_t):
n_t = []
y_t = []
for t in range(1, len(z_t)):
n_t_next = 0.33 + 0.809 * (z_t[t-1] - 1) + 0.025 * (k_t[t-1] - 9.354)
n_t.append(n_t_next)
y_t_next = z_t[t] * (n_t_next**0.67) * (k_t[t-1]**0.33)
y_t.append(y_t_next)
return n_t, y_t
# Calculate labor and output
n_t, y_t = calculate_labor_and_output(z_t, k_t)
# Plot labor and output
plt.figure(figsize=(12, 6))
plt.subplot(1, 2, 1)
plt.plot(n_t, label="n_t")
plt.title("Labor over Time")
plt.xlabel("Periods")
plt.ylabel("n_t")
plt.legend()
plt.subplot(1, 2, 2)
plt.plot(y_t, label="y_t")
plt.title("Output over Time")
plt.xlabel("Periods")
plt.ylabel("y_t")
plt.legend()
plt.tight_layout()
plt.show()
This process allows us to visualize the impact of an initial shock over time.
Answered By