<jupyter_start><jupyter_text>EEP/IAS 118 - Introductory Applied Econometrics Problem Set 2, Spring 2022, Villas-Boas  See due date on time on Gradescope   Submit materials (pdf of your Jupyter notebook with all code cells run) as one combined pdf on [Gradescope](https://www.gradescope.com/courses/353120).  Exercise 1: Relationship between Airline Fares and Route Observable Variables  GuidelinesThis exercise should be completed using R. Remember, when you want an output to show in the notebook, you need to *explicitly* call the object in your R code. For example, if you want to show the mean oairline fare, you can't just type `MeanFare <- mean(fare)`, because that will just save the output to `MeanFare`. Instead, you need to then type `MeanFare` on its own so it displays the output. **Answers that do not display the desired output will be graded as incorrect.**To write comments in your script (text that will appear but will not be read as commands), type a \ at the beginning of the line. Use these as notes to keep track of which question you are trying to answer, the purpose of each command, etc.<jupyter_code># a commented out line of code - nothing happens if you run this cell<jupyter_output><empty_output><jupyter_text>To get started:This time you are opening a STATA-formatted ".dta" file, so you will use the `read_dta()` command instead of the import command that was applied to a “.csv” spreadsheet in the first problem set. You will need to load the `haven` package to do this. Your command should look like this: `DataName <- read_dta("file_name")`Exercises require both R work and written answers.  R Tips	* See the Coding Bootcamp Parts 1 and 2 for some basic operations (i.e. counting observations, scatterplots, generating variables) See also all the Lecture R command files to replicate lectures where we did most of what you are asked to do here : e.g., Lecture5.R, Lecture6.R, and Lecture7.R.* The command `table()` lists all values a variable takes in the sample and the number of times it takes each value. * To summarize data for a specified subset of the observations, you can use `filter()` to subset the data, and then either `summary()` for simple summary statistics or `summarise()` in `tidyverse` to generate more detailed summary statistics.  Data DescriptionThe data for this exercise come from the Domestic Airline Fares Consumer Report by the U.S. Department of Transportation for the year of 2000. In this problem set we delve into that data to provide insights into the airline fares and then relate the variation in airline fares in the sample to  trip characteristics and also the possibility of large carriers in the trip having a large share of the market and thus having some sort of pricing power. The pset2.dta file includes the following variables:The **dataPset2.dta** file includes the following variables:| Variable Name | Description                             ||---------------|-----------------------------------------|| origin      | Flight's origin                   || originstate          | Origin state || destin      | Flight's destination    || destinstate      | Destination state       || id             | route identifier      || dist        | distance, in miles || passen           | avg. passengers per day || fare          | avg. one-way fare (\$) || bmktshr       | market share (fraction of route market) held by biggest carrier |  PreambleWhen writing R code, it's a good habit to start your notebooks or R scripts with a preamble, a section where you load all necessary packages, set paths or change the working directory, or declare other options.Use the below code cell to load in packages you will use throughout the problem set (at least `haven` and `tidyverse` this week). *Note:* **never** try to install packages on Datahub. All packages that you need are already installed and can be loaded immediately using the `library()` function. Attempting to install packages will create conflicts with the package versions on the server and potentially corrupt your notebook.<jupyter_code># insert preamble code here<jupyter_output><empty_output><jupyter_text>Question 1First we would like you to become familiar with your data: (a) Please detail the following: How many routes are in the data set? How many routes have distance larger than 1000 miles?<jupyter_code># insert code here<jupyter_output><empty_output><jupyter_text>➡️ Type your written answer for Question 1a here (replacing this text). (b) What is the average fare in the data set?<jupyter_code># insert code here<jupyter_output><empty_output><jupyter_text>➡️ Type your written answer for Question 1b here (replacing this text). (c) What is the range for the variable **dist**, route distance, in the data?<jupyter_code># insert code here<jupyter_output><empty_output><jupyter_text>➡️ Type your written answer for Question 1c here (replacing this text). (d) Construct a variable **PricePerMile** equal to the fare divided by distance of the route. You will need to create this new variable in R.<jupyter_code># insert code here<jupyter_output><empty_output><jupyter_text>(e) Plot a histogram of this constructed variable. What is the range of airline price per mile flown in the US in 2000?<jupyter_code># insert code here<jupyter_output><empty_output><jupyter_text>➡️ Type your written answer Question 1e here (replacing this text). (f) What is the mean of **PricePerMile**? What is its median?<jupyter_code># insert code here<jupyter_output><empty_output><jupyter_text>➡️ Type your written answer for Question 1f here (replacing this text). (g) Compute the mean of price per mile flown separately for routes ending in California and those ending in all other states.*(hint: first create an indicator variable as an additional column in the dataset that equals one for routes that end in CA and is zero otherwise using*`my_data <- mutate(my_data,    destin_CA = ifelse(destinstate == "CA", 1,0)    )`    *Then, use `group_by()` and `summarise()` in the `tidyverse` package. See Coding Bootcamp Part 3 for more on grouped summary statistics)*<jupyter_code># insert code here<jupyter_output><empty_output><jupyter_text>(h) Do routes that end in CA have lower average price per mile than routes that end in other states? ➡️ Type your written answer for Question 1h here (replacing this text).  Question 2 Consider the following model where $x_i =$ average number of passengers per day on route $i$$$Fare_i= \beta_1 + \beta_2 x_i + u_i~~~~~~~~ i = \text{routes 1,2,...N in the data} ~~~~~~~~~~~~~~~~~~~~(eq.1)$$ (a) Estimate the model in R with the `lm()` command. Interpret your $\hat \beta_1$ and $\hat \beta_2$ coefficients, remembering the triplet S(ign), S(ignificance), S(ize), though you do not need to comment on significance in this problem set. **Make sure your uploaded pdf includes the R output.**<jupyter_code># insert code here<jupyter_output><empty_output><jupyter_text>➡️ Type your answer to Question 2a here (replacing this text). (b) How well does the average  number of passengers per day  predict the route fare? ➡️ Type your answer to Question 2b here (replacing this text). (c) What is the predicted fare for a route with an average of daily passengers of 5000?<jupyter_code># insert code here<jupyter_output><empty_output><jupyter_text>➡️ Type your answer to Question 2c here (replacing this text).  Question 3 Consider the following model where $x$ is once again the number of daily passengers per route:$$ log(Fare)_i = \beta_3 + \beta_4 log(x_i) + \nu_i ~~~~~~~~ i = \text{routes 1,2,...N in the data} ~~~~~~~~~~~~~~~~~~~~(eq.2)$$you need to generate the logarithm of the variables of interest for this question's model, namely the log of   average one-way fare and log of daily passengers. Use the `log()` function. (a) Estimate the model in R with the `lm()` command. Interpret your $\hat\beta_4$ coefficent, remembering the triplet S(ign), S(ignificance), S(ize), though you don't need to comment you need to generate the logarithm of the variables of interest for this question's model.<jupyter_code># insert code here<jupyter_output><empty_output><jupyter_text>➡️ Type your answer to Question 3a here (replacing this text). (b) Using the results from estimating (eq.2), how would you expect the route fare to change if the number of passengers increases by 1\%?<jupyter_code># insert code here<jupyter_output><empty_output><jupyter_text>➡️ Type your answer to Question 3b here (replacing this text). (c) How about if the number of passengers increases by 25\%?<jupyter_code># insert code here<jupyter_output><empty_output><jupyter_text>➡️ Type your answer to Question 3c here (replacing this text).  Question 4We will now explore the role of route characteristics in explaining the route fare where **x** is the average number of daily passengers in the route and **dist** is the route's distance$$Fare_i= \beta_1 + \beta_2 x_i + \beta_3 dist_i + \gamma_i~~~~~~~~ i = \text{routes 1,2,...N in the data} ~~~~~~~~~~~~~~~~~~~~(eq.3)$$ (a) How did your estimate $\hat \beta_2$ for x (that is, passengers) change between equation (eq.1) and equation (eq.3)?<jupyter_code># insert code here<jupyter_output><empty_output><jupyter_text>➡️ Type your answer to Question 4a here (replacing this text) (b) Without performing any calculations, what information does this give you about the correlation between the daily number of passengers and route distance? (Explain your reasoning in no more than 4 sentences. *Hint: OVB*) ➡️ Type your answer to Question 4b here (replacing this text) (c) Compute the correlation between the number of passengers and the biggest carrier market share. If you include the variable largest carrier market share in the model in equation (eq.3) and that slope coefficient estimate is 61.4, what do you think will happen to the estimated coefficient on the number of passengers when compared to the estimate you got in equation (eq. 3)? Explain your reasoning using OVB briefly here again.<jupyter_code># insert code here<jupyter_output><empty_output><jupyter_text>➡️ Type your answer to Question 4c here (replacing this text) d) Predict the expected fare for a route with 6000 daily passengers and a distance of 1200 miles using your estimates from equation (eq.3).<jupyter_code># insert code here<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08442376659881748, 'fraction_numerical': 0.009789667539013279, 'mean_word_length': 4.675467546754676, 'pattern_counts': {'":': 0, '<': 72, '<?xml version=': 0, '>': 69, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '17', 'dir': 'jupyter-structured-clean-dedup', 'id': '575736', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 2891, 'n_tokens_neox': 2751, 'n_words': 1440, 'path': 'Problem Sets/ProblemSet2/ProblemSet2_2022.ipynb', 'repo_name': 'ds-modules/ENVECON-118-SP22', 'size': '10317'}