Skip to content

Commit

Permalink
install statsmodel and update code
Browse files Browse the repository at this point in the history
  • Loading branch information
HumphreyYang committed Jul 5, 2024
1 parent 54552c0 commit 0ff86d2
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions lectures/calvo_gradient.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ $$
where $\theta_t$ satisfies

$$
\theta_t = (1-\lambda) \sum_{j=0}^{T-1-t} \lambda^j \mu_{t+j} + \lambda^{T-t} \bar \mu \tag{1}
\theta_t = (1-\lambda) \sum_{j=0}^{T-1-t} \lambda^j \mu_{t+j} + \lambda^{T-t} \bar \mu
$$

for $t=0, 1, \ldots, T-1$ and $\bar \theta = \bar \mu$.
Expand Down Expand Up @@ -170,6 +170,7 @@ We use the following imports in this lecture
!pip install --upgrade quantecon
!pip install --upgrade optax
!pip install --upgrade statsmodels
```

```{code-cell} ipython3
Expand Down Expand Up @@ -427,7 +428,7 @@ compute_V(optimized_μ, β=0.85, c=2) \
μs = np.array(optimized_μ)
# First regression: μ_t on a constant and θ_t
X1_θ = sm.add_constant(θs) # Add a constant term for the intercept
X1_θ = sm.add_constant(θs)
model1 = sm.OLS(μs, X1_θ)
results1 = model1.fit()
Expand All @@ -437,11 +438,6 @@ print(results1.summary())
```

```{code-cell} ipython3
results1.predict(X_θ)
```

```{code-cell} ipython3
# Plot for the first regression
plt.scatter(θs, μs, label='Data')
plt.plot(θs, results1.predict(X1_θ), 'C1', label='$\hat \mu_t$', linestyle='--')
plt.xlabel(r'$\theta_t$')
Expand All @@ -452,8 +448,8 @@ plt.show()

```{code-cell} ipython3
# Second regression: θ_{t+1} on a constant and θ_t
θ_t = np.array(computed_θ[:-1]) # θ_t
θ_t1 = np.array(computed_θ[1:]) # θ_{t+1}
θ_t = np.array(θs[:-1]) # θ_t
θ_t1 = np.array(θs[1:]) # θ_{t+1}
X2_θ = sm.add_constant(θ_t) # Add a constant term for the intercept
model2 = sm.OLS(θ_t1, X2_θ)
results2 = model2.fit()
Expand Down

1 comment on commit 0ff86d2

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.