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

pd.plotting.register_matplotlib_converters()
%matplotlib inline
```

# Discussion: Week 4

## Exercise: The Perpetual Inventory Method

The stock of physical capital is a fundamental component of many macroeconomic models but measuring, and therefore acquiring data on, the value of a country's capital stock is hard. The challenge arise because it is hard to estimate the value of something that is not changing ownership in a transaction. What is value of a high-rise apartment building that has had the same owner for 50 years?

One way to overcome this challenge is to use the **perpetual inventory method**. The perpetual inventory method is based on the law of motion of the capital stock:

\begin{align}
K_{t+1} & = I_t + (1-\delta) K_t
\end{align}

where $K_t$ denotes physical capital, $I_t$ denotes investment (purchases of new capital), and $\delta$ denotes the rate of depreciation. Give $K_0$ and data on investment $I_0, I_1, \ldots,$, the the capital stock in periods $1, 2, \ldots$ can be computed iteratively. To obtain $K_0$, the method assumes that the economy is in  a steady state in the initial year. Recall that in the steady state:

\begin{align}
I & = \delta K
\end{align}

So, set $K_0 = \delta^{-1} I_0$.

Steps:

1. Obtain real investment data (https://fred.stlouisfed.org/series/GPDICA)
2. Select a value for the depreciation rate $\delta$. 0.1 is a standard choice.
3. Initialize an array of zeros (or an empty array) to store capital values
4. Set the first value of the captial array equal to the $\delta^{-1} I_0$
5. Iterate over the values in the investment data to compute the remaining values of capital.

Read Timothy Kehoe's notes (http://users.econ.umn.edu/~tkehoe/classes/GrowthAccountingNotes.pdf) for more background on the perpetual inventory method if you're interested.


```python
# Import real investment data from FRED into a DataFrame called 'data' (PROVIDED)
data = pd.read_csv('https://fred.stlouisfed.org/data/GPDICA.txt',sep='\s+',skiprows=13,index_col=0,parse_dates=True)

# Set the columns attribute of data to ['Investment']


# Set the index.name attribute of data to 'Date' (i.e., data.index.name)


# Create a variable called 'delta' that stores the value for delta as 0.1


# Create a variable called 'capital' equal to an array of zeros with the same length as the variable 'data'


# Set the initial value of the 'capital' variable equal to the initial value of investment divided by delta


# Iterate (i.e., use a for loop) over t in range(len(capital)-1) to construct values in the capital array


# Add a 'Capital' column to data


# Divide data by 1000 so that the values are in units are in trillions of $ (instead of billions)


# Print the first 5 rows of data

```

Now construct a figure that contains a plot of capital in the top panel and investment in the bottom panel.

1. The figure should have dimensions $12\times 8$.
2. Y-axis labels for investment and capital should both be "trillions of chained dollars"
3. Each axis should have an appropriate title.


```python
# Create figure


# Construct the plot of capital


# Construct the plot of investment


# Use fig.tight_layout() to adjust whitespace

```

**Question**

1. Why does the computed capital series fluctuate less than the investment data?
2. Given that there are about 325 million people in the US, does the computed value in the last year look large, small, or about right on a per capita basis?

**Answer**

1.  

2.  

3b94176ddfdf45dd18df61dba6a9b6281032340d
ipynb
Jupyter Notebook
Discussion Notebooks/Econ126_Discussion_Week_04_blank.ipynb
t-hdd/econ126
17029937bd6c40e606d145f8d530728585c30a1d
MIT
Discussion Notebooks/Econ126_Discussion_Week_04_blank.ipynb
t-hdd/econ126
17029937bd6c40e606d145f8d530728585c30a1d
MIT
Discussion Notebooks/Econ126_Discussion_Week_04_blank.ipynb
t-hdd/econ126
17029937bd6c40e606d145f8d530728585c30a1d
MIT
Qwen/Qwen-72B
1. YES
2. YES