SSID
1.1 Exercise 1: Single Regression
Please don’t forget to comment your code. Failure to do so will result in a loss of points.
Also, remember that all code that is required here (unless otherwise stated) can be found in the lecture Jupyter Notebooks or the coding notebooks from class.
Here are three models for the median starting salary of law school graduates in 1985.
log(salaryi) = b0 + b1 LSATi + ei
(1) log(salaryi) = b0 + b1 LSATi + b2GPAi + ei
(2) log(salaryi) = b0 + b1 LSATi + b2GPAi + b3log(costi) + b4ranki + ei
(3)Each observation i represents a school. The variables in the dataset are:
Variable Description
rank law school ranking
salary median starting salary
cost law school cost
LSAT median LSAT score
GPA median college GPA
libvol volumes in lib., 1000s
faculty of faculty
age age of law sch., years
clsize size of entering class
north =1 if law sch in north
south =1 if law sch in south
east =1 if law sch in east
west =1 if law sch in west
studfac student-faculty ratio
top10 =1 if ranked in top 10
In the code cell below, write the appropriate imports you will need for this question (we will need pandas, numpy and formula.api). You can do an abbreviated import if you wish (but the standard for pandas is pd, statsmodels.formula.api is smf, and numpy is np). Afterwards, load in the data from here:
https://raw.githubusercontent.com/lordflaron/ARE106data/master/lawsch85.csv
This can be done using the read_csv() function. Name this dataset raw_df. After loading in the data, show the first 10 observations in the output.
Use the describe() method on raw_df to show a table of summary statistics for each variable in the dataset. How many observations do salary have? Write this in a print statement. (Hint: This is in the “count” row the summary table).
NameError Traceback (most recent call last)
<ipython-input-56-894b02c4d62f> in <module>
1 ## b. Put your answer in this cell.
----> 2 describe(raw_df)
3 print("raw_df")
NameError: name 'describe' is not defined
Since we’ll need a log-transformed version of salaryi for all our models, use assign() to create a new variable which is the log of salaryi. Name this new variable log_salary.
Hints:
Remember that assign is not an inplace operation!
Remember to use a lambda function in this case. To log a variable, you can use np.log()
Remember the syntax for assign(): my_df.assign(new_variable = expression)
After this we now need to also drop any observations that are missing. This isn’t actually how econometricians deal with missing data, but this is good enough for us for now.
You can do this by chaining the dropna() method after the assign() method.
Warning: Do not do dropna BEFORE assign
The end result should look something like this:
df = raw_df.assign(log_salary= expression).dropna()
[3]:
Before estimating the model, explain how to interpret b1 in Model
Please write your answer for d here. If you need to use more than one line, you may do so.
Before estimating the model, explain how to interpret b1 in Model
Please write your answer for e here. If you need to use more than one line, you may do so.
Before estimating the model, do you expect b1 and b2 to be positive or negative in Model 2? Explain. (Hint: I’m not asking for any rigorous mathematical way to answer this question. Just use your economic intuition and reasoning skills to write an argument).
Please write your answer for f here. If you need to use more than one line, you may do so.
Estimate Model 1. Show the regression
What is the effect of a one unit increase in LSAT score on the log of median salary?
Please write your answer for h here. If you need to use more than one line, you may do so.
What does the R2 measure in the regression? What is the R2 in this case? (Not the adjusted
R2).
Please write your answer for i here. If you need to use more than one line, you may do so.
Exercise 2: Multiple Regression
This is a continuation of what we were doing in Exercise 1.
For this exercise, observe the expression for b1 when there are two regressors in the equation:
bˆ ∑N x1iyi ∑N x2
− ∑N x1ix2i ∑N x2iyivariances and covariances without changing the value of the coefficient (since N2 is 1).
N2
Also notice that the covariance is like an un-normalized correlation coefficient. So if you
calculate the correlation between two variables, you won’t know the covariance between the two, but you’ll know the direction and strength of their relationship. Estimate Model 2.
Calculate the correlations between log(salary)i, LSAT, and GPA.
Use the slicing notation to first make a subset of the data with only log_salary, LSAT and GPA.
Then use the corr() method to get the correlation for those variables, i.e. it will look something like this:
df[['log_salary', 'GPA', 'LSAT']].corr()
DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma
Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t
Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th
1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of
1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of
Get Free Quote!
276 Experts Online