<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Class 7
Step1:  The variable y1 in the preceding example stores the computed value for $y_1$. We can continue to iterate on Equation (4) to compute $y_2$, $y_3$, and so on. For example
Step2:  We can do this as many times as necessary to reach the desired value of $t$. Note that iteration is necesary. Even though $y_t$ is apparently a function of $t$, we could not, for example, compute $y_{20}$ directly. Rather we'd have to compute $y_1, y_2, y_3, \ldots, y_{19}$ first. The linear first-order difference equation is an example of a recursive model and iteration is necessary for computing recursive models in general.
Of course, there is a better way. Let's define a function called diff1_example()that takes as arguments $\rho$, an array of values for $w$, and $y_0$.
Step3:  Exercise
Step4:  Exercise
<ASSISTANT_TASK:>
Python Code:
# Initialize parameter values
y0 = 0
rho = 0.5
w1 = 1
# Compute the period 1 value of y
y1 = rho*y0 + w1
# Print the result
print('y1 =',y1)
Explanation: Class 7: Deterministic Time Series Models
Time series models are at the foundatation of dynamic macroeconomic theory. A time series model is an equation or system of equations that describes how the variables in the model change with time. Here, we examine some theory about deterministic, i.e., non-random, time series models and we explore methods for simulating them. Leter, we'll examine the properties of stochastic time series models by introducing random variables to the discrete time models covered below.
Discrete Versus Continuous Time
To begin, suppose that we are interested in a variable $y$ that takes on the value $y_t$ at date $t$. The date index $t$ is a real number. We'll say that $y_t$ is a discrete time variable if $t$ takes on values from a countable sequence; e.g. $t = 1, 2, 3 \ldots$ and so on. Otherwise, if $t$ takes on values from an uncountable sequence; e.g. $t\in[0,\infty)$, then we'll say that $y_t$ is a continuous time variable. Discrete and continuous time models both have important places in macroeconomic theory, but we're going to focus on understanding discrete time models.
First-Order Difference Equations
Now, suppose that the variable $y_t$ is determined by a linear function of $y_{t-1}$ and some other exogenously given variable $w_t$
\begin{align}
    y_{t} & =  (1- \rho) \mu + \rho y_{t-1} + w_t,  \tag{1}\
\end{align}
where $\rho$ and $\mu$ are constants. Equation (1) is an example of a linear first-order difference equation. As a difference equation, it specifies how $y_t$ is related to past values of $y$. The equation is a first-order difference equation because it specifies that $y_t$ depends only on $y_{t-1}$ and not $y_{t-2}$ or $y_{t-3}$. 
Example: Compounding Interest
Suppose that you have an initial balance of $b_0$ dollars in a savings account that pays an interest rate $i$ per compounding period. Then, after the first compounding, your account will have $b_1 = (1+i)b_0$ dollars in it. Assuming that you never withdraw funds from the account, then your account balance in any subsequent period $t$ is given by the following difference equation:
\begin{align}
b_{t} & =  \left(1+i\right) b_{t-1}. \tag{2}
\end{align}
Equation (2) is linear first-order difference equation in the same form as Equation (1). You can see this by setting $y_t = b_t$, $\rho=1+i$, $\mu=0$, and $w_t=0$ in Equation (1).
Example: Capital Accumulation
Let $K_t$ denote the amont of physical capital in a country at date $t$, let $\delta$ denote the rate at which the capital stock depreciates each period, and let $I_t$ denote the country's investment in new capital in date $t$. Then the law of motion for the stock of physical capital is:
\begin{align}
K_{t+1} & =  I_t + (1-\delta)K_t. \tag{3}
\end{align}
This standard expression for the law of motion for the capital stock is a linear first-order difference equation. To reconcile Equation (3) with Equation (1), set $y_t = K_{t+1}$, $\rho=1-\delta$, $\mu=0$, and $w_t=I_t$. 
Note: There is a potentially confusing way in which we identified the $t+1$-dated variable $K_{t+1}$ with the $t$-dated variable $y_t$ in this example. We can do this because the value of $K_{t+1}$ truly is determined at date $t$ even though the capital isn't used for production until the next period.
Computation
From Equation (1), it's easy to compute the value of $y_t$ as long as you know the values of the constants $\rho$ and $\mu$ and the variables $y_{t-1}$ and $w_t$. To begin, let's suppose that the values of the constants are $\mu=0$, $\rho=0.5$. Then Equation (1) in our example looks like this:
\begin{align}
y_{t} & =  0.5 y_{t-1} + w_t. \tag{4}\
\end{align}
Now, suppose that the initial value of $y$ is $y_0=0$ and that $w$ is equal to 1 in the first period and equal to zero in subsequent periods. That is: $w_1=1$ and $w_2=w_3=\cdots =0$. Now, with what we have, we can compute $y_1$. Here's how:
End of explanation
# Compute the period 2 value of y
w2=0
y2 = rho*y1 + w2
# Print the result
print('y2 =',y2)
Explanation: The variable y1 in the preceding example stores the computed value for $y_1$. We can continue to iterate on Equation (4) to compute $y_2$, $y_3$, and so on. For example:
End of explanation
# Compute 
# Initialize the variables T and w
T = 10
w = np.zeros(T)
w[0]=1
# Define a function that returns an arrary of y-values given rho, y0, and an array of w values.
def diff1_example(rho,w,y0):
    T = len(w)
    y = np.zeros(T+1)
    y[0] = y0
    for t in range(T):
        y[t+1]=rho*y[t]+w[t]
    return y
fig = plt.figure()
y = diff1_example(0.5,w,0)
plt.plot(y,'-',lw=5,alpha = 0.75)
ax1.set_title('$\\rho=0.5$')
plt.ylabel('y')
plt.xlabel('t')
plt.grid()
Explanation: We can do this as many times as necessary to reach the desired value of $t$. Note that iteration is necesary. Even though $y_t$ is apparently a function of $t$, we could not, for example, compute $y_{20}$ directly. Rather we'd have to compute $y_1, y_2, y_3, \ldots, y_{19}$ first. The linear first-order difference equation is an example of a recursive model and iteration is necessary for computing recursive models in general.
Of course, there is a better way. Let's define a function called diff1_example()that takes as arguments $\rho$, an array of values for $w$, and $y_0$.
End of explanation
fig = plt.figure(figsize=(12,8))
ax1 = fig.add_subplot(2,2,1)
y = diff1_example(0.5,w,0)
ax1.plot(y,'-',lw=5,alpha = 0.75)
ax1.set_title('$\\rho=0.5$')
ax1.set_ylabel('y')
ax1.set_xlabel('t')
ax1.grid()
ax2 = fig.add_subplot(2,2,2)
y = diff1_example(-0.5,w,0)
ax2.plot(y,'-',lw=5,alpha = 0.75)
ax2.set_title('$\\rho=-0.5$')
ax2.set_ylabel('y')
ax2.set_xlabel('t')
ax2.grid()
ax3 = fig.add_subplot(2,2,3)
y = diff1_example(1,w,0)
ax3.plot(y,'-',lw=5,alpha = 0.75)
ax3.set_title('$\\rho=1$')
ax3.set_ylabel('y')
ax3.set_xlabel('t')
ax3.grid()
ax4 = fig.add_subplot(2,2,4)
y = diff1_example(1.25,w,0)
ax4.plot(y,'-',lw=5,alpha = 0.75)
ax4.set_title('$\\rho=1.25$')
ax4.set_ylabel('y')
ax4.set_xlabel('t')
ax4.grid()
plt.tight_layout()
Explanation: Exercise:
Use the function diff1_example() to make a $2\times2$ grid of plots just like the previous exercise but with with $\rho = 0.5$, $-0.5$, $1$, and $1.25$. For each, set $T = 10$, $y_0 = 1$, $w_0 = 1$, and $w_1 = w_2 = \cdots 0$.
End of explanation
# Initialize the variables T and w
T = 25
w = np.zeros(T)
w[0]=1
y1 = diff1_example(0.25,w,0)
y2 = diff1_example(0.75,w,0)
y3 = diff1_example(0.5,w,0)
y4 = diff1_example(0.95,w,0)
fig = plt.figure()
plt.plot(y1,'-',lw=5,alpha = 0.75,label='$\\rho=0.25$')
plt.plot(y2,'-',lw=5,alpha = 0.75,label='$\\rho=0.50$')
plt.plot(y3,'-',lw=5,alpha = 0.75,label='$\\rho=0.75$')
plt.plot(y4,'-',lw=5,alpha = 0.75,label='$\\rho=0.95$')
ax1.set_title('$\\rho=0.5$')
plt.ylabel('y')
plt.xlabel('t')
plt.legend(loc='upper right')
plt.grid()
Explanation: Exercise:
Use the function diff1_example() to make a single plot with 4 lines reflecting $\rho = 0.25$, $0.5$, $0.75$, and $0.95$. As before, $y_0 = 1$, $w_0 = 1$, and $w_1 = w_2 = \cdots 0$ for each but this time set $T=20$. Add a legend to clearly identify which line has which $\rho$ value.
End of explanation
<END_TASK>