C2
# Load the dataset
library(wooldridge)
data("barium")
# (i)
barium$time_trend <- 1:nrow(barium)
model_i <- lm(lchnimp ~ time_trend + lgas + lrtwex + befile6 + affile6 + afdec6, data = barium)
summary(model_i)
##
## Call:
## lm(formula = lchnimp ~ time_trend + lgas + lrtwex + befile6 +
## affile6 + afdec6, data = barium)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.95492 -0.31483 0.02427 0.37757 1.27273
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -4.183264 20.464190 -0.204 0.838
## time_trend 0.010731 0.001426 7.526 9.32e-12 ***
## lgas 0.380149 0.860031 0.442 0.659
## lrtwex 0.209807 0.407138 0.515 0.607
## befile6 0.089842 0.250582 0.359 0.721
## affile6 0.076459 0.253909 0.301 0.764
## afdec6 -0.387672 0.274112 -1.414 0.160
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.5732 on 124 degrees of freedom
## Multiple R-squared: 0.36, Adjusted R-squared: 0.329
## F-statistic: 11.62 on 6 and 124 DF, p-value: 2.666e-10
# (ii)
model_restricted <- lm(lchnimp ~ time_trend, data = barium)
anova(model_restricted, model_i)
## Analysis of Variance Table
##
## Model 1: lchnimp ~ time_trend
## Model 2: lchnimp ~ time_trend + lgas + lrtwex + befile6 + affile6 + afdec6
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 129 41.709
## 2 124 40.739 5 0.96972 0.5903 0.7074
# (iii)
model_c9 <- lm(rsp500 ~ pcip + i3, data = volat)
summary(model_c9)
##
## Call:
## lm(formula = rsp500 ~ pcip + i3, data = volat)
##
## Residuals:
## Min 1Q Median 3Q Max
## -157.871 -22.580 2.103 25.524 138.137
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 18.84306 3.27488 5.754 1.44e-08 ***
## pcip 0.03642 0.12940 0.281 0.7785
## i3 -1.36169 0.54072 -2.518 0.0121 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 40.13 on 554 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.01189, Adjusted R-squared: 0.008325
## F-statistic: 3.334 on 2 and 554 DF, p-value: 0.03637
C9
# Load the necessary library and dataset
library(wooldridge)
data("volat")
# (i)
# Expected signs:
# - pcip: Positive (economic growth supports stock returns)
# - i3: Negative (higher risk-free rates reduce stock attractiveness)
# (ii)
model_c9 <- lm(rsp500 ~ pcip + i3, data = volat)
summary(model_c9)
##
## Call:
## lm(formula = rsp500 ~ pcip + i3, data = volat)
##
## Residuals:
## Min 1Q Median 3Q Max
## -157.871 -22.580 2.103 25.524 138.137
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 18.84306 3.27488 5.754 1.44e-08 ***
## pcip 0.03642 0.12940 0.281 0.7785
## i3 -1.36169 0.54072 -2.518 0.0121 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 40.13 on 554 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.01189, Adjusted R-squared: 0.008325
## F-statistic: 3.334 on 2 and 554 DF, p-value: 0.03637
# (iii)
# Extract p-values and identify significance
p_values <- summary(model_c9)$coefficients[, 4]
significant <- p_values < 0.05
# Output significance results
cat("P-values for each variable:\n")
## P-values for each variable:
print(p_values)
## (Intercept) pcip i3
## 1.444871e-08 7.784810e-01 1.207402e-02
cat("\nSignificance (TRUE = significant at 5% level):\n")
##
## Significance (TRUE = significant at 5% level):
print(significant)
## (Intercept) pcip i3
## TRUE FALSE TRUE
# (iv)
if (all(significant[-1] == FALSE)) {
cat("\nThe variables pcip and i3 are NOT statistically significant.\n")
cat("This suggests that the return on the S&P 500 is NOT predictable using these variables.\n")
} else {
cat("\nAt least one variable is statistically significant.\n")
cat("This suggests that the return on the S&P 500 shows SOME level of predictability.\n")
}
##
## At least one variable is statistically significant.
## This suggests that the return on the S&P 500 shows SOME level of predictability.