<jupyter_start><jupyter_text>EEP/IAS 118 - Introductory Applied Econometrics Problem Set 4, Spring 2022, Villas-Boas Due in Gradescope – March 31, 2022 at 11.59pm  Submit materials (all handwritten/typed answers, Excel workbooks, and R reports) as one combined pdf on [Gradescope](https://www.gradescope.com/courses/353120). All students currently on the EEP118 bCourses have been added using the bCourses email. If you do not have access to the Gradescope course, please reach out to the GSI's.For help combining pdf's, see the "Tips for Saving/Combining PDFs" announcement on bCourses. For the purposes of this class, we will be primarily Berkeley's _Datahub_ to conduct our analysis remotely using these notebooks.If instead you already have an installation of R/RStudio on your personal computer and prefer to work offline, you can download the data for this assignment from bCourses (Make sure to install/update all packages mentioned in the problem sets in order to prevent issues regarding deprecated or outdated packages). The data files can be accessed directly  through $Datahub$ and do not require you to install anything on your computer. For full credit, all confidence intervals/hypothesis tests must be conducted **by hand** - you can use functions like `sd()` or `mean()` to get values to plug into the formulas, but **no credit** will be given for the use of canned interval/test functions (i.e. `linearHypothesis()`) with no steps/calculations provided.  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`, `tidyverse` and `ggplot` 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.  Data descriptionIn this problem set we will use a dataset on prices of apartments sold in 2015 in a country and the characteristics of the apartments as well as neighborhood characteristics, and also indicators on what season of the year each sale took place. One characteristic available is the distance of each apartment to the subway system (walking distance in meters).  Readme for data variables |Variable name 	|	Definition	||-----------|---------------||spring	| **=1** if apartment sold in the Spring 2015, **=0** if not. ||fall	| **=1** if apartment sold in the Fall 2015, **=0** if not.||winter	| **=1** if apartment sold in the Winter 2015, **=0** if not. ||sizeofunit	| Size of unit in square meters	| |price	| Apartment price in unnamed currency  |	|floor	| Apartment floor (from -1 to 79, i.e. basement to 79th floor) ||constructionyear	| Year of construction	| |numberofhighschools	| Number of high schools near apartment	| |distancetonearestgreenest | Network distance to greenest green space in meters	| |mediumage | Median age of residents ||populationdensity| Population density defined as population/city area	| |ratioadultswithhigherdegrees	| Adults with higher education degrees divided by number of adults	||distanceSubway	| Distance to a subway station in meters	|    Exercise 1:Using Hedonics to measure the economic value of  public transit systems  This exercise is to be completed using R. We will establish a simple linear relationship **between housing prices and characteristics of the house and also of the neighborhood** in a sample of apartments sold in 2015 in a unnamed country. This is called a hedonic regression, relating price to characteristics. The idea is that, if a characteristic is valued, demand for housing increases as people move there and then housing price increases, all else constant. Vice versa, if people do not value a characteristic, like crime or pollution, for example.   *Note: in economics, log always refers to the natural log, ln().* 1. Read the data into R and create a new variable __lprice__ as an additional column in the data, defined as the log of price_Note: The dataset is in Stata. It is available on bcourses and is called **pset4_2022.dta**._<jupyter_code># insert your code here<jupyter_output><empty_output><jupyter_text>2. For the following variables (price,  lprice, size of unit, distance to Subway, year constructed, and floor of apartment), get the sample mean, standard deviation, minimum, and maximum. _Hint: see the summarise() and across() section of Coding Bootcamp Part 1._<jupyter_code># insert your code here<jupyter_output><empty_output><jupyter_text>3. (a) Create a histogram for **price**, label everything, add axis and add a title. (b) Plot another histogram for apartments that are located close to the subway, where close is defined if the apartment is no more than 200 meters from the subway. (c) Finally, plot the same graph for apartments with a distance of 200 or more meters from the subway entrance. What is the average apartment price for each group? _Hint: see the Histograms section of Coding Bootcamp Part 4._<jupyter_code># insert your code for 3a here
# insert your code for 3b here
# insert your code for 3c here<jupyter_output><empty_output><jupyter_text>➡️ Type your written answer for _Exercise 1 Question 3_ here (replacing this text). 4. Estimate the model of apartment price as a linear function of a constant, distance to subway, and distance to the closest green space. Comment on the estimated intercept and each of the right hand side variables’ estimated parameters in terms of Sign, Size, and Significance (SSS).<jupyter_code># insert your code here<jupyter_output><empty_output><jupyter_text>➡️ Type your written answer for _Exercise 1 Question 4_ here (replacing this text). 5. In absolute terms, does a change in distance to subway or in distance to the closest greenspace have a larger impact on expected apartment sales price?_Hint: Use standardized from Lecture 13_<jupyter_code># insert your code here<jupyter_output><empty_output><jupyter_text>➡️ Type your written answer for _Exercise 1 Question 5_ here (replacing this text). 6. (a) Estimate the model of apartment prices as a linear function of a constant, distance to subway, distance to the closest greenspace, number of high schools, medium age of residents,  population density, and ratio of adults with highest degrees. (b) Test the joint significance of the variables medium age of residents, number of high schools, population density, and ratio of adults with highest degrees at the 10% significance level.<jupyter_code># insert your code for 6a here
# insert your code for 6b here<jupyter_output><empty_output><jupyter_text>➡️ Type your written answer for _Exercise 1 Question 6_ here (replacing this text). 7.	(a) Estimate the model of apartment prices as a linear function like in 6 and also add characteristics of the apartment (size of unit, floor, construction year). (b) Test jointly the significance of these three additional variables at the 5% significance level.<jupyter_code># insert your code for 7a here
# insert your code for 7b here<jupyter_output><empty_output><jupyter_text>➡️ Type your answer to _Exercise 1 Question 7_ here (replacing this text) 8.	I am still worried that the regression in 7 is not taking into account that the housing market is seasonal, and that more people may be seeking to buy during different seasons of the year and therefore we could have omitted variable bias. What regression do you propose to control for the season of the year each apartment sold in? Estimate that model. Looking at the coefficient on the distance to the subway, what do you conclude in terms of the seasonality of the housing markets having caused bias on the impact of distance to the subway?<jupyter_code># insert your code here<jupyter_output><empty_output><jupyter_text>➡️ Type your answer to _Exercise 1 Question 8_ here (replacing this text) 9.	(a) Consider now a model where you regress the price on only the size of the unit, the floor of the unit, and the distance to the subway. Specify a model to predict the average apartment price of an apartment that is located 150 meters from the subway, has a size of 200 square meters, and is on the 25th  floor of a building. (b) Construct a 99% confidence interval for the average predicted price for an apartment with those characteristics.<jupyter_code># insert your code for 9a here
# insert your code for 9b here<jupyter_output><empty_output><jupyter_text>➡️ Type your answer to _Exercise 1 Question 9_ here (replacing this text) 10.	What would be the 99% confidence interval for the predicted price of one apartment (not the average predicted) with those characteristics? Are you surprised that the intervals differ between question 10 and 11?_Hint: see lecture 14_<jupyter_code># insert your code here<jupyter_output><empty_output><jupyter_text>➡️ Type your answer to _Exercise 1 Question 10_ here (replacing this text) 11.	We want to select the best model to use for a future analysis of the benefits of public transportation. We are selecting between model (a) and model (b) below. Estimate both models, creating any variables you need.  Based on your estimated output using linear regression analysis, which model would you choose to use in the remaining analysis by policy makers thinking of measuring the economic benefits of expanding subway station locations? (a) $ price_i = \beta_0 + distanceSubway_i \beta_1 + sizeUnit \beta_2 + floor_i \beta_3 + ConstructionYear \beta_4 + u_i $(b) $ price_i = \gamma_0 + log(distanceSubway)_i \gamma_1 + sizeUnit \gamma_2 + floor_i \gamma_3 + ConstructionYear \gamma_4 + v_i $_Hint: see lecture 14_<jupyter_code># insert your code here<jupyter_output><empty_output><jupyter_text>➡️ Type your answer to _Exercise 1 Question 11_ here (replacing this text)  Exercise 2: Prices -  to Log or not to Log… We want to select the best model to use for a future analysis of the benefits of public transportation. We are selecting between model (a) and model (b) below. (a) $ price_i = \beta_0 + log(distanceSubway)_i \beta_1 + sizeUnit \beta_2 + floor_i \beta_3 + ConstructionYear \beta_4 + u_i $(b) $ log(price)_i = \gamma_0 + log(distanceSubway)_i \gamma_1 + sizeUnit \gamma_2 + floor_i \gamma_3 + ConstructionYear \gamma_4 + v_i $ 1. Estimate both models in exercise 2, creating any variables you need.  Which model would you choose to use in the remaining analysis by policy makers thinking of measuring the economic benefits of expanding subway station locations?  (_Hint: see lecture 15_)<jupyter_code># insert your code here<jupyter_output><empty_output><jupyter_text>➡️ Type your answer to _Exercise 2 Question 1_ here (replacing this text) 2.	Using model (b) from Exercise 2, please predict the average apartment price 150 meters from a subway and 150 square meters in size, and on the 13th floor constructed in 2009.<jupyter_code># insert your code here<jupyter_output><empty_output><jupyter_text>➡️ Type your answer to _Exercise 2 Question 2_ here (replacing this text)  Exercise 3: Ahh the Seasons… 1.	Estimate model 2b separately for apartments sold in the spring and those not sold in the spring (any other season). Formally test at the 10% significance level whether the regressions should be estimated separately or whether we can pool the data like we have been doing so far. (_Hint: See Lecture 17_)<jupyter_code># insert your code here<jupyter_output><empty_output><jupyter_text>➡️ Type your answer to _Exercise 3 Question 1_ here (replacing this text) 2. I would like to know whether the effect of the log of distance on the log of apartment prices (model 2b) differs depending on whether the median age of the residents is old (define old as median age being more than 50 – ok, I am old…). Estimate a model that enables you to test this and please interpret your findings. Compare the p value for the estimated coefficient of interest to the 10 percent significance level to conclude whether you reject the null of no heterogeneity in the effect of the closeness to subways stations on apartment prices mattering differently in areas where median age is 50 or more (older population), against a two sided alternative, holding all else equal. _Hint: Generate the old variable and then the interaction you need and add it to the regression._<jupyter_code># insert your code here<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.05541842503384027, 'fraction_numerical': 0.016004458953738355, 'mean_word_length': 5.029764762361978, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 61, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '186737', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 3407, 'n_tokens_neox': 3177, 'n_words': 1856, 'path': 'Problem Sets/ProblemSet4/Problem_Set_4_2022.ipynb', 'repo_name': 'ds-modules/ENVECON-118-SP22', 'size': '12559'}