{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Exam 1\n",
"\n",
"files needed = ('taylor.csv')\n",
"\n",
"Answer all the questions below in this notebook. You should insert as many cells into the notebook as you need. When you are finished, upload your finished notebook to Canvas. \n",
"\n",
"You may use your notes and the Internet, but you cannot work with others in class. Remember, jupyter notebooks and python have lots of built in help facilities. \n",
"\n",
"The best way to use this practice exam is to first study, and then take the exam as you would in class --- with a 1:15 time cap. When you are finished, I would appreciate it if you took the quick two-question survey to give me your thoughts. [Survey link](https://forms.gle/pVKQ2Qjz9ez8X4U98) "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question 0\n",
"Copy the following text into a new cell. \n",
"\n",
"`The quick brown fox jumps over the lazy dog.`\n",
"\n",
"Then:\n",
"\n",
"1. Strikethrough the word 'brown'\n",
"2. Italicize the word 'jumps'\n",
"3. Make the words 'lazy dog' a link to https://www.akc.org/dog-breeds/pug\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question 1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"1. Capitalize the entries in `list1` and store them in `list2`.\n",
"2. Insert `F` into `list2` in a way that preserves the alphabetic ordering of `list2`.\n",
"3. Slice `list2` into two lists: `list2a` includes letters 'A' through 'B' (inclusive) and `list2b` includes 'C' through 'J' (inclusive).\n",
"4. Print out `list2`, `list2a`, and `list2b` "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"list1 = ['a', 'b', 'c', 'd', 'e', 'g', 'h', 'i', 'j']"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question 2\n",
"1. Using a loop, sum the squares of the numbers from 0 to 50. That is, compute the sum \n",
"$$0+1^2 + 2^2+3^2+\\cdots+50^2$$\n",
"2. Print out the sum and use string formatting to separate the thousands with a comma: xxx,xxx. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question 3\n",
"1. Write a function called `linear_demand` that takes a price as an input and returns the quantity demanded. The demand function is\n",
"$$ d(p) = -2\\times p + 10$$\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"2. Using a loop or list comprehension, compute demand for the following list of prices and store the associated demands in a list named `demands`. Print `demands`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"prices = [0.5, 0.75, 1, 1.2, 2, 2.25, 3.33333, 6]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"3. Write a new function named `linear_demand_2` that computes demand as in part 1, but have the function return 0 if the computed demand is negative and the computed demand if it is positive. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"4. Test your new function on `p=6` and `p=2.25`. Print the demands associated with each price."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question 4\n",
"\n",
"Now let's work with some data. This question should be completed using a pandas DataFrame. \n",
"\n",
"The Taylor rule relates the **target** federal funds rate $i$ to the inflation rate $\\pi$ and log gdp $y$ according to \n",
"\n",
"$$ i_t = \\pi_t + r^*_t + 0.5(\\pi_t-\\pi^*_t)+0.5(y_t-\\bar{y}_t)\\times100$$\n",
"\n",
"where $r^*$ is the 'long-run' real interest rate, $\\pi^*$ is the target inflation rate and $\\bar{y}_t$ is log 'potential gdp'. \n",
"\n",
"Let the long-run interest rate and the inflation target be constant: $r^*_t=1.25$ and $\\pi^*_t=2.0$.\n",
"\n",
"### Data\n",
"The file 'taylor.csv' contains quarterly data on the components of the Taylor rule:\n",
"* DATE = the date, '.00' means the first quarter, '.25' means the second quarter, '.50' means the third quarter and '.75' means the fourth quarter. \n",
"* PCETRIM12M159SFRBDAL = the inflation rate, expressed in percent\n",
"* FEDFUNDS = the **actual** federal funds rate, expressed in percent\n",
"* GDPPOT = log potential GDP\n",
"* GDPC1 = log GDP"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"1. Load 'taylor.csv'. \\[Make sure the data are what you expect! We'll be using data from 1978-2019.\\] "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"2. Rename \n",
" * 'PCETRIM12M159SFRBDAL' to 'inflation' \n",
" * 'GDPPOT' to 'pot_gdp'\n",
" * 'FEDFUNDS' to 'fed_funds'\n",
" * 'GDPC1' to 'gdp'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"3. Using the data, compute the target federal funds rate using the Taylor rule equation. Store it in a variable named `taylori`."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"4. Compute `taylori` - `fed_funds`. This is the difference between the Taylor rule's target fed funds rate and the actual fed funds rate. Store the difference in a variable named 'deviation'. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"5. Print out the following, each with three digits to the right of the decimal place. \n",
" 1. The mean and max deviation for 1978-2019\n",
" 2. The mean and max deviation for 1978-1985\n",
" 3. The mean and max deviation for 2008-2019\n",
" \n",
"Print them out as statements like: \n",
"\n",
"'1978-2019: The mean deviation is x.xxx percent and the max deviation is x.xxx percent.'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### You are finished!\n",
"Upload your completed notebook to Canvas. \n",
"\n",
"\\[Well, not this one, because it is a practice. You could take the [survey](https://forms.gle/pVKQ2Qjz9ez8X4U98), though, to let me know how it went.\\]"
]
}
],
"metadata": {
"celltoolbar": "Attachments",
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}