install.packages("wooldridge")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.3'
## (as 'lib' is unspecified)
library(wooldridge)
data("barium")
head(barium,10)
##      chnimp   bchlimp befile6 affile6 afdec6 befile12 affile12 afdec12 chempi
## 1  220.4620  9578.376       0       0      0        0        0       0  100.1
## 2   94.7980 11219.480       0       0      0        0        0       0  100.9
## 3  219.3575  9719.900       0       0      0        0        0       0  101.1
## 4  317.4215 12920.950       0       0      0        0        0       0  102.5
## 5  114.6390  9790.446       0       0      0        0        0       0  104.1
## 6  129.5240 11020.470       0       0      0        0        0       0  104.8
## 7  110.0920  8302.168       0       0      0        0        0       0  104.7
## 8   39.6830  9583.325       0       0      0        0        0       0  105.8
## 9  262.8230  9880.729       0       0      0        0        0       0  106.8
## 10 173.9980  9003.923       0       0      0        0        0       0  107.7
##           gas rtwex spr sum fall  lchnimp     lgas   lrtwex  lchempi  t feb mar
## 1  7830000128 86.74   0   0    0 5.395725 22.78123 4.462915 4.606170  1   1   0
## 2  8819999744 85.63   1   0    0 4.551748 22.90029 4.450036 4.614130  2   0   1
## 3  8449999872 85.42   1   0    0 5.390703 22.85743 4.447580 4.616110  3   0   0
## 4  9240000512 87.29   1   0    0 5.760231 22.94681 4.469236 4.629863  4   0   0
## 5  9150000128 86.60   0   1    0 4.741788 22.93702 4.461300 4.645352  5   0   0
## 6  9520000000 84.63   0   1    0 4.863866 22.97666 4.438289 4.652054  6   0   0
## 7  9770000384 82.57   0   1    0 4.701316 23.00258 4.413646 4.651099  7   0   0
## 8  9379999744 82.33   0   0    1 3.680923 22.96185 4.410736 4.661551  8   0   0
## 9  9390000128 79.45   0   0    1 5.571481 22.96291 4.375128 4.670958  9   0   0
## 10 9610000384 82.24   0   0    1 5.159044 22.98607 4.409642 4.679349 10   0   0
##    apr may jun jul aug sep oct nov dec   percchn
## 1    0   0   0   0   0   0   0   0   0 2.3016636
## 2    0   0   0   0   0   0   0   0   0 0.8449411
## 3    1   0   0   0   0   0   0   0   0 2.2567875
## 4    0   1   0   0   0   0   0   0   0 2.4566422
## 5    0   0   1   0   0   0   0   0   0 1.1709272
## 6    0   0   0   1   0   0   0   0   0 1.1753038
## 7    0   0   0   0   1   0   0   0   0 1.3260633
## 8    0   0   0   0   0   1   0   0   0 0.4140838
## 9    0   0   0   0   0   0   1   0   0 2.6599557
## 10   0   0   0   0   0   0   0   1   0 1.9324688
#i. The coefficient is statistically significant at the 5% level. So, only Irtwex is a significant variable. The P-value of Irtwex is 0.0154, which is lower than 0.05.
attach(barium)
model1<- lm(log(chnimp)~ log(chempi)+log(gas)+log(rtwex)+befile6+ affile6 +afdec6)
a <-summary(model1)
a
## 
## Call:
## lm(formula = log(chnimp) ~ log(chempi) + log(gas) + log(rtwex) + 
##     befile6 + affile6 + afdec6)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.03356 -0.39080  0.03048  0.40248  1.51720 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -17.80277   21.04537  -0.846   0.3992    
## log(chempi)   3.11719    0.47920   6.505 1.72e-09 ***
## log(gas)      0.19634    0.90662   0.217   0.8289    
## log(rtwex)    0.98302    0.40015   2.457   0.0154 *  
## befile6       0.05957    0.26097   0.228   0.8198    
## affile6      -0.03241    0.26430  -0.123   0.9026    
## afdec6       -0.56524    0.28584  -1.978   0.0502 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.5974 on 124 degrees of freedom
## Multiple R-squared:  0.3049, Adjusted R-squared:  0.2712 
## F-statistic: 9.064 on 6 and 124 DF,  p-value: 3.255e-08
#ii. 
model_2 <- lm(log(chnimp)~ log(chempi)+log(gas)+log(rtwex)+befile6+affile6+afdec6, data= barium)
summary(model_2)
## 
## Call:
## lm(formula = log(chnimp) ~ log(chempi) + log(gas) + log(rtwex) + 
##     befile6 + affile6 + afdec6, data = barium)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.03356 -0.39080  0.03048  0.40248  1.51720 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -17.80277   21.04537  -0.846   0.3992    
## log(chempi)   3.11719    0.47920   6.505 1.72e-09 ***
## log(gas)      0.19634    0.90662   0.217   0.8289    
## log(rtwex)    0.98302    0.40015   2.457   0.0154 *  
## befile6       0.05957    0.26097   0.228   0.8198    
## affile6      -0.03241    0.26430  -0.123   0.9026    
## afdec6       -0.56524    0.28584  -1.978   0.0502 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.5974 on 124 degrees of freedom
## Multiple R-squared:  0.3049, Adjusted R-squared:  0.2712 
## F-statistic: 9.064 on 6 and 124 DF,  p-value: 3.255e-08
#iii. adding monthly variables
model_3 <- lm(log(chnimp)~ log(chempi)+log(gas)+log(rtwex)+befile6+affile6+afdec6+feb+mar+apr+may+jun+jul+aug+sep+oct+nov+dec, data= barium)
summary(model_3)
## 
## Call:
## lm(formula = log(chnimp) ~ log(chempi) + log(gas) + log(rtwex) + 
##     befile6 + affile6 + afdec6 + feb + mar + apr + may + jun + 
##     jul + aug + sep + oct + nov + dec, data = barium)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.98535 -0.36207  0.07366  0.41786  1.37734 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 16.779215  32.428645   0.517   0.6059    
## log(chempi)  3.265062   0.492930   6.624 1.24e-09 ***
## log(gas)    -1.278140   1.389008  -0.920   0.3594    
## log(rtwex)   0.663045   0.471304   1.407   0.1622    
## befile6      0.139703   0.266808   0.524   0.6016    
## affile6      0.012632   0.278687   0.045   0.9639    
## afdec6      -0.521300   0.301950  -1.726   0.0870 .  
## feb         -0.417711   0.304444  -1.372   0.1728    
## mar          0.059052   0.264731   0.223   0.8239    
## apr         -0.451483   0.268386  -1.682   0.0953 .  
## may          0.033309   0.269242   0.124   0.9018    
## jun         -0.206332   0.269252  -0.766   0.4451    
## jul          0.003837   0.278767   0.014   0.9890    
## aug         -0.157064   0.277993  -0.565   0.5732    
## sep         -0.134161   0.267656  -0.501   0.6172    
## oct          0.051693   0.266851   0.194   0.8467    
## nov         -0.246260   0.262827  -0.937   0.3508    
## dec          0.132838   0.271423   0.489   0.6255    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.6012 on 113 degrees of freedom
## Multiple R-squared:  0.3583, Adjusted R-squared:  0.2618 
## F-statistic: 3.712 on 17 and 113 DF,  p-value: 1.282e-05