```python
import numpy as np
import pandas as pd
import linearsolve as ls
import matplotlib.pyplot as plt
plt.style.use('classic')
%matplotlib inline
```

# Class 16: Real and Nominal Business Cycle Data

In this notebook, we will briefly explore US macroeconomic data suggesting that, contrary to the assumptions of most RBC models, there is in fact a relationship between real and nominal quantities over the business cycle. We will estimate an aggregate supply equation for the US and a monetary policy rule for the FOMC.

## Data

The file `business_cycle_data_actual_trend_cycle.csv`, available at https://github.com/letsgoexploring/econ126/raw/master/Data/Csv/business_cycle_data_actual_trend_cycle.csv, contains actual and trend data for real GDP per capita, real consumption per capita, real investment per capita, real physical capital per capita, TFP, hours per capita, the rea money supply (M2), (nominal) interest rate on 3-month T-bills, the PCE inflation rate, and the unemployment rate; each at quarterly frequency. The GDP, consumption, investment, capital, and money supply data are in terms of 2012 dollars. Hours is measured as an index with the value in October 2012 set to 100.


```python
# Read business_cycle_data_actual_trend.csv into a Pandas DataFrame with the first column set as the index and parse_dates=True


# Print the last five rows of the data

```

### Exercise: GDP and Inflation

Construct a plot of the cyclical components of GDP and inflation. 


```python
# Construct plot


# Place legend to right of figure. PROVIDED
plt.legend(loc='center left', bbox_to_anchor=(1, 0.5))
```

### Exercise: GDP and the 3-Month T-Bill Rate

Construct a plot of the cyclical components of GDP and the 3-month T-bill rate. 


```python
# Construct plot


# Place legend to right of figure. PROVIDED
plt.legend(loc='center left', bbox_to_anchor=(1, 0.5))
```

### Correlations Between GDP, Inflation, and 3-Month T-Bill Rate

Compute the coefficients of corrrelation between GDP, inflation, and the 3-month T-bill rate.


```python

```

Strong (but not perfect!) correlations between GDP and inflation and GDP and the T-bill rate suggest link between nominal and real quantities over the business cycle that should be exaplined by business cycle theory.

## Aggregate Supply

Contemporary business cycle models for monetary policy emphasize the importance of an upward-sloping aggreagate supply (AS) curve: a positive relationship between the cyclical components of output and inflation. We will uncover evidence of an upward-sloping AS curve for the US by estimating the following equation:

\begin{align}
\hat{\pi}_t & = \beta \hat{y}_t + \epsilon_t,
\end{align}

where $\hat{\pi}_t$ is the cyclical component of inflation, $\hat{y}_t$ is the cyclical component of real GDP for the US, and $\epsilon_t$ is the resudual of the regression. We do not estimate a constant because the data are mean 0.

Note that estimation exercise is subject to an endogeneity bias because output and inflation are in fact determined simultaneously in equilbrium. However, while the results we obtain my not be robust, they will be suggestive and that's enough for now.


```python
# Import statsmodels.api

```

### OLS Regression


```python
# Define variable 'X' to be equal to the cyclical component of real GDP


# Define variable 'X' to be equal to the cyclical component of inflation


# Initialze the OLS model


# Fit the OLS model


# Display estimation results

```

Apparently, a percent increase in GDP relative to trend corresponds with a 0.6 percent increase in the inflation rate.

### Plot results

Construct a scatter plot of the underelying data with the predicted values from the OLS regression.


```python
# Create variable 'x_values' as an array from -10 to 6


# Create variable 'y_values' using estimated value for beta


# Create figure and axis


# Scatter plot with poitn size of 50, opacity 0.25, and label of 'actual'


# Plot estimated relationship as a red line with label of 'fitted'


# Set x-axis limits to [-10,6]


# Axis labels and title


# Legend in the lower right corner with scatterpoints=1


# Grid

```

## Taylor's Monetary Policy Rule

Central banks in many countries set monetary policy with at least some autonomy. In the US, the Federal Reserve has broad discretion to decide how to manage its federal funds rate target in response to changes in the economy. The Federal Open Market Committee (FOMC), the monetary policymaking body within the Fed, comprises members of the Board of Governors and a rotating group of presidents from five of the regional Federal Reserve Banks.

The members of the FOMC can vote to set policy how they like and the composition of the FOMC changes regularly. So it might seem that modeling the decisionmaking of the FOMC would not be fruitful. But in fact, evidence shows that the FOMC does behave in a remarkably systematic way.

In his article "Discretion versus policy rules in practice" in the December 1993 issue of the *Carnegie-Rochester Conference Series on Public Policy*, John Taylor shows that monetary policy in the US could be approximated by a simple linear equation. (link to article: https://www.sciencedirect.com/science/article/pii/016722319390009L). His equation is:

\begin{align}
\text{Federal funds rate} & = \text{Inflation} + 0.5\cdot \text{Output gap} + 0.5\cdot(\text{Inflation - 2}) + 2,
\end{align}

where *inflation* is the percent change in the GDP deflator over the previous year and *output gap* is the percent deviation of GDP from a "target rate". Taylor assumed a target rate consistent with a constant growth GDP path of 2.2%. Note that the coefficients on inflation sum to 1.5.

You can see how well Taylor's rule fit the data as of 1993 in this figure from his paper:

<br>

<div align="center">
 <figure style="display: table">
    
  <figcaption style="display: table-caption; caption-side: top; text-align: center;" >Figure 1. <strong>Taylor's rule and the actual federal funds rate.</strong> Source: Taylor (1993)</figcaption>
</figure> 
</div>

<br>

Taylor doesn't estimate his equation precisely and it's remarkable that such a simple linear equation would even come close to matching policy. In this example, we will gather data to replicate Taylor's rule and estimate his rule using OLS.


```python
# Initial an empty DataFrame that will store data

```

### Federal Funds Rate

The federal funds are is the interest rate on overnight interbank loans. The FOMC sets a taget for the fed funds rate and implements monetary policy so that the actual (or *effective*) federal unds rate equals the FOMS's target. The effective federal funds rate has FRED series ID `FEDFUNDS` and is available here: https://fred.stlouisfed.org/series/FEDFUNDS. Notice that there are 62 lines of text *before* the line starting with "DATE".


```python
# Import federal funds rate data from FRED. Use arguments: sep='\s+',skiprows=62,index_col=0,parse_dates=True


# Set fed_funds equal to 'VALUE' column of fed_funds


# Use .resample('QS').mean() method of 'fed_funds' to convert the fed funds data from monthdy to quarterly


# Plot the federal funds rate. PROVIDED
plt.plot(fed_funds)
```

# Inflation

Taylor computes the inflation rate as the percent change in the GDP deflator from one year prior:

\begin{align}
\text{Inflation}_t = \frac{\text{GDP deflator}_t - \text{GDP deflator}_{t-4}}{\text{GDP deflator}_{t-4}}\cdot 100
\end{align}

The GDP deflator has FRED series ID `GDPDEF` and is available here: https://fred.stlouisfed.org/series/GDPDEF. Notice that there are 15 lines of text *before* the line starting with "DATE".


```python
# Import GDP deflator data from FRED. PROVIDED
deflator = pd.read_csv('https://fred.stlouisfed.org/data/GDPDEF.txt',sep='\s+',skiprows=15,index_col=0,parse_dates=True)

# Set deflator equal to 'VALUE' column of deflator. PROVIDED
deflator = deflator['VALUE']

# Compute the inflation rate


# Plot the inflation rate data. PROVIDED
plt.plot(inflation)
```

### Output gap

The output gap is measured as the percent difference of real GDP from the CBO's estimate of the potential real GDP:

\begin{align}
\text{Output gap} & = \left(\frac{\text{Real GDP}-\text{Real potential GDP}}{\text{Real potential GDP}}\right)\cdot 100
\end{align}

Real GDP has FRED series ID `GDPC1` and is available here: https://fred.stlouisfed.org/series/GDPC1. Notice that there are 17 lines of text *before* the line starting with "DATE".


```python
# Import real GDP data from FRED. PROVIDED
gdp_actual = pd.read_csv('https://fred.stlouisfed.org/data/GDPC1.txt',sep='\s+',skiprows=17,index_col=0,parse_dates=True)

# Set gdp_actual equal to 'VALUE' column of gdp_actual. PROVIDED
gdp_actual = gdp_actual['VALUE']
```

Potential real GDP has FRED series ID `GDPPOT` and is available here: https://fred.stlouisfed.org/series/GDPPOT. Notice that there are 12 lines of text *before* the line starting with "DATE".


```python
# Import potential real GDP data from FRED. PROVIDED
gdp_potential = pd.read_csv('https://fred.stlouisfed.org/data/GDPPOT.txt',sep='\s+',skiprows=12,index_col=0,parse_dates=True)

# Set gdp_potential equal to 'VALUE' column of gdp_potential. PROVIDED
gdp_potential = gdp_potential['VALUE']
```


```python
# Plot the actual and potential real GDP data with a legend. CELL PROVIDED
plt.plot(gdp_actual,label='actual')
plt.plot(gdp_potential,label='potential')
plt.legend(loc='lower right')
plt.title('Real GDP')
```

### Combine Data into a DataFrame


```python
# Create variable 'df' that is a DataFrame storing fed funds, inflation, actual and potential real GDP


# Drop missing values from 'df'

```


```python
# Construct an output gap column

```

Recall Taylor's rule:

\begin{align}
\text{Federal funds rate} & = \text{Inflation} + 0.5\cdot \text{Output gap} + 0.5\cdot(\text{Inflation - 2}) + 2
\end{align}


```python
# Construct a column called 'taylor' that implements Taylor's rule

```


```python
# Plot actual federal funds rate and the federal funds rate implied by Taylor's rule. CELL PROVIDED
plt.plot(df['fed_funds'],label='actual')
plt.plot(df['taylor'],label='Taylor')
plt.title('Federal Funds Rate')
plt.legend()
```

### OLS Model of the FOMC's Monetary Policy Rule

Following the format suggested by Taylor's rule, we'll estimate the following monetary policy rule for the US:

\begin{align}
\hat{i}_t & = \bar{\imath} + \phi_{\pi}\pi_t + \phi_{y} y_t + \epsilon_t
\end{align}

where $\pi_t$ is the percent change in the GDP deflator over the previous year and $y_t$ is the output gap measured as the percent difference of real GDP from the CBO's estimate of the potential real GDP. $\phi_{\pi}$ is the weight that the FOMC places on inflation in the rule and $\phi_{y}$ is the weight that the central bank places on the output gap. $\epsilon_t$ is the residual of the regression. 


```python
# Create variable 'X' with columns inflation, output and a constant


# Create variable 'Y' equal to the federal funds rate


# Initialize OLS model


# Fit OLS model


# Print regression results

```

The estimated constant in the regression is about 0.94 compared with 1 in Taylor's rule. The estimated coefficnets on inflation and the output gap are 1.22 and 0.12 compared with 1.5 and 0.5 in Taylor's rule. All three parameter estimates are remarkably close to Taylor's proposal. It's amazing that his rule still preforms will after almost 30 years.

Note, Taylor doens't argue that his rule is *optimal* in the sense that it is the best way for the FOMC to meet it's objectives. But there is evidence that it is actually very close to an optimal rule and therefore evidence that the FOMC does in fact tend to make good policy decisions.


```python
# Add column 'fed_funds_predicted' to df equal to predicted fed funds rate values from regression

```


```python
# Plot actual federal funds rate and the predicted federal funds. CELL PROVIDED
plt.plot(df['fed_funds'],label='actual')
plt.plot(df['fed_funds_predicted'],label='predicted')
plt.title('Federal Funds Rate')
plt.legend()
```

7ba738f787e18787272fdc7ba470fd3879afe60a
ipynb
Jupyter Notebook
Lecture Notebooks/Econ126_Class_16_blank.ipynb
letsgoexploring/econ126
05f50d2392dd1c7c38b14950cb8d7eff7ff775ee
MIT
2020-12-12T16:28:44.000Z
2021-02-24T12:11:04.000Z
Lecture Notebooks/Econ126_Class_16_blank.ipynb
letsgoexploring/econ126
05f50d2392dd1c7c38b14950cb8d7eff7ff775ee
MIT
2019-04-29T08:50:41.000Z
2019-04-29T08:51:05.000Z
Lecture Notebooks/Econ126_Class_16_blank.ipynb
letsgoexploring/econ126
05f50d2392dd1c7c38b14950cb8d7eff7ff775ee
MIT
2019-03-08T18:49:19.000Z
2022-03-07T23:27:16.000Z
Qwen/Qwen-72B
1. YES
2. YES