9/9/2020 Problem set 1 Jason Parker In this problem set, the data sets are available as tables in the wooldridge2.db file. You can find out how to connect to databases in chapter 2 section 2.1.2.6 of my book. I have also uploaded a wpull function in my startup_script.R code which can be used to pull particular tables from the database (if you are in the right working directory–hint). Your solution should have the code you used in a .txt file with the answers as comments. Please format your code neatly in some way similar to the example that I have posted in box. Question 1 Use the data in the wage1 table for this exercise. 1. Find the average education level in the sample. What are the lowest and highest years of education? wage1 <- wpull('wage1') summary(wage1$educ) #Average is 12.56 #Lowest is 0 #Highest is 18 2. Find the average hourly wage in the sample. Does it seem high or low? summary(wage1$wage) #Average is 5.91, which seems low 3. The wage data are reported in 1976 dollars. Using the Economic Report of the President (2011 or later), obtain and report the Consumer Price Index (CPI) for the years 1976 and 2010 #CPI for 1976 was 56.9 #CPI for 2010 was 218.1 4. Use the CPI values from above to find the average hourly wage in 2010 dollars. Now does the average hourly wage seem reasonable? mean(wage1$wage)/56.9*218.1 #22.65 per hour, which seems reasonable 5. How many women are in the sample? How many men? table(wage1$female) #252 female, 274 male Question 2 The data in meap01 table are for the state of Michigan in the year 2001. Use these data to answer the following questions. 1. Find the largest and smallest values of math4. Does the range make sense? Explain. meap01 <- wpull('meap01') summary(meap01$math4) #Largest 100 #Smallest 0 #Makes sense because it indicates the maximum and minimum possible scores 1 2. How many schools have a perfect pass rate on the math test? What percentage is this of the total sample? sum(meap01$math4==100) mean(meap01$math4==100) # 38 schools scored perfectly, which is ~2% of the sample size 3. How many schools have math pass rates of exactly 50%? sum(meap01$math4==50) # 17 4. Compare the average pass rates for the math and reading scores. Which test is harder to pass? mean(meap01$math4) mean(meap01$read4) #Math 71.9 vs Reading 60.1. Reading seems to be harder. 5. Find the correlation between math4 and read4. What do you conclude? cor(meap01$math4,meap01$read4) #.84, which a high correlation 6. The variable exppp is expenditure per pupil. Find the average of exppp along with its standard deviation. Would you say there is wide variation in per pupil spending? mean(meap01$exppp) sd(meap01$exppp) #Average is $5,194, with a stdev of $1,092. Seems like a reasonable variation. 7. Suppose School A spends $6000 per student and School B spends $5500 per student. By what percentage does School A’s spending exceed School B’s? Compare this to 100 ∗ [ln(6000) − ln(5500)], which is the approximation percentage difference based on the difference in the natural logs. (6000-5500)/5500 log(6000)-log(5500) #Actual 9.1% vs Log 8.7%, .4% difference Question 3 The data in 401k are a subset of data analyzed by Papke (1995) to study the relationship between participation in a 401(k) pension plan and the generosity of the plan. The variable prate is the percentage of eligible workers with an active account; this is the variable we would like to explain. The measure of generosity is the plan match rate, mrate. This variable gives the average amount the firm contributes to each worker’s plan for each $1 contribution by the worker. For example, if mrate = 0.50, then a $1 contribution by the worker is matched by a 50? contribution by the firm. 1. Find the average participation rate and the average match rate in the sample of plans. k401<- wpull('401k') mean(k401$prate) mean(k401$mrate) #Average prate 87.4% #Average mrate 73.2% 2. Now, estimate the simple regression equation: ˆ ˆ prateˆ = β 0 + β 1mrate, and report the results along with the sample size and R-squared. model <- lm(prate~mrate,data=k401) summary(model) #Estimated prate=83.1+5.86mrate 2 #Sample size=1,532, R^2=.075 3. Interpret the intercept in your equation. Interpret the coefficient on mrate. The intercept implies that if the mrate=0, then the predicted prate is 83.1%. The coefficient of mrate shows that for every 1% increase in mrate, the prate increases by 5.86%. 4. Find the predicted prate when mrate = 3.5. Is this a reasonable prediction? Explain what is happening here. 83.08+5.86*3.5 This predicts a prate of 103.59%. Obviously this doesn’t work because the max can only be 100%. Because this is a simple regression model, extreme values can give unrealistic predictions. 5. How much of the variation in prate is explained by mrate? #The R^2 is only 7.5%, which means the mrate has very low influence on the model. There's likely other factors that better explain prate. Question 4 The data set in ceosal2 contains information on chief executive officers for U.S. corporations. The variable salary is annual compensation, in thousands of dollars, and ceoten is prior number of years as company CEO. 1. Find the average salary and the average tenure in the sample. ceosal2 <- wpull('ceosal2') summary(ceosal2) #Average salary is $865,900. Average tenure is 7.955 years. 2. How many CEOs are in their first year as CEO (that is, ceoten = 0)? What is the longest tenure as a CEO? sum(ceosal2$ceoten==0) #5 CEOs in the first year. Longest tenure is 37 years. 3. Estimate the simple regression model ln[salary] = β0 + β1ceoten + u and report your results in the usual form. What is the (approximate) predicted percentage increase in salary given one more year as a CEO? model1=lm(log(salary)~ceoten,data=ceosal2) summary(model1) #6.505498+.009724(ceoten). 1 year of CEO tenure is associated with .97% increase in pay. Question 5 Use the data in wage2 to estimate a simple regression explaining monthly salary (wage) in terms of IQ score (IQ). 1. Find the average salary and average IQ in the sample. What is the sample standard deviation of IQ? (IQ scores are standardized so that the average in the population is 100 with a standard deviation equal to 15.) wage2<- wpull('wage2') mean(wage2$wage) mean(wage2$IQ) sd(wage2$IQ) #Average salary $957.95. Average IQ 101. Stdev 15.05. 2. Estimate a simple regression model where a one-point increase in IQ changes wage by a constant dollar amount. Use this model to find the predicted increase in wage for an increase in IQ of 15 points. Does IQ explain most of the variation in wage? wageIQmodel=lm(wage~IQ,data=wage2) 3 summary(wageIQmodel) 8.3*15 #15 point increase in IQ is associated with $124.50 increase in salary. The R^2 is only .0955, which means IQ isn't a very good predictor of salary. 3. Now, estimate a model where each one-point increase in IQ has the same percentage effect on wage. If IQ increases by 15 points, what is the approximate percentage increase in predicted wage? wageIQmodellog=lm(log(wage)~IQ,data=wage2) summary(wageIQmodellog) .0088*15 #13.2% increase per 15 IQ points Question 6 Using the meap93 data, we want to explore the relationship between the math pass rate (math10) and spending per student (expend). 1. Do you think each additional dollar spent has the same effect on the pass rate, or does a diminishing effect seem more appropriate? Explain. #Diminishing effect makes more sense. As you get closer to 100% pass rates, it becomes more difficult to see the same incremental improvements. 2. In the population model, math10 = β0 + β1 ln[expend] + u argue that β1/10 is the percentage point change in math10 given a 10% increase in expend. #In this model, b1=11.164. Because logs are in percentages, b1/10 can also be notated as b1*10%. Hence b1/10 is associated with a 10% increase in expend. 3. Estimate this model. Report the estimated equation in the usual way, including the sample size and Rsquared. meap93<-wpull('meap93') meap93model<-lm(math10~log(expend),data=meap93) summary(meap93model) #math10=-69.341+11.164*log(expend). Sample size is 408, and the R^2 is .02966. 4. How big is the estimated spending effect? Namely, if spending increases by 10%, what is the estimated percentage point increase in math10? 11.164*.1 #There is a 1.12% increase in math10. 5. One might worry that regression analysis can produce fitted values for math10 that are greater than 100. Why is this not much of a worry in this data set? max(meap93$math10) #The max math10 in the dataset is 66.7, which means it's highly unlikely that 100+ scores would occur. Question 7 Use the data in hprice1 to estimate the model price = β0 + β1sqrft + β2bdrms + u, where price is the house price measured in thousands of dollars. 1. Write out the results in equation form. 4 2. 3. 4. 5. 6. hprice1 <- wpull('hprice1') hprice1model<-lm(price~sqrft+bdrms,data=hprice1) summary(hprice1model) #hprice1=-19.315+.12844sqrft+15.19819bdrms What is the estimated increase in price for a house with one more bedroom, holding square footage constant? #One more bedroom is associated with an increase of 15.2% What is the estimated increase in price for a house with an additional bedroom that is 140 square feet in size? Compare this to your answer from above. (140*.12844) +15.19819 #One more bedroom and 140 additional sq ft is associated with an increase of 33.18. What percentage of the variation in price is explained by square footage and number of bedrooms? #The R^2 is .6319, so 63.2% of price variation is associated with bedrooms and square feet. The first house in the sample has sqrft = 2438 and bdrms = 4. Find the predicted selling price for this house from the OLS regression line. -19.315+(15.19819*4)+(.12844*2438) #The associated price is $354,614.50 The actual selling price of the first house in the sample was $300000 (so price = 300). Find the residual for this house. Does it suggest that the buyer underpaid or overpaid for the house? 354614.50-300000 #The residual was $54,614.50, which means the buyer underpaid. Question 8 The file ceosal2 contains data on 177 chief executive officers and can be used to examine the effects of firm performance on CEO salary. 1. Estimate a model relating annual salary to firm sales and market value. Make the model of the constant elasticity variety for both independent variables. Write the results out in equation form. ceosal2 <- wpull('ceosal2') ceosal2model<-lm(log(salary)~log(sales)+log(mktval),data=ceosal2) summary(ceosal2model) Log(salary) = 4.62092 + 0.1621log(sales) + 0.1067log(mktval) 2. Add profits to the model. Why can this variable not be included in logarithmic form? Would you say that these firm performance variables explain most of the variation in CEO salaries? ceosal3model<-lm(log(salary)~log(sales)+log(mktval)+profits,data=ceosal2) summary(ceosal3model) #Profits can be negative, so they won't work in log form. R^2 is .2993, so there is another ~70% associated with other factors. 3. Now also add the variable ceoten to the model. What is the estimated percentage return for another year of CEO tenure, holding other factors fixed? ceosal4model<-lm(log(salary)~log(sales)+log(mktval)+profits+ceoten,data=ceosal2) summary(ceosal4model) #One year increase in CEO tenure is associated with 1.17% in pay. 4. Find the sample correlation coefficient between the variables log(mktval) and profits. Are these variables highly correlated? What does this say about the OLS estimators? cor(log(ceosal2$mktval),ceosal2$profits) #They are 77.7% correlated to each other, which is a high correlation. Since they are highly correlated, there's a risk of multi-collinearity. It could be difficult to understand their independent effects. 5 Question 9 Use the data in attend for this exercise. Create the variable atndrte which is attend/32 because there were 32 classes. 1. Obtain the minimum, maximum, and average values for the variables atndrte, priGPA, and ACT. attend <- wpull('attend') attend$atndrte <- attend$attend/32 summary(attend$atndrte) summary(attend$priGPA) summary(attend$ACT) #atndrte- Min .0625, Max 1.0, Avg .8171 #priGPA- Min .857, Max 3.93, Avg 2.587 #ACT- Min 13, Max 32, Avg 22.51 2. Estimate the model atndrte = β0 + β1GPA + β2ACT + u and write the results in equation form. Interpret the intercept. Does it have a useful meaning? atndrtemodel<-lm(atndrte~priGPA+ACT,data=attend) summary(atndrtemodel) #.757 + .17261 priGPA – .01717 ACT #If priGPA and ACT is 0, attendance is associated with 75.7%, which wouldn’t make sense. 3. Discuss the estimated slope coefficients. Are there any surprises? #The attendance shows to go down by 1.7% for every point increase in ACT scores, which is surprising. 4. What is the predicted atndrte if priGPA = 3.65 and ACT = 20? What do you make of this result? Are there any students in the sample with these values of the explanatory variables? 0.7570 + (0.1726*3.65)- (0.0172*20) #Predicted value is 104.3%. This is greater than 100%, which isn't possible. nrow(attend[priGPA==3.65 & ACT==20]) #There's one student with these values. 5. If Student A has priGPA = 3.1 and ACT = 21 and Student B has priGPA = 2.1 and ACT = 26, what is the predicted difference in their attendance rates? 0.7570 + (0.1726*3.1) - (0.0172*21) 0.7570 + (0.1726*2.1) - (0.0172*26) #Student A is predicted at .93086 and Student B is .67226 .93086-.67226 #The predicted difference is .2586 Question 10 Use the data in htv to answer this question. The data set includes information on wages, education, parents’ education, and several other variables for 1,230 working men in 1991. 1. What is the range of the educ variable in the sample? What percentage of men completed 12th grade but no higher grade? Do the men or their parents have, on average, higher levels of education? htv <- wpull('htv') 6 summary(htv$educ) #Min is 6 and Max is 20 sum(htv$educ==12) 512/1230 #41.6% completed 12th grade. summary(htv$educ) summary(htv$motheduc) summary(htv$fatheduc) #On average, men have higher eduction than their parents. 2. Estimate the regression model educ = β0 + β1motheduc + β2fatheduc + u by OLS and report the results in the usual form. How much sample variation in educ is explained by parents’ education? Interpret the coefficient on motheduc. educmodel<-lm(educ~motheduc+fatheduc,data=htv) summary(educmodel) #6.96435 + 0.30420motheduc + 0.19029fatheduc #24.93% is explained by mother and father's education #Motheduc's coefficient is .30420, which means that every year of mother's education the men's education is associated with a 30.4% increase. 3. Add the variable abil (a measure of cognitive ability) to the regression above, and report the results in equation form. Does ability help to explain variations in education, even after controlling for parents’ education? Explain. educmodel2<-lm(educ~motheduc+fatheduc+abil,data=htv) summary(educmodel2) #8.44869 + 0.18913 motheduc + 0.11109 fatheduc + 0.50248 abil #R^2 is .4275, which is much higher than the previous model. This implies that cognitive is a significant factor, even with the parents' education being factored in. 4. Now estimate an equation where abil appears in quadratic form: educ = β0 + β1motheduc + β2fatheduc + β3abil + β4abil2 + u. With the estimated coefficients on ability, use calculus to find the value of abil where educ is minimized. (The other coefficients and values of parents’ education variables have no effect; we are holding parents’ education fixed.) Notice that abil is measured so that negative values are permissible. You might also verify that the second derivative is positive so that you do indeed have a minimum. #b0 +b1 motheduc +b2 fatheduc +b3 abil +b4abil^2 +u #d educ/ d abil = b3 + 2b4abil #0.4015 + 2*0.0506abil = 0 #abil = - 3.9674 5. Argue that only a small fraction of men in the sample have ability less than the value calculated above. Why is this important? sum(htv$abil<=-3.97) (15/1230) #1.2% of men have an ability less than -3.97. We do not have enough data points for this ability level. 7 6. Use the estimates above to plot the relationship between the predicted education and abil. Let motheduc and fatheduc have their average values in the sample, 12.18 and 12.45, respectively. htv2<-htv htv2$motheduc<-(htv2$motheduc)*2 htv2$fatheduc<-(htv2$fatheduc)*2 htv2$motheduc<-12.18 htv2$fatheduc<-12.45 ggplot(htv,aes(x=abil,y=educ))+ geom_point()+ geom_line(aes(y=predict(educmodel2,htv2)),color="Blue")+ scale_x_continuous('Cognitive Ability')+ scale_y_continuous('Years of Education') 8