Question 1:
# Load the wooldridge library
library(wooldridge)
# Load the WAGE2 dataset
data("wage2")
# View the first few rows of the dataset to check the variables
head(wage2)
## wage hours IQ KWW educ exper tenure age married black south urban sibs
## 1 769 40 93 35 12 11 2 31 1 0 0 1 1
## 2 808 50 119 41 18 11 16 37 1 0 0 1 1
## 3 825 40 108 46 14 11 9 33 1 0 0 1 1
## 4 650 40 96 32 12 13 7 32 1 0 0 1 4
## 5 562 40 74 27 11 14 5 34 1 0 0 1 10
## 6 1400 40 116 43 16 14 2 35 1 1 0 1 1
## brthord meduc feduc lwage
## 1 2 8 8 6.645091
## 2 NA 14 14 6.694562
## 3 2 14 14 6.715384
## 4 3 12 12 6.476973
## 5 6 6 11 6.331502
## 6 2 8 NA 7.244227
##(I)
# Simple regression of IQ on education
model_iq_educ <- lm(IQ ~ educ, data = wage2)
# Display summary to get the slope coefficient
summary(model_iq_educ)
##
## Call:
## lm(formula = IQ ~ educ, data = wage2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -50.228 -7.262 0.907 8.772 37.373
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 53.6872 2.6229 20.47 <2e-16 ***
## educ 3.5338 0.1922 18.39 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 12.9 on 933 degrees of freedom
## Multiple R-squared: 0.2659, Adjusted R-squared: 0.2652
## F-statistic: 338 on 1 and 933 DF, p-value: < 2.2e-16
# Extract the slope coefficient (delta_1)
# This extracts the coefficient for "educ", which is the slope
delta_1 <- coef(model_iq_educ)["educ"]
delta_1
## educ
## 3.533829
Question 2:
##(II)
# Simple regression of log(wage) on education
model_logwage_educ <- lm(log(wage) ~ educ, data = wage2)
# Display the regression output to verify it works
summary(model_logwage_educ)
##
## Call:
## lm(formula = log(wage) ~ educ, data = wage2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.94620 -0.24832 0.03507 0.27440 1.28106
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 5.973062 0.081374 73.40 <2e-16 ***
## educ 0.059839 0.005963 10.04 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.4003 on 933 degrees of freedom
## Multiple R-squared: 0.09742, Adjusted R-squared: 0.09645
## F-statistic: 100.7 on 1 and 933 DF, p-value: < 2.2e-16
# Extract the slope coefficient (beta_1)
beta_1 <- coef(model_logwage_educ)["educ"]
beta_1 # This should now display the slope coefficient
## educ
## 0.05983921
Question 3:
# Load the wooldridge library
library(wooldridge)
# Load the wage2 dataset
data("wage2")
# Multiple regression of log(wage) on education and IQ
model_logwage_educ_iq <- lm(log(wage) ~ educ + IQ, data = wage2)
# Display the regression summary
summary(model_logwage_educ_iq)
##
## Call:
## lm(formula = log(wage) ~ educ + IQ, data = wage2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.01601 -0.24367 0.03359 0.27960 1.23783
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 5.6582876 0.0962408 58.793 < 2e-16 ***
## educ 0.0391199 0.0068382 5.721 1.43e-08 ***
## IQ 0.0058631 0.0009979 5.875 5.87e-09 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.3933 on 932 degrees of freedom
## Multiple R-squared: 0.1297, Adjusted R-squared: 0.1278
## F-statistic: 69.42 on 2 and 932 DF, p-value: < 2.2e-16
# Extract the slope coefficients (beta_1 for educ and beta_2 for IQ)
beta_1_multi <- coef(model_logwage_educ_iq)["educ"]
beta_2 <- coef(model_logwage_educ_iq)["IQ"]
# Print the slope coefficients
beta_1_multi
## educ
## 0.0391199
beta_2
## IQ
## 0.005863132
Question 4
# Calculate beta_1 from the right-hand side: beta_1_multi + beta_2 * delta_1
beta_1_rhs <- beta_1_multi + beta_2 * delta_1
# Compare it with the beta_1 from simple regression (question ii)
beta_1_rhs
## educ
## 0.05983921
beta_1 # From the simple regression
## educ
## 0.05983921