## DeLong: Teaching Economics ¶

Last edited: 2019-10-09

# Introduction: Math Tools ¶

#### Due ???? via upload to ??? ¶

This second introductory notebook will remind—well, at least familiarize—you with some math tools useful in economics:

For questions that are to be answered numerically, there is a code cell that starts with:

__# ANSWER__



and has a line in which there is a variable (like "X") currently set to underscores so:

X = ___



Replace those underscores with your final answer. It is okay to make other computations in that cell and others, so long as you set the variable to your answer.

### Math as a Tool ¶

#### Suppose a quantity grows at a steady proportional rate of 3% per year...¶

...How long will it take to double?

In [ ]:
# ANSWER
import math
n=math.log(2)/math.log(1.03)
print(n)
TIME_TO_DOUBLE = 23.45


In [ ]:
# ANSWER
import math
n=math.log(4)/math.log(1.03)
print(n)


Grow 1024-fold?

In [ ]:
# ANSWER
import math
n=math.log(1024)/math.log(1.03)
print(n)
TIME_TO_1024 = 234.50


#### Suppose we have a quantity x(t) that varies over time following the equation:¶

$\frac{dx(t)}{dt} = -(0.06)x + 0.36$

$\frac{dx(t)}{dt} - \frac{d(6)}{dt} = -(0.06)(x - 6)$

$\frac{dx(t)}{dt} = -(0.06)(x - 6)$

$\frac{dy(t)}{dt} = -(0.06)y$

Without integrating the equation:

$1.$ Tell me what the long-run steady-state value of $x$--that is, the limit of $x$ as $t$ approaches in infinity--is going to be.

In [ ]:
steady_state_val = 6


$2.$ Suppose that the value of $x$ at time $t=0$, $x(0)$ equals 12. Once again, without integrating the equation, tell me how long it will take x to close half the distance between its initial value of 12 and its steady-state value.

In [ ]:
half_dist_time = 12
import math
t=math.log(16)/0.06
print(t)


$3.$ How long will it take to close 3/4 of the distance?

In [ ]:
three_fourth_time = 23


$4.$ $7/8$ of the distance?

In [ ]:
seven_eighth_time = 35


$5.$ $15/16$ of the distance?

In [ ]:
fifteen_sixteenth = 46


Now you are allowed to integrate $\frac{dx(t)}{dt} = -(0.06)x + 0.36$.

$1.$ Write down and solve the indefinite integral.

ANSWER: $\frac{dx(t)}{dt} - \frac{d(6)}{dt} = -(0.06)(x - 6)$

$\frac{dy(t)}{dt} = -(0.06)y$

$\int \frac{dy(t)}{y} = \int -(0.06)dt$

$\ln y = -0.06t + c$

$y=c_{1}e^{-0.06t}$

$x=c_{1}e^{-0.06t}+6$

</font>

$2.$ Write down and solve the definite integral for the initial condition $x(0) = 12$.

ANSWER: $x=c_{1}e^{-0.06t}+6$

$x(0)=12$

$c_{1}=6$

$x=6e^{-0.06t}+6$

$3.$ Write down and solve the definite integral for the initial condition $x(0) = 6$.

ANSWER: $x=c_{1}e^{-0.06t}+6$

$x(0)=6$

$c_{1}=0$

$x=6$

</font>

#### Suppose we have a quantity $z = (\frac{x}{y})^\beta$¶

Suppose $x$ is growing at 4% per year and that $\beta=1/4$:

$1.$ How fast is $z$ growing if $y$ is growing at 0% per year?

In [ ]:
zero_per_growth = 1%


$2.$ If $y$ is growing at 2% per year?

In [ ]:
two_per_growth = 0.5%


$3.$ If $y$ is growing at 4% per year?

In [ ]:
four_per_growth = 0%


#### Rule of 72 (Use it for the next four questions)¶

1. If a quantity grows at about 3% per year, how long will it take to double?
In [ ]:
time_to_double = 24


$2.$ If a quantity shrinks at about 4% per year, how long will it take it to halve itself?

In [ ]:
time_to_half = 18


$3.$ If a quantity doubles five times, how large is it relative to its original value?

In [ ]:
doubled_five_times_ratio = 32


$4.$ If a quantity halves itself three times, how large is it relative to its original value?

In [ ]:
halved_three_times_ratio = 0.125


#### Interactive Model for Rule of 72¶

In future problem sets, you will build models of your own, but for now, look over this code. Its a simple model that shows what happens as you adjust a single parameter (the interest rate) and its effect on the outcome (the time to double). First we need to make sure all of our packages are imported.

In [ ]:
import matplotlib.pyplot as plt
import numpy as np
from ipywidgets import interact, IntSlider
%matplotlib inline


Our model is going to be graph that shows what happens as the interest rate varies.

In [ ]:
def graph_rule_of_72(interest_rate):
# np.linspace takes values evenly spaced between a stop and end point. In this case,
# will take 30 values between 1 and 10. These will be our x values in the graph.
x = np.linspace(1,10,30)

# Here we create are corresponding y values
y = 72 / x

print('Time to double:', 72 / interest_rate, 'years')

# graphing our lines
plt.plot(x,y)
# graphing the specific point for our interest_rate
plt.scatter(interest_rate, 72 / interest_rate, c='r')

plt.xlabel('interest rate (%)')
plt.ylabel('time (years)')
plt.show()


When we call interact, select the function that we want to interact with (graph_rule_of_72) and tell it what the value we want its parameters to take on. In this case, graph_rule_of_72 only takes one parameter, interest_rate, and we choose to put an adjustable slider there. You can check out the ipywidget examples for more uses.

In [ ]:
interact(graph_rule_of_72, interest_rate=IntSlider(min=1,max=10,step=1))


### Review: Measuring the Economy Concepts and Quantities ¶

#### National Income and Product Accounting¶

Explain whether or not, why, and how the following items are included in the calculations of national product:

$1.$ Increases in business inventories.

ANSWER: yes, so that New goods that are produced but go unsold will still be counted in the year in which they are produced.

$2.$ Fees earned by real estate agents on selling existing homes.

ANSWER: yes. The service of real estate agents needs to be counted.

$3.$ Social Security checks written by the government.

ANSWER: no. they do not involve the production of any good or service

$4.$ Building of a new dam by the Army Corps of Engineers.

ANSWER: yes. The goods and services purchased by the government to build the dam will count in GDP.

$5.$ Interest that your parents pay on the mortgage they have on their house.

ANSWER: no. It is not assumed to flow from the production of goods and services.

$6.$ Purchases of foreign-made trucks by American residents

ANSWER: Purchases of foreign-made trucks by American residents are counted in the calculation of GDP. They enter GDP negatively through the category IM and positively through C. In reality, C may be slightly greater than IM in magnitude. The net contribution to GDP would be positive due to the production of these American services.

#### In or Out of National Product? And Why¶

Explain whether or not, why, and how the following items are included in the calculation of national product:

$1.$ The sale for $\$25,000$of an automobile that cost$\$20,000$ to manufacture that had been produced here at home last year and carried over in inventory.

$2.$ The sale for $\$35,000$of an automobile that cost$\$25,000$ to manufacture newly- made at home this year.

$3.$ The sale for $\$45,000$of an automobile that cost$\$30,000$ to manufacture that was newly-made abroad this year and imported.

$4.$ The sale for $\$25,000$of an automobile that cost$\$20,000$ to manufacture that was made abroad and imported last year.

#### In or Out of National Product? And Why II¶

Explain whether or not, why, and how the following items are included in the calculation of GDP:

$1.$ The purchase for \$500 of a dishwasher produced here at home this year. ANSWER:$2.$The purchase for$500 of a dishwasher made abroad this year.

$3.$ The purchase for $500 of a used dishwasher. ANSWER: n GNP.$4.$The manufacture of a new dishwasher here at home for$500 of a dishwasher that then nobody wants to buy.

#### Components of National Income and Product¶

Suppose that the appliance store buys a refrigerator from the manufacturer on December 15, 2018 for $\$600$, and that you then buy that refrigerator on January 15, 2019 for$\$1000$:

$1.$ What is the contribution to GDP in 2018?

In [ ]:
contribution_2018 =


$2.$ How is the refrigerator accounted for in the NIPA in 2019?

$3.$ What is the contribution to GDP in 2019?

In [ ]:
contribution_2019 =


$4.$ How is the refrigerator accounted for in the NIPA in 2019?

In [ ]:
# These lines are reading in CSV files and creating dataframes from then, you don't have to change about them!

import pandas as pd
import numpy as np

from_2007 = quarterly_acc.loc[(quarterly_acc["Year"].isin(np.arange(2007, 2018)))]


### Estimating National Product¶

The Bureau of Economic Analysis measures national product in two different ways: as total expenditure on the economy’s output of goods and services and as the total income of everyone in the economy. Since – as you learned in earlier courses – these two things are the same, the two approaches should give the same answer. But in practice they do not.

We have provided a data table quarterly_gdp that contains quarterly data on real GDP measured on the expenditure side (referred to in the National Income and Product Accounts as “Real Gross Domestic Product, chained dollars”) and real GDP measured on the income side (referred to as “Real Gross Domestic Income, chained dollars”). The table refers to Real Gross Dometic Product as "Real GDP" and to Real Gross Dometic Income as "Real GDI", and they are measured in billions of dollars. (Note: You will not have to use Nominal GDP)

Another table, from_2007, has been created from quarterly_gdp, and includes information from 2007 to 2017. Below is a snippet from from_2007:

In [ ]:
from_2007.head(10)


$1.$ Compute the growth rate at an annual rate of each of the two series by quarter for 2007:Q1–2012:Q4.

In [ ]:
gdi_rate = ___
gdp_rate = ___
from_2007


$2.$ Describe any two things you see when you compare the two series that you find interesting, and explain why you find them interesting.

#### Calculating Real Magnitudes:¶

$1.$ When you calculate real national product, do you do so by dividing nominal national product by the price level or by subtracting the price level from nominal national product?

ANSWER: dividing nominal national product by the price level

$2.$ When you calculate the real interest rate, do you do so by dividing the nominal interest rate by the price level or by subtracting the inflation rate from the nominal interest rate?

ANSWER: subtracting the inflation rate from the nominal interest rate

$3.$ Are your answers to (a) and (b) the same? Why or why not?

ANSWER: no. The interest rate is a ratio.

### Unemployment Rate¶

Use the unemployment table provided to answer the following questions. All numbers (other than percents) are in the thousands.

Here are the first five entries of the table.

In [ ]:
unemployment.head()


#### What, roughly, was the highest level the U.S. unemployment rate (measured as Percent Unemployed of Labor Force in the table) reached in:¶

$1.$ The 20th century?

In [ ]:
unemployment.sort_values('Percent Unemployed\nof\nlabor\nforce', ascending=False)
1982


$2.$ The past fifty years?

In [ ]:
1982
un2=unemployment[unemployment["Year"]>=1964]
un2.sort_values('Percent Unemployed\nof\nlabor\nforce', ascending=False)


$3.$ The twenty years before 2006?

In [ ]:
1992
un3=unemployment[39:59]
un3.sort_values("Percent Unemployed\nof\nlabor\nforce", ascending=False)


$4.$ Given your answers to (1) through (3), Do you think there is a connection between your answer to the question above and the fact that Federal Reserve Chair Alan Greenspan received a five-minute standing ovation at the end of the first of many events marking his retirement in 2005?

#### The State of the Labor Market¶

$1.$ About how many people lose or quit their jobs in an average year?

In [ ]:
unemployment


$2.$ About how many people get jobs in an average year?

In [ ]:
average_getters = ___


$3.$ About how many people are unemployed in an average year?

In [ ]:
average_unemployed = ___


$4.$ About how many people are at work in an average year?

In [ ]:
average_workers = ___


$5.$ About how many people are unemployed now?

In [ ]:
unemployed_now = ___


#### National Income Accounting:¶

$1.$ What was the level of real GDP in 2005 dollars in 1970?

In [ ]:
quarterly_acc.loc[90:98]


$2.$ What was the rate of inflation in the United States in 2000?

In [ ]:
quarterly_acc.loc[211:215]


$3.$ Explain whether or not, how, and why the following items are included in the calculation of GDP: (i) rent you pay on an apartment, (ii) purchase of a used textbook, (iii) purchase of a new tank by the Department of Defense, (iv) watching an advertisement on youtube.

Congratulations, you have finished your first assignment for Econ 101B! Run the cell below to submit all of your work. Make sure to check on OK to make sure that it has uploaded.

Some materials this notebook were taken from Data 8, CS 61A, and DS Modules lessons.

## Introduction: Python and Economics ¶ 