{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Interpreting Indicator Variables\n", "\n", "\n", "In this exercise we'll work with a (somewhat canonical) dataset on the prices, mileages, weights, and other characteristics of 74 automobiles. These data originally came from the April 1979 issue of Consumer Reports and from the United States Government EPA statistics on fuel consumption; they were compiled and published by Chambers et al. (1983).\n", "\n", "To get the data, follow [this link](https://github.com/nickeubank/MIDS_Data/blob/master/automobile_dataset.dta?raw=true) or go to [http://www.github.com/nickeubank/MIDS_Data](http://www.github.com/nickeubank/MIDS_Data) and download the `automobile_dataset.dta` file. This is a canonical example dataset used in coding examples all over the internet, and the codebook is roughly:\n", "\n", "```\n", "make Make and Model\n", "price Price\n", "mpg Mileage (mpg)\n", "rep78 Repair Record 1978\n", "headroom Headroom (in.)\n", "trunk Trunk space (cu. ft.)\n", "weight Weight (lbs.)\n", "length Length (in.)\n", "turn Turn Circle (ft.)\n", "displacement Displacement (cu. in.)\n", "gear_ratio Gear Ratio\n", "foreign Car type\n", "```\n", "\n", "\n", "## Indicator Variables and Omitted Variable Bias\n", "\n", "### Exercise 1\n", "\n", "Create a new variable named `guzzler` that takes the value of 1 if the car's miles per gallon (`mpg`) is less than 18 and takes value 0 otherwise (\"guzzler\" is a term for a car that consumes gas very quickly, or \"guzzles gas\"). Regress `price` on `guzzler` and interpret the coefficients. Do gas guzzlers cost more than the other cars? How much more?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 2\n", "\n", "Create a scatter plot of `price` against `weight` and color code your markers by the value of `guzzler` (red for `guzzler` = 1 and green for `guzzler` = 0). \n", "\n", "Based on the graph you just created, do you think **not** controlling for `weight` might lead to omitted variable bias in the regression in Exercise 1? What is the direction of the bias?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 3\n", "\n", "Regress `price` on `guzzler`, `weight`, `foreign`, `headroom`, and `displacement`. Interpret the coefficients. Do the regression results confirm your guess in Q3?\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 4\n", "\n", "Variable `rep78` indicates the car's repair record. The variable is poorly documented (we don't know that the value means) but take our word for it that the values from 1-5 indicate \"very poor\", \"poor\", \"acceptable\", \"good\", and \"very good\" record, respectively. \n", "\n", "Create five separate indicator variables from `rep78` and regress `price` on indicators for values 2 through 5. Also control for `headroom`, `weight`, `foreign`, and `displacement`. Interpret the coefficients on the indicator for `rep78 == 3`. \n", "\n", "(Note: You can use the `C()` method for creating indicator variables, but your answers will only be right if the omitted category is `rep78 == 1`)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Interaction Effects\n", "\n", "### Exercise 5\n", "\n", "You suspect that the effect of `guzzler` on `price` may be conditioned by whether or not the car is manufactured abroad. Regress `price` on `guzzler`, `foreign` **and their interaction,** controlling for `headroom`, `weight` and `displacement`. Without using mathematical language, explain to your grandma what the coefficient on the interaction term means." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 6\n", "\n", "What is the price difference between a foreign guzzler and a foreign non-guzzler?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 7\n", "\n", "What is the price difference between a domestic non-guzzler and a foreign non-guzzler?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 8\n", "\n", "Regress `price` on `foreign`, `mpg` and their interaction, controlling for `headroom`, `weight` and `displacement`. Interpret the coefficients of the main independent variables. Explain in layman terms the coefficient on the interaction term." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Absolutely positively need the solutions?\n", "\n", "*Don't use this link until you've really, really spent time struggling with your code!* Doing so only results in you cheating yourself. \n", "\n", "[Link](../solutions_warning.ipynb)" ] } ], "metadata": { "kernelspec": { "display_name": "base", "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.10.8" }, "vscode": { "interpreter": { "hash": "718fed28bf9f8c7851519acf2fb923cd655120b36de3b67253eeb0428bd33d2d" } } }, "nbformat": 4, "nbformat_minor": 4 }