library(psych)
library(lmtest)
library(sandwich)
library(ggplot2)
reg1 <- lm(log(ahe) ~ yrseduc + age + female + hsdipl, data = cps99_ps3)
summary(reg1)
Call:
lm(formula = log(ahe) ~ yrseduc + age + female + hsdipl, data = cps99_ps3)
Residuals:
Min 1Q Median 3Q Max
-2.37760 -0.28810 0.02876 0.32185 1.59381
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.1831860 0.0167710 70.55 <2e-16 ***
yrseduc 0.0814235 0.0011400 71.42 <2e-16 ***
age 0.0074897 0.0002449 30.59 <2e-16 ***
female -0.2440905 0.0048827 -49.99 <2e-16 ***
hsdipl 0.1269925 0.0097665 13.00 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.469 on 37805 degrees of freedom
Multiple R-squared: 0.2385, Adjusted R-squared: 0.2384
F-statistic: 2960 on 4 and 37805 DF, p-value: < 2.2e-16
Yrseduc means that when all other variables remain same one additional year of education increases wage by \(8.37\)%
Age means that when all other variables remain same one additional year of age increases wage by \(0.6\)%
Female means that when all other variables remain same being the woman decreases wage by \(24.4\)%
Explanation of the root mean squared error in this regression is that the prediction of the regression in general deviated by \(46.48\) percentage points from the actual number.
Solution:
confint(reg1, "female", vcov = vcovHC(reg1, type = "HC1"))
2.5 % 97.5 %
female -0.2536607 -0.2345203
Thus, the 95% confidence interval for the gender gap in earnings (controlling for age, years of education, and obtaining a high school diploma) is (-25.4%, -19.43%).
coef1 <- coeftest(reg1, vcov = vcovHC(reg1, type = "HC1"))
coef1
t test of coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.18318604 0.01655335 71.477 < 2.2e-16 ***
yrseduc 0.08142350 0.00115179 70.693 < 2.2e-16 ***
age 0.00748968 0.00024823 30.172 < 2.2e-16 ***
female -0.24409049 0.00485128 -50.315 < 2.2e-16 ***
hsdipl 0.12699253 0.00978548 12.978 < 2.2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
coef1[5,1]
[1] 0.1269925
We got that the coefficient on \(hsdipl\) is 0.0836225 and it shows that estimated marginal value of 12 years of education that is followed by getting a high school diploma (\(8.36\)%) if we remain constant the number of years of education and all other variables remain same.
The coefficient on \(hsdipl\) has t statistics equal to \(2.6478>1.96\) therefor the null hypothesis (that marginal value is zero) is rejected.
The marginal value is relatively high in a real-world sense because those people who got a diploma receive 1 monthly wage more in a year compared to those who didn’t get the diploma (if people without the diploma get 12 monthly wages in year, people who got the diploma receive 13 in the same year).
\[ln(ahe) = \beta_0 + \beta_1 * yrseduc_i + \beta_2 * age_i + \beta_3 * female_i + \beta_4 * hsdipl_i + u_i\]
Marginal value of 12 years of education plus high school diploma, relative to the value of having 10 years of education, holding constant age and gender, means it is having 2 additional years of education to complete and get the diploma. Thus, \(V = 2 *\beta_1 + \beta_4\) from the lecture slides. So, we can rewrite it as: \[V = 2*\beta_1 + \beta_4 = 2* 0.08371618 + 0.08362250 = 0.2510549\]
2* 0.08371618 + 0.08362250
[1] 0.2510549
Then, the marginal value is \(25.10549\)%, which is relatively high in a real-world sense.
cps99_ps3$yrseduc2 <- cps99_ps3$yrseduc/2
cps99_ps3$var <- cps99_ps3$hsdipl - cps99_ps3$yrseduc/2
reg2 <- lm(log(ahe) ~ yrseduc2 + age + female + var, data = cps99_ps3)
summary(reg2)
Call:
lm(formula = log(ahe) ~ yrseduc2 + age + female + var, data = cps99_ps3)
Residuals:
Min 1Q Median 3Q Max
-2.37760 -0.28810 0.02876 0.32185 1.59381
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.1831860 0.0167710 70.55 <2e-16 ***
yrseduc2 0.2898395 0.0087553 33.10 <2e-16 ***
age 0.0074897 0.0002449 30.59 <2e-16 ***
female -0.2440905 0.0048827 -49.99 <2e-16 ***
var 0.1269925 0.0097665 13.00 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.469 on 37805 degrees of freedom
Multiple R-squared: 0.2385, Adjusted R-squared: 0.2384
F-statistic: 2960 on 4 and 37805 DF, p-value: < 2.2e-16
coef2 <- coeftest(reg2, vcov = vcovHC(reg2, type = "HC1"))
coef2
t test of coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.18318604 0.01655335 71.477 < 2.2e-16 ***
yrseduc2 0.28983953 0.00873426 33.184 < 2.2e-16 ***
age 0.00748968 0.00024823 30.172 < 2.2e-16 ***
female -0.24409049 0.00485128 -50.315 < 2.2e-16 ***
var 0.12699253 0.00978548 12.978 < 2.2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
confint(reg2, "yrseduc2", vcov = vcovHC(reg2, type = "HC1"))
2.5 % 97.5 %
yrseduc2 0.272679 0.3070001
So, we got that a 95% confidence interval for \(V\) is \((0.272679, 0.3070001)\)
cps99_ps3$age2 <- cps99_ps3$age * cps99_ps3$age
reg3 <- lm(log(ahe) ~ yrseduc + age + age2 + female + hsdipl, data = cps99_ps3)
summary(reg3)
Call:
lm(formula = log(ahe) ~ yrseduc + age + age2 + female + hsdipl,
data = cps99_ps3)
Residuals:
Min 1Q Median 3Q Max
-2.35868 -0.28283 0.03027 0.32107 1.57482
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 4.407e-01 4.345e-02 10.14 <2e-16 ***
yrseduc 8.102e-02 1.135e-03 71.38 <2e-16 ***
age 4.495e-02 2.039e-03 22.05 <2e-16 ***
age2 -4.410e-04 2.383e-05 -18.51 <2e-16 ***
female -2.447e-01 4.861e-03 -50.35 <2e-16 ***
hsdipl 1.224e-01 9.726e-03 12.59 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.4669 on 37804 degrees of freedom
Multiple R-squared: 0.2453, Adjusted R-squared: 0.2452
F-statistic: 2458 on 5 and 37804 DF, p-value: < 2.2e-16
coef3 <- coeftest(reg3, vcov = vcovHC(reg3, type = "HC1"))
coef3
t test of coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 4.4075e-01 4.3181e-02 10.207 < 2.2e-16 ***
yrseduc 8.1024e-02 1.1468e-03 70.651 < 2.2e-16 ***
age 4.4953e-02 2.0555e-03 21.870 < 2.2e-16 ***
age2 -4.4099e-04 2.4303e-05 -18.145 < 2.2e-16 ***
female -2.4473e-01 4.8329e-03 -50.639 < 2.2e-16 ***
hsdipl 1.2240e-01 9.7704e-03 12.528 < 2.2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
The signs of the coefficients on \(age\) and \(age^2\) are different: positive and negative, respectively. Thus, the income from age has a parabolic relationship. Since the coefficient on \(age^2\) is negative, it is a parabola with branches down. So, in the beginning, incomes grow with age, then the growth speed slows down. At a certain point of age the maximum income has been reached and after it the income begins to decrease.
As can be seen on the table, coefficient on \(age^2\) has t statistics equal to \(-18.145\), which is in absolute value more than 1.96. So, the hypothesis that the relation between \(ln(ahe)\) and \(age\) is rejected at the 5% significance level. Therefore, hypothesis that the relation between \(ln(ahe)\) and \(age\) is linear is rejected in preference to the hypothesis that it is quadratic.
As can be seen from the table, coefficient on \(female\) is \(-0.24473\), which is equal to \(24.473\)%. From the Task 1 we know that the coefficient on \(female\) is \(0.2241535\), which is equal to 24.415% and the difference between values is relatively small. The coefficient on \(age^2\) is significant, but adding \(age^2\) to the regression did not affect the gender gap in earnings (coefficient on \(female\)). Now we can look at the correlations:
corvar <- c("female","age","age2","yrseduc","hsdipl")
library(dplyr)
library(GGally)
corr <- cor(cps99_ps3[,corvar])
corr
female age age2 yrseduc hsdipl
female 1.00000000 0.020021667 0.01873234 0.027891188 0.058864765
age 0.02002167 1.000000000 0.99281365 -0.006251482 -0.009037531
age2 0.01873234 0.992813647 1.00000000 -0.010872308 -0.014092882
yrseduc 0.02789119 -0.006251482 -0.01087231 1.000000000 0.537810390
hsdipl 0.05886477 -0.009037531 -0.01409288 0.537810390 1.000000000
So, we can see that the correlation between \(age^2\) and \(female\) is really small and negligible. Thus, gender and age do not affect each other. That is why the addition to \(age^2\) in regression did not lead to changes in the gender income gap.
cps99_ps3$age3 <- cps99_ps3$age * cps99_ps3$age * cps99_ps3$age
reg4 <- lm(log(ahe) ~ yrseduc + age + age2 + age3 + female + hsdipl, data = cps99_ps3)
summary(reg4)
Call:
lm(formula = log(ahe) ~ yrseduc + age + age2 + age3 + female +
hsdipl, data = cps99_ps3)
Residuals:
Min 1Q Median 3Q Max
-2.35769 -0.28199 0.02949 0.32039 1.57338
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -3.043e-01 1.746e-01 -1.743 0.0814 .
yrseduc 8.115e-02 1.135e-03 71.485 < 2e-16 ***
age 1.007e-01 1.282e-02 7.854 4.12e-15 ***
age2 -1.780e-03 3.050e-04 -5.837 5.34e-09 ***
age3 1.033e-05 2.345e-06 4.405 1.06e-05 ***
female -2.442e-01 4.861e-03 -50.243 < 2e-16 ***
hsdipl 1.226e-01 9.724e-03 12.605 < 2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.4668 on 37803 degrees of freedom
Multiple R-squared: 0.2457, Adjusted R-squared: 0.2456
F-statistic: 2052 on 6 and 37803 DF, p-value: < 2.2e-16
As can seen from the table, coefficient on \(age^3\) has t statistics equals to $ 4.405$, which is in absolute value more than 1.96. It means that hypothesis that the relation between \(ln(ahe)\) and \(age\) is quadratic is rejected at the 5% significance level. Hence, hypothesis that the relation between \(ln(ahe)\) and \(age\) is quadratic is rejected in preference to the hypothesis that it is cubic.
library(car)
Loading required package: carData
Attaching package: ‘car’
The following object is masked from ‘package:dplyr’:
recode
The following object is masked from ‘package:psych’:
logit
hypothesis <- c("age2 = 0", "age3 = 0")
linearHypothesis(reg4, hypothesis, vcov = vcovHC(reg4, type = "HC1"))
Linear hypothesis test
Hypothesis:
age2 = 0
age3 = 0
Model 1: restricted model
Model 2: log(ahe) ~ yrseduc + age + age2 + age3 + female + hsdipl
Note: Coefficient covariance matrix supplied.
Res.Df Df F Pr(>F)
1 37805
2 37803 2 182.37 < 2.2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
As can been seen, F-statistic is \(182.37 > 1.96\). It means that the relationship between \(ln(ahe)\) and \(age\) is non-linear at the 5% significance level (hypothesis that the relation between \(ln(ahe)\) and \(age\) is linear is rejected at the 5% significance level).
Also, we can conclude that the cubic relation is preferable to the others.
lincoef <- coef1[3, 1]
quadcoef <- coef2[3, 1]
quad2coef <- coef2[4, 1]
cubcoef <- coef3[3, 1]
cub2coef <- coef3[4, 1]
cub3coef <- coef3[5, 1]
x11 <- lincoef * (31 - 30)
x21 <- quadcoef * (31 - 30) + quad2coef * (31^2 - 30^2)
x31 <- cubcoef * (31 - 30) + cub2coef * (31^2 - 30^2) + cub3coef * (31^3 - 30^3)
x12 <- lincoef * (46 - 45)
x22 <- quadcoef * (46 - 45) + quad2coef * (46^2 - 45^2)
x32 <- cubcoef * (46 - 45) + cub2coef * (46^2 - 45^2) + cub3coef *(46^3 - 45^3)
x13 <- lincoef * (61 - 60)
x23 <- quadcoef * (61 - 60) + quad2coef * (61^2 - 60^2)
x33 <- cubcoef * (61 - 60) + cub2coef * (61^2 - 60^2) + cub3coef * (61^3 - 60^3)
age_30<- c(x11, x21, x31)
age_45 <- c(x12, x22, x32)
age_60 <- c(x13, x23, x33)
per_age_30 <- age_30 * 100
per_age_45 <- age_45 * 100
per_age_60 <- age_60 * 100
table <-data.frame(per_age_30, per_age_45, per_age_60)
table