library(wooldridge)
packageVersion("wooldridge")
## [1] '1.4.3'
data("vote1")
head(vote1)
##   state district democA voteA expendA expendB prtystrA lexpendA lexpendB
## 1    AL        7      1    68 328.296   8.737       41 5.793916 2.167567
## 2    AK        1      0    62 626.377 402.477       60 6.439952 5.997638
## 3    AZ        2      1    73  99.607   3.065       55 4.601233 1.120048
## 4    AZ        3      0    69 319.690  26.281       64 5.767352 3.268846
## 5    AR        3      0    75 159.221  60.054       66 5.070293 4.095244
## 6    AR        4      1    69 570.155  21.393       46 6.345908 3.063064
##     shareA
## 1 97.40767
## 2 60.88104
## 3 97.01476
## 4 92.40370
## 5 72.61247
## 6 96.38355
#(i)
model <- lm(voteA ~ prtystrA + expendA + expendB + I(expendA * expendB), data = vote1)
summary(model)
## 
## Call:
## lm(formula = voteA ~ prtystrA + expendA + expendB + I(expendA * 
##     expendB), data = vote1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -28.9999  -8.7632  -0.1726   8.2310  29.7325 
## 
## Coefficients:
##                        Estimate Std. Error t value Pr(>|t|)    
## (Intercept)           3.212e+01  4.591e+00   6.995 5.99e-11 ***
## prtystrA              3.419e-01  8.799e-02   3.886 0.000146 ***
## expendA               3.828e-02  4.960e-03   7.718 1.00e-12 ***
## expendB              -3.172e-02  4.588e-03  -6.915 9.32e-11 ***
## I(expendA * expendB) -6.629e-06  7.186e-06  -0.923 0.357584    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 11.13 on 168 degrees of freedom
## Multiple R-squared:  0.5708, Adjusted R-squared:  0.5606 
## F-statistic: 55.86 on 4 and 168 DF,  p-value: < 2.2e-16
#(ii)p-value is above 0.05. So, the interaction term is not statistically significant

#(iii)
mean_expendA <- mean(vote1$expendA, na.rm = TRUE)
mean_expendA
## [1] 310.611
effect_increase_expendB <- coef(model)["expendB"] + coef(model)["I(expendA * expendB)"] * 300
effect_increase_expendB
##     expendB 
## -0.03371269
#it is not that large 

#(iv)
effect_increase_expendA <- coef(model)["expendA"] + coef(model)["I(expendA * expendB)"] * 100
effect_increase_expendA
##    expendA 
## 0.03761799
#no

#(v)
vote1$shareA <- vote1$expendA / (vote1$expendA + vote1$expendB)
model_shareA <- lm(voteA ~ prtystrA + expendA + expendB + shareA, data = vote1)
summary(model_shareA)
## 
## Call:
## lm(formula = voteA ~ prtystrA + expendA + expendB + shareA, data = vote1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -15.5859  -3.3764  -0.3036   3.2095  31.5656 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 18.195374   2.567856   7.086 3.63e-11 ***
## prtystrA     0.157272   0.049685   3.165  0.00184 ** 
## expendA     -0.006670   0.002833  -2.354  0.01971 *  
## expendB      0.004267   0.002607   1.637  0.10351    
## shareA      49.439436   2.530859  19.535  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6.167 on 168 degrees of freedom
## Multiple R-squared:  0.8681, Adjusted R-squared:  0.865 
## F-statistic: 276.5 on 4 and 168 DF,  p-value: < 2.2e-16
#yes

#(vi)
partial_effect_expendB <- coef(model)["expendB"] + coef(model)["I(expendA * expendB)"] * 300
partial_effect_expendB
##     expendB 
## -0.03371269