install.packages("devtools")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.4'
## (as 'lib' is unspecified)
install.packages("lmtest")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.4'
## (as 'lib' is unspecified)
install.packages("sandwich")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.4'
## (as 'lib' is unspecified)
library(devtools)
## Loading required package: usethis
library(lmtest)
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
library(sandwich)

devtools::install_github("JustinMShea/wooldridge")
## Skipping install of 'wooldridge' from a github remote, the SHA1 (44137328) has not changed since last install.
##   Use `force = TRUE` to force installation
library(wooldridge)

data("barium")

model_barium <- lm(log(chnimp) ~ log(chempi) + log(gas) + rtwex + befile6 + affile6 + afdec6 + t, data = barium)

summary(model_barium)
## 
## Call:
## lm(formula = log(chnimp) ~ log(chempi) + log(gas) + rtwex + befile6 + 
##     affile6 + afdec6 + t, data = barium)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.94173 -0.31037  0.03092  0.36435  1.21434 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)   
## (Intercept) -2.3972590 19.7847366  -0.121  0.90376   
## log(chempi) -0.6612071  1.2224820  -0.541  0.58957   
## log(gas)     0.4734524  0.8720272   0.543  0.58816   
## rtwex        0.0009682  0.0044441   0.218  0.82790   
## befile6      0.0878089  0.2507104   0.350  0.72676   
## affile6      0.0928429  0.2572680   0.361  0.71881   
## afdec6      -0.3619936  0.2907101  -1.245  0.21542   
## t            0.0126198  0.0037647   3.352  0.00107 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.5747 on 123 degrees of freedom
## Multiple R-squared:  0.3617, Adjusted R-squared:  0.3253 
## F-statistic: 9.956 on 7 and 123 DF,  p-value: 8.28e-10
model_barium_no_time <- lm(log(chnimp) ~ log(chempi) + log(gas) + rtwex + befile6 + affile6 + afdec6, data = barium)

# Perform the F-test comparing the two models
anova(model_barium, model_barium_no_time)
## Analysis of Variance Table
## 
## Model 1: log(chnimp) ~ log(chempi) + log(gas) + rtwex + befile6 + affile6 + 
##     afdec6 + t
## Model 2: log(chnimp) ~ log(chempi) + log(gas) + rtwex + befile6 + affile6 + 
##     afdec6
##   Res.Df    RSS Df Sum of Sq      F   Pr(>F)   
## 1    123 40.631                                
## 2    124 44.343 -1   -3.7119 11.237 0.001066 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
model_barium_with_monthly <- lm(log(chnimp) ~ log(chempi) + log(gas) + rtwex + befile6 + affile6 + afdec6 + 
                               feb + mar + apr + may + jun + jul + aug + sep + oct + nov + dec, data = barium)

# Display the summary of the model
summary(model_barium_with_monthly)
## 
## Call:
## lm(formula = log(chnimp) ~ log(chempi) + log(gas) + rtwex + befile6 + 
##     affile6 + afdec6 + feb + mar + apr + may + jun + jul + aug + 
##     sep + oct + nov + dec, data = barium)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.99351 -0.36138  0.08331  0.41404  1.38601 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 21.149449  30.949521   0.683   0.4958    
## log(chempi)  3.281504   0.491628   6.675 9.64e-10 ***
## log(gas)    -1.366322   1.369156  -0.998   0.3204    
## rtwex        0.006119   0.004508   1.357   0.1774    
## befile6      0.145300   0.266529   0.545   0.5867    
## affile6      0.015003   0.279437   0.054   0.9573    
## afdec6      -0.541856   0.311689  -1.738   0.0849 .  
## feb         -0.427149   0.303544  -1.407   0.1621    
## mar          0.058031   0.264883   0.219   0.8270    
## apr         -0.453006   0.268561  -1.687   0.0944 .  
## may          0.035040   0.269396   0.130   0.8967    
## jun         -0.204567   0.269413  -0.759   0.4492    
## jul          0.008259   0.278714   0.030   0.9764    
## aug         -0.152847   0.277969  -0.550   0.5835    
## sep         -0.135434   0.267967  -0.505   0.6143    
## oct          0.051164   0.267134   0.192   0.8485    
## nov         -0.244611   0.262969  -0.930   0.3543    
## dec          0.137690   0.271281   0.508   0.6128    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.6016 on 113 degrees of freedom
## Multiple R-squared:  0.3576, Adjusted R-squared:  0.2609 
## F-statistic:   3.7 on 17 and 113 DF,  p-value: 1.351e-05
# Perform an ANOVA to compare the models
anova(model_barium_no_time, model_barium_with_monthly)
## Analysis of Variance Table
## 
## Model 1: log(chnimp) ~ log(chempi) + log(gas) + rtwex + befile6 + affile6 + 
##     afdec6
## Model 2: log(chnimp) ~ log(chempi) + log(gas) + rtwex + befile6 + affile6 + 
##     afdec6 + feb + mar + apr + may + jun + jul + aug + sep + 
##     oct + nov + dec
##   Res.Df    RSS Df Sum of Sq      F Pr(>F)
## 1    124 44.343                           
## 2    113 40.892 11    3.4508 0.8669 0.5746
data("volat") 
# Fit the model for the Volat dataset
model_volat <- lm(rsp500 ~ pcip + i3, data = volat)

# Display the summary of the model
summary(model_volat)
## 
## 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
summary(model_volat)$coefficients
##                Estimate Std. Error    t value     Pr(>|t|)
## (Intercept) 18.84305624  3.2748802  5.7538154 1.444871e-08
## pcip         0.03641681  0.1293963  0.2814362 7.784810e-01
## i3          -1.36168867  0.5407244 -2.5182677 1.207402e-02