library(wooldridge)
#C2
data(barium)
str(barium)
## 'data.frame':    131 obs. of  31 variables:
##  $ chnimp  : num  220.5 94.8 219.4 317.4 114.6 ...
##  $ bchlimp : num  9578 11219 9720 12921 9790 ...
##  $ befile6 : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ affile6 : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ afdec6  : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ befile12: int  0 0 0 0 0 0 0 0 0 0 ...
##  $ affile12: int  0 0 0 0 0 0 0 0 0 0 ...
##  $ afdec12 : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ chempi  : num  100 101 101 102 104 ...
##  $ gas     : num  7.83e+09 8.82e+09 8.45e+09 9.24e+09 9.15e+09 ...
##  $ rtwex   : num  86.7 85.6 85.4 87.3 86.6 ...
##  $ spr     : int  0 1 1 1 0 0 0 0 0 0 ...
##  $ sum     : int  0 0 0 0 1 1 1 0 0 0 ...
##  $ fall    : int  0 0 0 0 0 0 0 1 1 1 ...
##  $ lchnimp : num  5.4 4.55 5.39 5.76 4.74 ...
##  $ lgas    : num  22.8 22.9 22.9 22.9 22.9 ...
##  $ lrtwex  : num  4.46 4.45 4.45 4.47 4.46 ...
##  $ lchempi : num  4.61 4.61 4.62 4.63 4.65 ...
##  $ t       : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ feb     : int  1 0 0 0 0 0 0 0 0 0 ...
##  $ mar     : int  0 1 0 0 0 0 0 0 0 0 ...
##  $ apr     : int  0 0 1 0 0 0 0 0 0 0 ...
##  $ may     : int  0 0 0 1 0 0 0 0 0 0 ...
##  $ jun     : int  0 0 0 0 1 0 0 0 0 0 ...
##  $ jul     : int  0 0 0 0 0 1 0 0 0 0 ...
##  $ aug     : int  0 0 0 0 0 0 1 0 0 0 ...
##  $ sep     : int  0 0 0 0 0 0 0 1 0 0 ...
##  $ oct     : int  0 0 0 0 0 0 0 0 1 0 ...
##  $ nov     : int  0 0 0 0 0 0 0 0 0 1 ...
##  $ dec     : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ percchn : num  2.302 0.845 2.257 2.457 1.171 ...
##  - attr(*, "time.stamp")= chr "25 Jun 2011 23:03"
barium$month <- rep(1:12, length.out = nrow(barium))
barium$month <- as.factor(barium$month)
#(i)
barium$time_trend <- 1:nrow(barium)
model_c2_1 <- lm(chnimp ~ gas + chempi + time_trend, data = barium)
summary(model_c2_1)
## 
## Call:
## lm(formula = chnimp ~ gas + chempi + time_trend, data = barium)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -451.59 -200.59  -49.09  153.81  943.43 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  5.827e+01  4.659e+02   0.125 0.900673    
## gas          6.686e-08  5.008e-08   1.335 0.184194    
## chempi      -3.739e+00  4.334e+00  -0.863 0.389901    
## time_trend   6.373e+00  1.589e+00   4.012 0.000102 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 291.1 on 127 degrees of freedom
## Multiple R-squared:  0.3225, Adjusted R-squared:  0.3065 
## F-statistic: 20.15 on 3 and 127 DF,  p-value: 9.564e-11
#The time trend is statistically significant (p=0.000102), showing a clear upward trend in chemical imports over time. Other variables (gas and chempi) are not statistically significant.
#(ii)
model_restricted <- lm(chnimp ~ time_trend, data = barium)
model_full <- lm(chnimp ~ gas + chempi + time_trend, data = barium)
anova(model_restricted, model_full)
## Analysis of Variance Table
## 
## Model 1: chnimp ~ time_trend
## Model 2: chnimp ~ gas + chempi + time_trend
##   Res.Df      RSS Df Sum of Sq      F Pr(>F)
## 1    129 10921259                           
## 2    127 10761080  2    160179 0.9452 0.3913
#F-statistic is 0.9452 with a p-value of 0.3913.This indicates that gas and chempi are not jointly significant in explaining chemical imports when the time trend is already included.
#(iii)
barium$month <- factor(barium$month) 
model_with_dummies <- lm(chnimp ~ gas + chempi + time_trend + month, data = barium)
summary(model_with_dummies)
## 
## Call:
## lm(formula = chnimp ~ gas + chempi + time_trend + month, data = barium)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -457.63 -224.10  -37.47  174.18  900.84 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.681e+02  4.984e+02   0.337 0.736475    
## gas          3.188e-08  7.134e-08   0.447 0.655782    
## chempi      -2.544e+00  4.744e+00  -0.536 0.592803    
## time_trend   5.942e+00  1.727e+00   3.441 0.000808 ***
## month2       1.590e+02  1.349e+02   1.179 0.240904    
## month3      -1.106e+02  1.323e+02  -0.837 0.404586    
## month4       1.184e+02  1.478e+02   0.801 0.424670    
## month5       1.632e+01  1.463e+02   0.112 0.911363    
## month6       9.568e+01  1.575e+02   0.608 0.544603    
## month7       3.189e+01  1.557e+02   0.205 0.838075    
## month8       1.582e+02  1.394e+02   1.134 0.259004    
## month9       1.395e+02  1.411e+02   0.989 0.324782    
## month10      6.595e-01  1.419e+02   0.005 0.996299    
## month11      1.070e+02  1.572e+02   0.680 0.497571    
## month12      1.272e+02  1.434e+02   0.887 0.376879    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 293.4 on 116 degrees of freedom
## Multiple R-squared:  0.3715, Adjusted R-squared:  0.2956 
## F-statistic: 4.897 on 14 and 116 DF,  p-value: 4.738e-07
#None of the monthly dummy variables are statistically significant (p>0.05), meaning there is no evidence of seasonality in chemical imports.The inclusion of monthly dummies didn't significantly change the coefficients or standard errors of other variables like gas, chempi, or time_trend.Only slightly improved the model’s fit (R^2 increased from 0.3065 to 0.3715), showing that monthly effects add minimal explanatory power.

#C9
data(volat)
str(volat)
## 'data.frame':    558 obs. of  17 variables:
##  $ date  : num  1947 1947 1947 1947 1947 ...
##  $ sp500 : num  15.2 15.8 15.2 14.6 14.3 ...
##  $ divyld: num  4.49 4.38 4.61 4.75 5.05 ...
##  $ i3    : num  0.38 0.38 0.38 0.38 0.38 ...
##  $ ip    : num  22.4 22.5 22.6 22.5 22.6 ...
##  $ pcsp  : num  NA 46.5 -48.6 -44.3 -21.4 ...
##  $ rsp500: num  NA 50.9 -44 -39.6 -16.3 ...
##  $ pcip  : num  NA 5.36 5.33 -5.31 5.33 ...
##  $ ci3   : num  NA 0 0 0 0 ...
##  $ ci3_1 : num  NA NA 0 0 0 ...
##  $ ci3_2 : num  NA NA NA 0 0 ...
##  $ pcip_1: num  NA NA 5.36 5.33 -5.31 ...
##  $ pcip_2: num  NA NA NA 5.36 5.33 ...
##  $ pcip_3: num  NA NA NA NA 5.36 ...
##  $ pcsp_1: num  NA NA 46.5 -48.6 -44.3 ...
##  $ pcsp_2: num  NA NA NA 46.5 -48.6 ...
##  $ pcsp_3: num  NA NA NA NA 46.5 ...
##  - attr(*, "time.stamp")= chr "25 Jun 2011 23:03"
#(i)β₁ (pcip): Likely positive, as higher industrial production typically boosts stock market returns.β₂ (i3): Likely negative, since higher T-bill returns could make equities less attractive.
#(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
#18.84306 — the average S&P 500 return when both pcip and i3 are 0.pcip (β₁): The coefficient (0.03642) is very small and not significant (p = 0.7785). This suggests that industrial production growth does not strongly influence S&P 500 returns in this model.i3 (β₂): The coefficient (-1.36169) is statistically significant (p = 0.0121), implying that a 1% increase in T-bill returns reduces S&P 500 returns by approximately 1.36 percentage points.
#(iii) pcip: Not statistically significant (p = 0.7785). Changes in industrial production do not significantly impact S&P 500 returns in this model. i3: Statistically significant (p = 0.0121). Changes in T-bill returns have a meaningful impact on S&P 500 returns.
#(iv) The F-statistic (3.334, p = 0.03637) suggests the model is significant at the 5% level, meaning that the independent variables jointly explain some variation in rsp500.However, the R-squared is very low (0.01189), meaning the model explains only about 1.2% of the variation in S&P 500 returns. This indicates the predictability is weak.
#T-bill returns (i3): The negative and significant coefficient implies that short-term interest rates can help predict S&P 500 returns to some extent. Industrial production growth (pcip): This variable does not significantly predict S&P 500 returns in this model.