Final Project - Technical Appendix

- by Johannes Ferstad, Brendan Hsu and Brenton Arnaboldi

Initializing packages, configuration, and loading data

require(mosaic)
require(repmis)
require(plm)
options(digits = 3)
trellis.par.set(theme = col.mosaic())
All <- repmis::source_DropboxData("CombinedStatesTEMP2.csv", "t7zov3jawubw9nq", 
    sep = ",", header = TRUE)

Function for testing for serial correlation in residuals.

This function returns the result of an OLS regression with each residuals as a response variables paired with the previous residual as the predictor. We will conclude that there is no significant serial correlation in the residuals if the p-value, from the t-test done with the null hypothesis that beta1=0, is greater than 0.10.

SCtest = function(model, periods) {
    res = model$res
    n = length(res)
    summary(lm(res[-n] ~ res[-1]))
}

Function for getting fitted values from plm models

This function is used for the residuals vs fitted plots.

fitted <- function(object, ...) object$model[[1]] - object$residuals

Using PRECIPcm and TMEANcm as quantitative predictors

\( TotalSTD_{ month,year,county }\quad =\quad \frac { TotalRetailSales_{ month,year,county }-\overline { TotalRetailSales_{ county } } }{ SD_{ TotalRetailSales_{ county } } } \)

\( { PRECIPcm }_{month, year, county }\quad=\quad {PRECIP}_{month, year, county}\quad - \quad \overline { PRECIP_{month,county} } \)

\( {TMEANcm }_{month, year, county }\quad=\quad {TMEAN}_{month, year, county}\quad - \quad \overline { TMEAN_{month,county} } \)

We start our analysis hoping to find significant relationships between centered TMEAN and PRECIP values and standardized retail sales. A summary of the results we considered are included in the output below.

## Setting up data
pdata = plm.data(All, index = c("County.Area", "t"))

## No time or county/area dummies
m1a = plm(TotalSTD ~ TMEANcm, data = pdata)
summary(m1a)  # nonsig
## Oneway (individual) effect Within Model
## 
## Call:
## plm(formula = TotalSTD ~ TMEANcm, data = pdata)
## 
## Balanced Panel: n=15, T=96, N=1440
## 
## Residuals :
##    Min. 1st Qu.  Median 3rd Qu.    Max. 
##  -2.750  -0.719  -0.098   0.559   3.800 
## 
## Coefficients :
##         Estimate Std. Error t-value Pr(>|t|)
## TMEANcm  0.00781    0.00948    0.82     0.41
## 
## Total Sum of Squares:    1300
## Residual Sum of Squares: 1300
## R-Squared      :  4.59e-06 
##       Adj. R-Squared :  4.54e-06 
## F-statistic: 0.678594 on 1 and 1424 DF, p-value: 0.41
SCtest(m1a)  # sig serial correlation!
## 
## Call:
## lm(formula = res[-n] ~ res[-1])
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -2.995 -0.575 -0.124  0.482  3.648 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 0.000476   0.022742    0.02     0.98    
## res[-1]     0.420953   0.023929   17.59   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.863 on 1437 degrees of freedom
## Multiple R-squared:  0.177,  Adjusted R-squared:  0.177 
## F-statistic:  309 on 1 and 1437 DF,  p-value: <2e-16

m2a = plm(TotalSTD ~ PRECIPcm, data = pdata)
summary(m2a)  # nonsig
## Oneway (individual) effect Within Model
## 
## Call:
## plm(formula = TotalSTD ~ PRECIPcm, data = pdata)
## 
## Balanced Panel: n=15, T=96, N=1440
## 
## Residuals :
##    Min. 1st Qu.  Median 3rd Qu.    Max. 
## -2.7600 -0.7160 -0.0966  0.5530  3.7800 
## 
## Coefficients :
##          Estimate Std. Error t-value Pr(>|t|)
## PRECIPcm  -0.0103     0.0101   -1.02     0.31
## 
## Total Sum of Squares:    1300
## Residual Sum of Squares: 1300
## R-Squared      :  1.09e-05 
##       Adj. R-Squared :  1.07e-05 
## F-statistic: 1.04607 on 1 and 1424 DF, p-value: 0.307
SCtest(m2a)  # sig serial correlation!
## 
## Call:
## lm(formula = res[-n] ~ res[-1])
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -3.051 -0.572 -0.115  0.471  3.638 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.00048    0.02274    0.02     0.98    
## res[-1]      0.42100    0.02393   17.59   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.863 on 1437 degrees of freedom
## Multiple R-squared:  0.177,  Adjusted R-squared:  0.177 
## F-statistic:  310 on 1 and 1437 DF,  p-value: <2e-16

m3a = plm(TotalSTD ~ PRECIPcm + TMEANcm, data = pdata)
summary(m3a)  # nonsig
## Oneway (individual) effect Within Model
## 
## Call:
## plm(formula = TotalSTD ~ PRECIPcm + TMEANcm, data = pdata)
## 
## Balanced Panel: n=15, T=96, N=1440
## 
## Residuals :
##    Min. 1st Qu.  Median 3rd Qu.    Max. 
##  -2.760  -0.718  -0.103   0.559   3.790 
## 
## Coefficients :
##          Estimate Std. Error t-value Pr(>|t|)
## PRECIPcm -0.00964    0.01013   -0.95     0.34
## TMEANcm   0.00699    0.00952    0.73     0.46
## 
## Total Sum of Squares:    1300
## Residual Sum of Squares: 1300
## R-Squared      :  2.47e-05 
##       Adj. R-Squared :  2.44e-05 
## F-statistic: 0.792406 on 2 and 1423 DF, p-value: 0.453
SCtest(m3a)  # sig serial correlation!
## 
## Call:
## lm(formula = res[-n] ~ res[-1])
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -3.048 -0.573 -0.122  0.477  3.645 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 0.000476   0.022736    0.02     0.98    
## res[-1]     0.420830   0.023930   17.59   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.862 on 1437 degrees of freedom
## Multiple R-squared:  0.177,  Adjusted R-squared:  0.177 
## F-statistic:  309 on 1 and 1437 DF,  p-value: <2e-16

The results above show that there are no significant relationships between PRECIPcm and TMEANcm values and standardized retail sales. We are also faced with the problem of serially correlated residuals. The p-values from our tests for serial correlation (SCtest) are all <2e-16 indicating that the residuals are highly auto-correlated. We deal with this issue of non-independence in the errors by including lags in our models.

## With lags to account for serial correlation
m1b = plm(TotalSTD ~ TMEANcm + lag(TotalSTD, 1) + lag(TotalSTD, 2) + lag(TotalSTD, 
    3), data = pdata)
summary(m1b)  #nonsig
## Oneway (individual) effect Within Model
## 
## Call:
## plm(formula = TotalSTD ~ TMEANcm + lag(TotalSTD, 1) + lag(TotalSTD, 
##     2) + lag(TotalSTD, 3), data = pdata)
## 
## Balanced Panel: n=15, T=93, N=1395
## 
## Residuals :
##    Min. 1st Qu.  Median 3rd Qu.    Max. 
## -3.0600 -0.5040 -0.0968  0.4090  3.5500 
## 
## Coefficients :
##                  Estimate Std. Error t-value Pr(>|t|)    
## TMEANcm           0.00380    0.00832    0.46    0.647    
## lag(TotalSTD, 1)  0.31154    0.02601   11.98   <2e-16 ***
## lag(TotalSTD, 2)  0.04847    0.02726    1.78    0.076 .  
## lag(TotalSTD, 3)  0.25618    0.02590    9.89   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    1250
## Residual Sum of Squares: 948
## R-Squared      :  0.191 
##       Adj. R-Squared :  0.188 
## F-statistic: 108.708 on 4 and 1376 DF, p-value: <2e-16
SCtest(m1b)  # no sig serial correlation!
## 
## Call:
## lm(formula = res[-n] ~ res[-1])
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -3.101 -0.505 -0.102  0.400  3.567 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept) 6.62e-05   2.21e-02    0.00      1.0
## res[-1]     2.77e-02   2.68e-02    1.03      0.3
## 
## Residual standard error: 0.825 on 1392 degrees of freedom
## Multiple R-squared:  0.000768,   Adjusted R-squared:  4.99e-05 
## F-statistic: 1.07 on 1 and 1392 DF,  p-value: 0.301

m2b = plm(TotalSTD ~ PRECIPcm + lag(TotalSTD, 1) + lag(TotalSTD, 2) + lag(TotalSTD, 
    3), data = pdata)
summary(m2b)  #nonsig
## Oneway (individual) effect Within Model
## 
## Call:
## plm(formula = TotalSTD ~ PRECIPcm + lag(TotalSTD, 1) + lag(TotalSTD, 
##     2) + lag(TotalSTD, 3), data = pdata)
## 
## Balanced Panel: n=15, T=93, N=1395
## 
## Residuals :
##    Min. 1st Qu.  Median 3rd Qu.    Max. 
##  -3.070  -0.505  -0.100   0.411   3.540 
## 
## Coefficients :
##                  Estimate Std. Error t-value Pr(>|t|)    
## PRECIPcm         -0.00767    0.00898   -0.85     0.39    
## lag(TotalSTD, 1)  0.31173    0.02598   12.00   <2e-16 ***
## lag(TotalSTD, 2)  0.04767    0.02723    1.75     0.08 .  
## lag(TotalSTD, 3)  0.25695    0.02588    9.93   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    1250
## Residual Sum of Squares: 947
## R-Squared      :  0.191 
##       Adj. R-Squared :  0.188 
## F-statistic: 108.879 on 4 and 1376 DF, p-value: <2e-16
SCtest(m2b)  # no sig serial correlation!
## 
## Call:
## lm(formula = res[-n] ~ res[-1])
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -3.111 -0.510 -0.103  0.392  3.555 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept) 7.67e-05   2.21e-02    0.00      1.0
## res[-1]     2.79e-02   2.68e-02    1.04      0.3
## 
## Residual standard error: 0.825 on 1392 degrees of freedom
## Multiple R-squared:  0.000779,   Adjusted R-squared:  6.15e-05 
## F-statistic: 1.09 on 1 and 1392 DF,  p-value: 0.298

m3b = plm(TotalSTD ~ PRECIPcm + TMEANcm + lag(TotalSTD, 1) + lag(TotalSTD, 2) + 
    lag(TotalSTD, 3), data = pdata)
summary(m3b)  #nonsig
## Oneway (individual) effect Within Model
## 
## Call:
## plm(formula = TotalSTD ~ PRECIPcm + TMEANcm + lag(TotalSTD, 1) + 
##     lag(TotalSTD, 2) + lag(TotalSTD, 3), data = pdata)
## 
## Balanced Panel: n=15, T=93, N=1395
## 
## Residuals :
##    Min. 1st Qu.  Median 3rd Qu.    Max. 
## -3.0700 -0.5040 -0.0991  0.4070  3.5400 
## 
## Coefficients :
##                  Estimate Std. Error t-value Pr(>|t|)    
## PRECIPcm         -0.00737    0.00902   -0.82    0.414    
## TMEANcm           0.00320    0.00835    0.38    0.702    
## lag(TotalSTD, 1)  0.31131    0.02602   11.97   <2e-16 ***
## lag(TotalSTD, 2)  0.04810    0.02727    1.76    0.078 .  
## lag(TotalSTD, 3)  0.25654    0.02591    9.90   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    1250
## Residual Sum of Squares: 947
## R-Squared      :  0.191 
##       Adj. R-Squared :  0.188 
## F-statistic: 87.0785 on 5 and 1375 DF, p-value: <2e-16
SCtest(m3b)  # no sig serial correlation!
## 
## Call:
## lm(formula = res[-n] ~ res[-1])
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -3.112 -0.507 -0.105  0.394  3.558 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept) 7.26e-05   2.21e-02    0.00      1.0
## res[-1]     2.80e-02   2.68e-02    1.04      0.3
## 
## Residual standard error: 0.825 on 1392 degrees of freedom
## Multiple R-squared:  0.000783,   Adjusted R-squared:  6.48e-05 
## F-statistic: 1.09 on 1 and 1392 DF,  p-value: 0.297

Adding three lagged response terms makes our test for serial correlation return large p-values, indicating that there is no significant serial correlation in the residuals. We are still not finding any significant relationships between our quantitative predictors and standardized retail sales. Now, we include dummies for the time period to account for any trends over time that affect retail sales across all the counties. We also include county dummies to account for any differences in standardized mean sales between counties. These could be necessary because sales were standardized by county using all the data we collected, but we are only using the part of the data in which all counties overlap for our models. For example, we collected data for the counties in Florida going all the way back to 2000, but we are only using data starting in June 2004 for our models.

## Adding county and time dummies
m1c = plm(TotalSTD ~ TMEANcm + lag(TotalSTD, 1) + lag(TotalSTD, 2) + lag(TotalSTD, 
    3), data = pdata, model = "within", effect = "twoways")
summary(m1c)  #nonsig
## Twoways effects Within Model
## 
## Call:
## plm(formula = TotalSTD ~ TMEANcm + lag(TotalSTD, 1) + lag(TotalSTD, 
##     2) + lag(TotalSTD, 3), data = pdata, effect = "twoways", 
##     model = "within")
## 
## Balanced Panel: n=15, T=93, N=1395
## 
## Residuals :
##    Min. 1st Qu.  Median 3rd Qu.    Max. 
## -2.9800 -0.3600 -0.0242  0.3550  3.1800 
## 
## Coefficients :
##                  Estimate Std. Error t-value Pr(>|t|)    
## TMEANcm          -0.00455    0.00924   -0.49   0.6220    
## lag(TotalSTD, 1)  0.48975    0.02775   17.65   <2e-16 ***
## lag(TotalSTD, 2)  0.07158    0.03079    2.32   0.0203 *  
## lag(TotalSTD, 3)  0.08145    0.02761    2.95   0.0032 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    787
## Residual Sum of Squares: 520
## R-Squared      :  0.112 
##       Adj. R-Squared :  0.103 
## F-statistic: 164.582 on 4 and 1284 DF, p-value: <2e-16
SCtest(m1c)  # no sig serial correlation!
## 
## Call:
## lm(formula = res[-n] ~ res[-1])
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -2.994 -0.358 -0.022  0.356  3.202 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.000176   0.016374    0.01     0.99
## res[-1]     0.008761   0.026801    0.33     0.74
## 
## Residual standard error: 0.611 on 1392 degrees of freedom
## Multiple R-squared:  7.68e-05,   Adjusted R-squared:  -0.000642 
## F-statistic: 0.107 on 1 and 1392 DF,  p-value: 0.744

m2c = plm(TotalSTD ~ PRECIPcm + lag(TotalSTD, 1) + lag(TotalSTD, 2) + lag(TotalSTD, 
    3), data = pdata, model = "within", effect = "twoways")
summary(m2c)  #nonsig
## Twoways effects Within Model
## 
## Call:
## plm(formula = TotalSTD ~ PRECIPcm + lag(TotalSTD, 1) + lag(TotalSTD, 
##     2) + lag(TotalSTD, 3), data = pdata, effect = "twoways", 
##     model = "within")
## 
## Balanced Panel: n=15, T=93, N=1395
## 
## Residuals :
##    Min. 1st Qu.  Median 3rd Qu.    Max. 
## -2.9800 -0.3590 -0.0227  0.3550  3.1700 
## 
## Coefficients :
##                  Estimate Std. Error t-value Pr(>|t|)    
## PRECIPcm         -0.00319    0.00801   -0.40   0.6906    
## lag(TotalSTD, 1)  0.48948    0.02775   17.64   <2e-16 ***
## lag(TotalSTD, 2)  0.07197    0.03079    2.34   0.0196 *  
## lag(TotalSTD, 3)  0.08097    0.02760    2.93   0.0034 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    787
## Residual Sum of Squares: 520
## R-Squared      :  0.112 
##       Adj. R-Squared :  0.103 
## F-statistic: 164.55 on 4 and 1284 DF, p-value: <2e-16
SCtest(m2c)  # no sig serial correlation!
## 
## Call:
## lm(formula = res[-n] ~ res[-1])
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -2.995 -0.361 -0.026  0.353  3.197 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.000178   0.016375    0.01     0.99
## res[-1]     0.009160   0.026801    0.34     0.73
## 
## Residual standard error: 0.611 on 1392 degrees of freedom
## Multiple R-squared:  8.39e-05,   Adjusted R-squared:  -0.000634 
## F-statistic: 0.117 on 1 and 1392 DF,  p-value: 0.733

m3c = plm(TotalSTD ~ PRECIPcm + TMEANcm + lag(TotalSTD, 1) + lag(TotalSTD, 2) + 
    lag(TotalSTD, 3), data = pdata, model = "within", effect = "twoways")
summary(m3c)  #nonsig
## Twoways effects Within Model
## 
## Call:
## plm(formula = TotalSTD ~ PRECIPcm + TMEANcm + lag(TotalSTD, 1) + 
##     lag(TotalSTD, 2) + lag(TotalSTD, 3), data = pdata, effect = "twoways", 
##     model = "within")
## 
## Balanced Panel: n=15, T=93, N=1395
## 
## Residuals :
##    Min. 1st Qu.  Median 3rd Qu.    Max. 
## -2.9800 -0.3580 -0.0227  0.3550  3.1800 
## 
## Coefficients :
##                  Estimate Std. Error t-value Pr(>|t|)    
## PRECIPcm         -0.00337    0.00802   -0.42   0.6744    
## TMEANcm          -0.00473    0.00925   -0.51   0.6094    
## lag(TotalSTD, 1)  0.48962    0.02776   17.64   <2e-16 ***
## lag(TotalSTD, 2)  0.07161    0.03080    2.32   0.0202 *  
## lag(TotalSTD, 3)  0.08142    0.02762    2.95   0.0033 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    787
## Residual Sum of Squares: 520
## R-Squared      :  0.112 
##       Adj. R-Squared :  0.103 
## F-statistic: 131.617 on 5 and 1283 DF, p-value: <2e-16
SCtest(m3c)  # no sig serial correlation!
## 
## Call:
## lm(formula = res[-n] ~ res[-1])
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -2.999 -0.357 -0.023  0.355  3.202 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.000183   0.016373    0.01     0.99
## res[-1]     0.008979   0.026801    0.34     0.74
## 
## Residual standard error: 0.611 on 1392 degrees of freedom
## Multiple R-squared:  8.06e-05,   Adjusted R-squared:  -0.000638 
## F-statistic: 0.112 on 1 and 1392 DF,  p-value: 0.738

At this point, we have dealt with the serial correlation issue, but we have not found any significant relationships between TMEANcm, PRECIPcm and TotalSTD. Believing that there are nonlinearities in the effects of temperature and precipitation deviances from the norm, we create levels capturing the extreme deviances in temperature and precipitation.

We create three different sets of levels.

1st set) The first kind sorts observations into 5 different TMEAN and PRECIP levels. The most extreme 1% of TMEANcm and PRECIPcm values on either side of the spectrum (+/-) go into four categories: “Drought”, “Soaked”, “Freezing” and “Hot”. The next 5% (1-6th percentile, 94-99th percentile) inwards from each side of the spectrum go into four other categories: “Dry”, “Wet”, “Cold” and “Warm”. The rest of the values are put into categories named “Normal”. The extremes here are calculated relative to the entire data set. So the cutoffs are the same for all the observations. The cutoffs are:

PRECIPlevels (values refer to PRECIPcm) Drought: <=-4.73, Dry:(-4.73,-3.14], Normal: (-3.14,4.38], Wet: (4.3794,8.0644], Soaked: >8.0644

TMEANlevels (values refer to TMEANcm) Freezing: <=-7.52, Cold: (-7.5205,-3.9915], Normal: (-3.9915,3.8974], Warm: (3.8974,6.2111], Hot: >6.2111

2nd set) These levels are identical in number and names, but the extreme values are picked relative to each county. This ensures that each county has the same number of observations in each level. The effects from results with these levels measure the effect of abnormal level relative to the county's normal weather. The cutoffs for these levels vary for each county and can be found in the code further below.

3rd set) Here, only the 5% most extreme observations on each side of the spectrum are put in categories named “Dry”, “Wet”, “Cold”, “Warm”. The extreme values are identified by county, so that each county has the same number of observations in each level. The cutoffs can be found in the code further below.

Hopefully, these levels will prove useful in explaining retail sales.

The code below creates all three sets of levels and sets Normal as the reference level for each set. The code also returns the number of observations in each level by county and year.

Creating 1st set of levels for PRECIPcm and TMEANcm

## 5% and 1% cutoffs (for entire sample)

All$PRECIPlevels = cut(All$PRECIPcm, breaks = c(-10, -4.7344, -3.1439, 4.3794, 
    8.0644, 15), labels = c("Drought", "Dry", "Normal", "Wet", "Soaked"))
tally(~All$PRECIPlevels)
## 
## Drought     Dry  Normal     Wet  Soaked 
##      15      72    1266      71      16

All$TMEANlevels = cut(All$TMEANcm, breaks = c(-16, -7.5205, -3.9915, 3.8974, 
    6.2111, 16), labels = c("Freezing", "Cold", "Normal", "Warm", "Hot"))
tally(~All$TMEANlevels)
## 
## Freezing     Cold   Normal     Warm      Hot 
##       15       72     1266       71       16

## Setting ref levels to Normal
All = within(All, PRECIPlevels <- relevel(PRECIPlevels, ref = "Normal"))
All = within(All, TMEANlevels <- relevel(TMEANlevels, ref = "Normal"))

## Validating choice of levels
table(All$PRECIPlevels, All$County.Area)
##          
##           Bar Harbor Camden Carteret Durham Duval (Jacksonville)
##   Normal          85     84       83     92                   87
##   Drought          0      0        0      0                    0
##   Dry              4      6        7      3                    3
##   Wet              6      4        6      1                    6
##   Soaked           1      2        0      0                    0
##          
##           Leon (Tallahassee) Lewiston LewistonSub Miami-Dade
##   Normal                  81       88          88         83
##   Drought                  2        0           0          4
##   Dry                      6        2           2          4
##   Wet                      7        6           6          4
##   Soaked                   0        0           0          1
##          
##           Orange (Orlando) Pinellas (Tampa) Portland PortlandSub St. Lucie
##   Normal                78               77       88          88        75
##   Drought                4                5        0           0         0
##   Dry                    8                4        3           3        12
##   Wet                    3                6        4           4         6
##   Soaked                 3                4        1           1         3
##          
##           Stanly
##   Normal      89
##   Drought      0
##   Dry          5
##   Wet          2
##   Soaked       0
table(All$PRECIPlevels, All$Year)
##          
##           2004 2005 2006 2007 2008 2009 2010 2011 2012
##   Normal    91  153  157  161  149  157  158  169   71
##   Drought    0    1    2    3    1    3    3    2    0
##   Dry        8    6   12   13   11    7   10    5    0
##   Wet        5   15    8    3   17   12    7    1    3
##   Soaked     1    5    1    0    2    1    2    3    1
table(All$TMEANlevels, All$County.Area)
##           
##            Bar Harbor Camden Carteret Durham Duval (Jacksonville)
##   Normal           84     81       86     82                   88
##   Freezing          0      1        1      1                    1
##   Cold              6      5        4      6                    3
##   Warm              5      8        4      6                    4
##   Hot               1      1        1      1                    0
##           
##            Leon (Tallahassee) Lewiston LewistonSub Miami-Dade
##   Normal                   84       84          84         89
##   Freezing                  2        0           0          1
##   Cold                      5        6           6          3
##   Warm                      4        3           3          3
##   Hot                       1        3           3          0
##           
##            Orange (Orlando) Pinellas (Tampa) Portland PortlandSub
##   Normal                 86               80       84          84
##   Freezing                2                3        0           0
##   Cold                    4                6        5           5
##   Warm                    4                7        5           5
##   Hot                     0                0        2           2
##           
##            St. Lucie Stanly
##   Normal          87     83
##   Freezing         2      1
##   Cold             3      5
##   Warm             4      6
##   Hot              0      1
table(All$TMEANlevels, All$Year)
##           
##            2004 2005 2006 2007 2008 2009 2010 2011 2012
##   Normal    100  158  156  153  172  161  137  174   55
##   Freezing    2    0    0    0    0    0   13    0    0
##   Cold        3   16    0   12    5   18   18    0    0
##   Warm        0    6   19   15    3    1   10    6   11
##   Hot         0    0    5    0    0    0    2    0    9
# Drought, Hot not present in all counties, but Dry is.

Creating 2nd set of levels for PRECIPcm and TMEANcm (1% and 5% extremes by county/area)


# Creating vars
All$PRECIPlevels2 = 0
All$TMEANlevels2 = 0

# Portland
All$PRECIPlevels2[which(All$County.Area == "Portland")] = cut(All$PRECIPcm[which(All$County.Area == 
    "Portland")], breaks = c(-10, -3.9519, -3.0658, 3.81, 7.55883, 15))

All$TMEANlevels2[which(All$County.Area == "Portland")] = cut(All$TMEANcm[which(All$County.Area == 
    "Portland")], breaks = c(-10, -5.7539, -3.6967, 4.1489, 6.6561, 15))

# PortlandSub (same weather data)
All$PRECIPlevels2[which(All$County.Area == "PortlandSub")] = cut(All$PRECIPcm[which(All$County.Area == 
    "PortlandSub")], breaks = c(-10, -3.9519, -3.0658, 3.81, 7.55883, 15))

All$TMEANlevels2[which(All$County.Area == "PortlandSub")] = cut(All$TMEANcm[which(All$County.Area == 
    "PortlandSub")], breaks = c(-10, -5.7539, -3.6967, 4.1489, 6.6561, 15))

# Lewiston and LewistonSub (same weather data)
All$PRECIPlevels2[which(All$County.Area == "Lewiston")] = cut(All$PRECIPcm[which(All$County.Area == 
    "Lewiston")], breaks = c(-10, -3.46783, -2.71689, 4.19856, 5.46544, 15))
All$PRECIPlevels2[which(All$County.Area == "LewistonSub")] = cut(All$PRECIPcm[which(All$County.Area == 
    "LewistonSub")], breaks = c(-10, -3.46783, -2.71689, 4.19856, 5.46544, 15))

All$TMEANlevels2[which(All$County.Area == "Lewiston")] = cut(All$TMEANcm[which(All$County.Area == 
    "Lewiston")], breaks = c(-10, -6.0478, -4.0333, 3.9033, 6.3506, 15))
All$TMEANlevels2[which(All$County.Area == "LewistonSub")] = cut(All$TMEANcm[which(All$County.Area == 
    "LewistonSub")], breaks = c(-10, -6.0478, -4.0333, 3.9033, 6.3506, 15))

# Bar Harbor
All$PRECIPlevels2[which(All$County.Area == "Bar Harbor")] = cut(All$PRECIPcm[which(All$County.Area == 
    "Bar Harbor")], breaks = c(-10, -4.0833, -2.8396, 5.1377, 7.7882, 15))

All$TMEANlevels2[which(All$County.Area == "Bar Harbor")] = cut(All$TMEANcm[which(All$County.Area == 
    "Bar Harbor")], breaks = c(-10, -6.2483, -3.95, 3.8189, 6.0672, 15))

# Duval (JacksonVille)
All$PRECIPlevels2[which(All$County.Area == "Duval (Jacksonville)")] = cut(All$PRECIPcm[which(All$County.Area == 
    "Duval (Jacksonville)")], breaks = c(-10, -3.42162, -2.59946, 4.47885, 5.16262, 
    15))

All$TMEANlevels2[which(All$County.Area == "Duval (Jacksonville)")] = cut(All$TMEANcm[which(All$County.Area == 
    "Duval (Jacksonville)")], breaks = c(-10, -6.69115, -3.62538, 3.72462, 5.20577, 
    15))

# Leon (Tallahassee)
All$PRECIPlevels2[which(All$County.Area == "Leon (Tallahassee)")] = cut(All$PRECIPcm[which(All$County.Area == 
    "Leon (Tallahassee)")], breaks = c(-10, -5.69608, -3.55415, 4.83869, 7.15823, 
    15))

All$TMEANlevels2[which(All$County.Area == "Leon (Tallahassee)")] = cut(All$TMEANcm[which(All$County.Area == 
    "Leon (Tallahassee)")], breaks = c(-10, -7.715, -4.2969, 3.7023, 5.6785, 
    15))

# Miami-Dade
All$PRECIPlevels2[which(All$County.Area == "Miami-Dade")] = cut(All$PRECIPcm[which(All$County.Area == 
    "Miami-Dade")], breaks = c(-10, -6.1063, -3.9016, 4.2288, 7.3182, 15))

All$TMEANlevels2[which(All$County.Area == "Miami-Dade")] = cut(All$TMEANcm[which(All$County.Area == 
    "Miami-Dade")], breaks = c(-10, -7.025, -2.93538, 2.96615, 4.68462, 15))

# Orange (Orlando)
All$PRECIPlevels2[which(All$County.Area == "Orange (Orlando)")] = cut(All$PRECIPcm[which(All$County.Area == 
    "Orange (Orlando)")], breaks = c(-10, -5.5777, -4.3725, 3.9824, 8.4885, 
    15))

All$TMEANlevels2[which(All$County.Area == "Orange (Orlando)")] = cut(All$TMEANcm[which(All$County.Area == 
    "Orange (Orlando)")], breaks = c(-12, -8.92846, -3.35231, 3.74154, 5.22615, 
    15))

# Pinellas (Tampa)
All$PRECIPlevels2[which(All$County.Area == "Pinellas (Tampa)")] = cut(All$PRECIPcm[which(All$County.Area == 
    "Pinellas (Tampa)")], breaks = c(-10, -6.33723, -4.04415, 5.60123, 9.34685, 
    15))

All$TMEANlevels2[which(All$County.Area == "Pinellas (Tampa)")] = cut(All$TMEANcm[which(All$County.Area == 
    "Pinellas (Tampa)")], breaks = c(-13, -10.0758, -5.6477, 4.1985, 5.0307, 
    15))

# St. Lucie
All$PRECIPlevels2[which(All$County.Area == "St. Lucie")] = cut(All$PRECIPcm[which(All$County.Area == 
    "St. Lucie")], breaks = c(-10, -4.0457, -3.6762, 5.2545, 10.7417, 15))

All$TMEANlevels2[which(All$County.Area == "St. Lucie")] = cut(All$TMEANcm[which(All$County.Area == 
    "St. Lucie")], breaks = c(-13, -8.4985, -3.3123, 3.6946, 5.5019, 15))

# Camden
All$PRECIPlevels2[which(All$County.Area == "Camden")] = cut(All$PRECIPcm[which(All$County.Area == 
    "Camden")], breaks = c(-10, -4.18125, -3.119, 4.2515, 9.225625, 15))

All$TMEANlevels2[which(All$County.Area == "Camden")] = cut(All$TMEANcm[which(All$County.Area == 
    "Camden")], breaks = c(-13, -5.9762, -4.1075, 4.4825, 5.5881, 15))

# Carteret
All$PRECIPlevels2[which(All$County.Area == "Carteret")] = cut(All$PRECIPcm[which(All$County.Area == 
    "Carteret")], breaks = c(-10, -4.0611, -3.2685, 4.2176, 6.3827, 15))

All$TMEANlevels2[which(All$County.Area == "Carteret")] = cut(All$TMEANcm[which(All$County.Area == 
    "Carteret")], breaks = c(-13, -5.9775, -3.77375, 3.81, 5.19625, 15))

# Durham
All$PRECIPlevels2[which(All$County.Area == "Durham")] = cut(All$PRECIPcm[which(All$County.Area == 
    "Durham")], breaks = c(-10, -3.2124, -2.69, 3.159, 3.8225, 15))

All$TMEANlevels2[which(All$County.Area == "Durham")] = cut(All$TMEANcm[which(All$County.Area == 
    "Durham")], breaks = c(-13, -6.0894, -4.0912, 3.9838, 5.8219, 15))

# Stanly
All$PRECIPlevels2[which(All$County.Area == "Stanly")] = cut(All$PRECIPcm[which(All$County.Area == 
    "Stanly")], breaks = c(-10, -3.4751, -2.629, 3.1653, 4.7032, 15))

All$TMEANlevels2[which(All$County.Area == "Stanly")] = cut(All$TMEANcm[which(All$County.Area == 
    "Stanly")], breaks = c(-13, -6.5425, -3.81, 4.1825, 5.5981, 15))

## Setting up factors and setting reference levels to Normal
All$PRECIPlevels2.f <- factor(All$PRECIPlevels2, labels = c("Drought", "Dry", 
    "Normal", "Wet", "Soaked"))
All$TMEANlevels2.f <- factor(All$TMEANlevels2, labels = c("Freezing", "Cold", 
    "Normal", "Warm", "Hot"))

All = within(All, PRECIPlevels2.f <- relevel(PRECIPlevels2.f, ref = "Normal"))
All = within(All, TMEANlevels2.f <- relevel(TMEANlevels2.f, ref = "Normal"))

## Validating choice of levels
table(All$PRECIPlevels2, All$County.Area)
##    
##     Bar Harbor Camden Carteret Durham Duval (Jacksonville)
##   1          1      1        1      1                    1
##   2          5      5        5      5                    5
##   3         84     84       84     84                   84
##   4          5      5        5      5                    5
##   5          1      1        1      1                    1
##    
##     Leon (Tallahassee) Lewiston LewistonSub Miami-Dade Orange (Orlando)
##   1                  1        1           1          1                1
##   2                  5        5           5          5                5
##   3                 84       84          84         84               84
##   4                  5        5           5          5                5
##   5                  1        1           1          1                1
##    
##     Pinellas (Tampa) Portland PortlandSub St. Lucie Stanly
##   1                1        1           1         1      1
##   2                5        5           5         5      5
##   3               84       84          84        84     84
##   4                5        5           5         5      5
##   5                1        1           1         1      1
table(All$PRECIPlevels2, All$Year)
##    
##     2004 2005 2006 2007 2008 2009 2010 2011 2012
##   1    5    0    1    5    2    0    1    1    0
##   2    7    7   13   11   13    8   11    5    0
##   3   87  154  152  159  145  160  161  170   72
##   4    5   11   14    5   18   11    6    3    2
##   5    1    8    0    0    2    1    1    1    1
table(All$TMEANlevels2, All$County.Area)
##    
##     Bar Harbor Camden Carteret Durham Duval (Jacksonville)
##   1          1      1        1      1                    1
##   2          5      5        5      5                    5
##   3         84     84       84     84                   84
##   4          5      5        5      5                    5
##   5          1      1        1      1                    1
##    
##     Leon (Tallahassee) Lewiston LewistonSub Miami-Dade Orange (Orlando)
##   1                  1        1           1          1                1
##   2                  5        5           5          5                5
##   3                 84       84          84         84               84
##   4                  5        5           5          5                5
##   5                  1        1           1          1                1
##    
##     Pinellas (Tampa) Portland PortlandSub St. Lucie Stanly
##   1                1        1           1         1      1
##   2                5        5           5         5      5
##   3               84       84          84        84     84
##   4                4        5           5         5      5
##   5                2        1           1         1      1
table(All$TMEANlevels2, All$Year)
##    
##     2004 2005 2006 2007 2008 2009 2010 2011 2012
##   1    1    1    0    4    0    0    9    0    0
##   2    3   16    1    7    5   20   23    0    0
##   3  101  157  156  151  171  159  136  175   54
##   4    0    6   14   17    4    1   12    5   15
##   5    0    0    9    1    0    0    0    0    6

Creating 3rd set of levels for PRECIPcm and TMEANcm (5% extremes by county)


# Creating vars
All$PRECIPlevels3 = 0
All$TMEANlevels3 = 0

# Portland
All$PRECIPlevels3[which(All$County.Area == "Portland")] = cut(All$PRECIPcm[which(All$County.Area == 
    "Portland")], breaks = c(-15, -3.1147, 4.0239, 15))

All$TMEANlevels3[which(All$County.Area == "Portland")] = cut(All$TMEANcm[which(All$County.Area == 
    "Portland")], breaks = c(-10, -3.8694, 4.5583, 15))

# PortlandSub (same weather data)
All$PRECIPlevels3[which(All$County.Area == "PortlandSub")] = cut(All$PRECIPcm[which(All$County.Area == 
    "PortlandSub")], breaks = c(-15, -3.1147, 4.0239, 15))

All$TMEANlevels3[which(All$County.Area == "PortlandSub")] = cut(All$TMEANcm[which(All$County.Area == 
    "PortlandSub")], breaks = c(-10, -3.8694, 4.5583, 15))

# Lewiston and LewistonSub
All$PRECIPlevels3[which(All$County.Area == "Lewiston")] = cut(All$PRECIPcm[which(All$County.Area == 
    "Lewiston")], breaks = c(-10, -2.85861, 4.56056, 15))
All$PRECIPlevels3[which(All$County.Area == "LewistonSub")] = cut(All$PRECIPcm[which(All$County.Area == 
    "LewistonSub")], breaks = c(-10, -2.85861, 4.56056, 15))

All$TMEANlevels3[which(All$County.Area == "Lewiston")] = cut(All$TMEANcm[which(All$County.Area == 
    "Lewiston")], breaks = c(-10, -4.3556, 4.2944, 10))
All$TMEANlevels3[which(All$County.Area == "LewistonSub")] = cut(All$TMEANcm[which(All$County.Area == 
    "LewistonSub")], breaks = c(-10, -4.3556, 4.2944, 10))

# Bar Harbor
All$PRECIPlevels3[which(All$County.Area == "Bar Harbor")] = cut(All$PRECIPcm[which(All$County.Area == 
    "Bar Harbor")], breaks = c(-10, -2.8842, 5.8397, 10))

All$TMEANlevels3[which(All$County.Area == "Bar Harbor")] = cut(All$TMEANcm[which(All$County.Area == 
    "Bar Harbor")], breaks = c(-10, -4.1722, 4.0083, 15))

# Duval (JacksonVille)
All$PRECIPlevels3[which(All$County.Area == "Duval (Jacksonville)")] = cut(All$PRECIPcm[which(All$County.Area == 
    "Duval (Jacksonville)")], breaks = c(-10, -2.65731, 4.73346, 15))

All$TMEANlevels3[which(All$County.Area == "Duval (Jacksonville)")] = cut(All$TMEANcm[which(All$County.Area == 
    "Duval (Jacksonville)")], breaks = c(-10, -3.64615, 3.82308, 15))

# Leon (Tallahassee)
All$PRECIPlevels3[which(All$County.Area == "Leon (Tallahassee)")] = cut(All$PRECIPcm[which(All$County.Area == 
    "Leon (Tallahassee)")], breaks = c(-10, -3.58019, 5.00423, 15))

All$TMEANlevels3[which(All$County.Area == "Leon (Tallahassee)")] = cut(All$TMEANcm[which(All$County.Area == 
    "Leon (Tallahassee)")], breaks = c(-10, -4.4904, 3.8904, 15))

# Miami-Dade
All$PRECIPlevels3[which(All$County.Area == "Miami-Dade")] = cut(All$PRECIPcm[which(All$County.Area == 
    "Miami-Dade")], breaks = c(-10, -4.1977, 4.5087, 15))

All$TMEANlevels3[which(All$County.Area == "Miami-Dade")] = cut(All$TMEANcm[which(All$County.Area == 
    "Miami-Dade")], breaks = c(-10, -3.18269, 3.16538, 15))

# Orange (Orlando)
All$PRECIPlevels3[which(All$County.Area == "Orange (Orlando)")] = cut(All$PRECIPcm[which(All$County.Area == 
    "Orange (Orlando)")], breaks = c(-10, -4.635, 4.7181, 15))

All$TMEANlevels3[which(All$County.Area == "Orange (Orlando)")] = cut(All$TMEANcm[which(All$County.Area == 
    "Orange (Orlando)")], breaks = c(-12, -4.23269, 3.80962, 15))

# Pinellas (Tampa)
All$PRECIPlevels3[which(All$County.Area == "Pinellas (Tampa)")] = cut(All$PRECIPcm[which(All$County.Area == 
    "Pinellas (Tampa)")], breaks = c(-10, -4.57846, 5.84192, 15))

All$TMEANlevels3[which(All$County.Area == "Pinellas (Tampa)")] = cut(All$TMEANcm[which(All$County.Area == 
    "Pinellas (Tampa)")], breaks = c(-13, -5.9962, 4.2481, 15))

# St. Lucie
All$PRECIPlevels3[which(All$County.Area == "St. Lucie")] = cut(All$PRECIPcm[which(All$County.Area == 
    "St. Lucie")], breaks = c(-10, -3.701, 5.87, 15))

All$TMEANlevels3[which(All$County.Area == "St. Lucie")] = cut(All$TMEANcm[which(All$County.Area == 
    "St. Lucie")], breaks = c(-13, -3.8558, 3.7231, 15))

# Camden
All$PRECIPlevels3[which(All$County.Area == "Camden")] = cut(All$PRECIPcm[which(All$County.Area == 
    "Camden")], breaks = c(-10, -3.181875, 4.595937, 15))

All$TMEANlevels3[which(All$County.Area == "Camden")] = cut(All$TMEANcm[which(All$County.Area == 
    "Camden")], breaks = c(-13, -4.7781, 4.8125, 15))

# Carteret
All$PRECIPlevels3[which(All$County.Area == "Carteret")] = cut(All$PRECIPcm[which(All$County.Area == 
    "Carteret")], breaks = c(-10, -3.4453, 4.6322, 15))

All$TMEANlevels3[which(All$County.Area == "Carteret")] = cut(All$TMEANcm[which(All$County.Area == 
    "Carteret")], breaks = c(-13, -4.00313, 3.8875, 15))

# Durham
All$PRECIPlevels3[which(All$County.Area == "Durham")] = cut(All$PRECIPcm[which(All$County.Area == 
    "Durham")], breaks = c(-10, -2.7678, 3.2997, 15))

All$TMEANlevels3[which(All$County.Area == "Durham")] = cut(All$TMEANcm[which(All$County.Area == 
    "Durham")], breaks = c(-13, -4.25, 4.1875, 15))

# Stanly
All$PRECIPlevels3[which(All$County.Area == "Stanly")] = cut(All$PRECIPcm[which(All$County.Area == 
    "Stanly")], breaks = c(-10, -3.0006, 3.3247, 15))

All$TMEANlevels3[which(All$County.Area == "Stanly")] = cut(All$TMEANcm[which(All$County.Area == 
    "Stanly")], breaks = c(-13, -4.0719, 4.2969, 15))

## Setting up factors and setting reference levels to Normal
All$PRECIPlevels3.f <- factor(All$PRECIPlevels3, labels = c("Dry", "Normal", 
    "Wet"))
All$TMEANlevels3.f <- factor(All$TMEANlevels3, labels = c("Cold", "Normal", 
    "Warm"))
All = within(All, PRECIPlevels3.f <- relevel(PRECIPlevels3.f, ref = "Normal"))
All = within(All, TMEANlevels3.f <- relevel(TMEANlevels3.f, ref = "Normal"))

## Validating choice of levels
table(All$PRECIPlevels3.f, All$County.Area)
##         
##          Bar Harbor Camden Carteret Durham Duval (Jacksonville)
##   Normal         86     86       86     86                   86
##   Dry             5      5        5      5                    5
##   Wet             5      5        5      5                    5
##         
##          Leon (Tallahassee) Lewiston LewistonSub Miami-Dade
##   Normal                 86       86          86         86
##   Dry                     5        5           5          5
##   Wet                     5        5           5          5
##         
##          Orange (Orlando) Pinellas (Tampa) Portland PortlandSub St. Lucie
##   Normal               86               86       86          86        86
##   Dry                   5                5        5           5         5
##   Wet                   5                5        5           5         5
##         
##          Stanly
##   Normal     86
##   Dry         5
##   Wet         5
table(All$PRECIPlevels3.f, All$Year)
##         
##          2004 2005 2006 2007 2008 2009 2010 2011 2012
##   Normal   89  157  161  164  151  163  161  171   73
##   Dry      11    6    9   13   13    6   12    5    0
##   Wet       5   17   10    3   16   11    7    4    2
table(All$TMEANlevels3.f, All$County.Area)
##         
##          Bar Harbor Camden Carteret Durham Duval (Jacksonville)
##   Normal         86     86       86     86                   86
##   Cold            5      5        5      5                    5
##   Warm            5      5        5      5                    5
##         
##          Leon (Tallahassee) Lewiston LewistonSub Miami-Dade
##   Normal                 86       86          86         86
##   Cold                    5        5           5          5
##   Warm                    5        5           5          5
##         
##          Orange (Orlando) Pinellas (Tampa) Portland PortlandSub St. Lucie
##   Normal               86               86       86          86        86
##   Cold                  5                5        5           5         5
##   Warm                  5                5        5           5         5
##         
##          Stanly
##   Normal     86
##   Cold        5
##   Warm        5
table(All$TMEANlevels3.f, All$Year)
##         
##          2004 2005 2006 2007 2008 2009 2010 2011 2012
##   Normal  102  161  159  158  171  164  137  178   60
##   Cold      3   13    0    7    5   16   31    0    0
##   Warm      0    6   21   15    4    0   12    2   15

Results using 1st set of levels

## Setting up data again
pdata = plm.data(All, index = c("County.Area", "t"))

## No county or time dummies
m1d = plm(TotalSTD ~ TMEANlevels + lag(TotalSTD, 1) + lag(TotalSTD, 2) + lag(TotalSTD, 
    3), data = pdata)
summary(m1d)  #sig hot
## Oneway (individual) effect Within Model
## 
## Call:
## plm(formula = TotalSTD ~ TMEANlevels + lag(TotalSTD, 1) + lag(TotalSTD, 
##     2) + lag(TotalSTD, 3), data = pdata)
## 
## Balanced Panel: n=15, T=93, N=1395
## 
## Residuals :
##    Min. 1st Qu.  Median 3rd Qu.    Max. 
## -3.0600 -0.5010 -0.0966  0.4210  3.5400 
## 
## Coefficients :
##                     Estimate Std. Error t-value Pr(>|t|)    
## TMEANlevelsFreezing  -0.3527     0.2167   -1.63   0.1039    
## TMEANlevelsCold      -0.0548     0.1022   -0.54   0.5921    
## TMEANlevelsWarm       0.1115     0.1015    1.10   0.2720    
## TMEANlevelsHot       -0.5805     0.2103   -2.76   0.0059 ** 
## lag(TotalSTD, 1)      0.3117     0.0260   11.98   <2e-16 ***
## lag(TotalSTD, 2)      0.0396     0.0273    1.45   0.1471    
## lag(TotalSTD, 3)      0.2611     0.0259   10.08   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    1250
## Residual Sum of Squares: 940
## R-Squared      :  0.197 
##       Adj. R-Squared :  0.194 
## F-statistic: 64.184 on 7 and 1373 DF, p-value: <2e-16
SCtest(m1d)  # no sig serial correlation!
## 
## Call:
## lm(formula = res[-n] ~ res[-1])
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -3.105 -0.506 -0.106  0.411  3.555 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept) 7.14e-05   2.20e-02    0.00     1.00
## res[-1]     3.00e-02   2.68e-02    1.12     0.26
## 
## Residual standard error: 0.821 on 1392 degrees of freedom
## Multiple R-squared:  0.0009, Adjusted R-squared:  0.000182 
## F-statistic: 1.25 on 1 and 1392 DF,  p-value: 0.263
xyplot(m1d$residuals ~ fitted(m1d))  # not bad

plot of chunk unnamed-chunk-10

qqPlot(m1d$residuals)  # not great

plot of chunk unnamed-chunk-10


m2d = plm(TotalSTD ~ PRECIPlevels + lag(TotalSTD, 1) + lag(TotalSTD, 2) + lag(TotalSTD, 
    3), data = pdata)
summary(m2d)  #sig
## Oneway (individual) effect Within Model
## 
## Call:
## plm(formula = TotalSTD ~ PRECIPlevels + lag(TotalSTD, 1) + lag(TotalSTD, 
##     2) + lag(TotalSTD, 3), data = pdata)
## 
## Balanced Panel: n=15, T=93, N=1395
## 
## Residuals :
##    Min. 1st Qu.  Median 3rd Qu.    Max. 
## -3.0900 -0.4800 -0.0975  0.4140  3.5200 
## 
## Coefficients :
##                     Estimate Std. Error t-value Pr(>|t|)    
## PRECIPlevelsDrought  -0.4188     0.2185   -1.92   0.0555 .  
## PRECIPlevelsDry      -0.3185     0.1024   -3.11   0.0019 ** 
## PRECIPlevelsWet      -0.0956     0.1049   -0.91   0.3623    
## PRECIPlevelsSoaked   -0.2894     0.2170   -1.33   0.1825    
## lag(TotalSTD, 1)      0.3074     0.0259   11.86   <2e-16 ***
## lag(TotalSTD, 2)      0.0531     0.0272    1.95   0.0509 .  
## lag(TotalSTD, 3)      0.2577     0.0258   10.00   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    1250
## Residual Sum of Squares: 938
## R-Squared      :  0.198 
##       Adj. R-Squared :  0.195 
## F-statistic: 64.7304 on 7 and 1373 DF, p-value: <2e-16
SCtest(m2d)  # no sig serial correlation!
## 
## Call:
## lm(formula = res[-n] ~ res[-1])
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -3.122 -0.489 -0.098  0.405  3.537 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept) 8.46e-05   2.20e-02    0.00     1.00
## res[-1]     2.04e-02   2.68e-02    0.76     0.45
## 
## Residual standard error: 0.821 on 1392 degrees of freedom
## Multiple R-squared:  0.000415,   Adjusted R-squared:  -0.000303 
## F-statistic: 0.578 on 1 and 1392 DF,  p-value: 0.447
xyplot(m2d$residuals ~ fitted(m2d))  # not bad

plot of chunk unnamed-chunk-10

qqPlot(m2d$residuals)  # not great

plot of chunk unnamed-chunk-10


## With time and county dummies
m1e = plm(TotalSTD ~ TMEANlevels + lag(TotalSTD, 1) + lag(TotalSTD, 2) + lag(TotalSTD, 
    3), data = pdata, model = "within", effect = "twoways")
summary(m1e)  #sig hot
## Twoways effects Within Model
## 
## Call:
## plm(formula = TotalSTD ~ TMEANlevels + lag(TotalSTD, 1) + lag(TotalSTD, 
##     2) + lag(TotalSTD, 3), data = pdata, effect = "twoways", 
##     model = "within")
## 
## Balanced Panel: n=15, T=93, N=1395
## 
## Residuals :
##    Min. 1st Qu.  Median 3rd Qu.    Max. 
## -2.9700 -0.3620 -0.0234  0.3550  3.1700 
## 
## Coefficients :
##                     Estimate Std. Error t-value Pr(>|t|)    
## TMEANlevelsFreezing   0.1940     0.2306    0.84   0.4003    
## TMEANlevelsCold      -0.0471     0.0966   -0.49   0.6259    
## TMEANlevelsWarm       0.0170     0.0995    0.17   0.8646    
## TMEANlevelsHot       -0.3583     0.1939   -1.85   0.0648 .  
## lag(TotalSTD, 1)      0.4879     0.0278   17.56   <2e-16 ***
## lag(TotalSTD, 2)      0.0673     0.0310    2.17   0.0302 *  
## lag(TotalSTD, 3)      0.0881     0.0278    3.17   0.0016 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    787
## Residual Sum of Squares: 519
## R-Squared      :  0.114 
##       Adj. R-Squared :  0.104 
## F-statistic: 94.7609 on 7 and 1281 DF, p-value: <2e-16
SCtest(m1e)  # non sig serial correlation!
## 
## Call:
## lm(formula = res[-n] ~ res[-1])
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -2.990 -0.361 -0.024  0.352  3.194 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.000171   0.016347    0.01     0.99
## res[-1]     0.008816   0.026802    0.33     0.74
## 
## Residual standard error: 0.61 on 1392 degrees of freedom
## Multiple R-squared:  7.77e-05,   Adjusted R-squared:  -0.000641 
## F-statistic: 0.108 on 1 and 1392 DF,  p-value: 0.742
qqPlot(m1e$residuals)  # better

plot of chunk unnamed-chunk-10


m2e = plm(TotalSTD ~ PRECIPlevels + lag(TotalSTD, 1) + lag(TotalSTD, 2), data = pdata, 
    model = "within", effect = "twoways")
summary(m2e)  #sig!
## Twoways effects Within Model
## 
## Call:
## plm(formula = TotalSTD ~ PRECIPlevels + lag(TotalSTD, 1) + lag(TotalSTD, 
##     2), data = pdata, effect = "twoways", model = "within")
## 
## Balanced Panel: n=15, T=94, N=1410
## 
## Residuals :
##    Min. 1st Qu.  Median 3rd Qu.    Max. 
## -2.9800 -0.3550 -0.0203  0.3630  3.1800 
## 
## Coefficients :
##                     Estimate Std. Error t-value Pr(>|t|)    
## PRECIPlevelsDrought  -0.4060     0.1767   -2.30  0.02173 *  
## PRECIPlevelsDry      -0.3279     0.0847   -3.87  0.00011 ***
## PRECIPlevelsWet      -0.1273     0.0848   -1.50  0.13338    
## PRECIPlevelsSoaked   -0.1111     0.1696   -0.66  0.51234    
## lag(TotalSTD, 1)      0.4979     0.0274   18.20  < 2e-16 ***
## lag(TotalSTD, 2)      0.1196     0.0272    4.39  1.2e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    805
## Residual Sum of Squares: 520
## R-Squared      :  0.123 
##       Adj. R-Squared :  0.113 
## F-statistic: 118.395 on 6 and 1296 DF, p-value: <2e-16
SCtest(m2e)  # non sig serial correlation!
## 
## Call:
## lm(formula = res[-n] ~ res[-1])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.9330 -0.3610 -0.0193  0.3728  3.1009 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)
## (Intercept)  0.000183   0.016184    0.01     0.99
## res[-1]     -0.026655   0.026661   -1.00     0.32
## 
## Residual standard error: 0.608 on 1407 degrees of freedom
## Multiple R-squared:  0.00071,    Adjusted R-squared:  -3.2e-07 
## F-statistic:    1 on 1 and 1407 DF,  p-value: 0.318
xyplot(m2e$residuals ~ fitted(m2e))  # not bad

plot of chunk unnamed-chunk-10

qqPlot(m2e$residuals)  # better

plot of chunk unnamed-chunk-10

The above results show that low levels of precipitation as defined by the 1st set of levels are related to lower levels of retail sales, regardless of whether temperature levels are included in the model. Adding county and time dummies makes the residuals behave slightly better in the QQ plot. The p-values also decrease with the dummies, indicating that some of the noisy/useless variation in sales has been accounted for. There is a significant negative coefficient on Hot in both models above. We will get back to this possible relationship between temperature level and retail sales.

Final model for 1st set of levels.

# Putting County and t in formula to aid with residual plots (see below for
# model with normal formula.
m3e = plm(TotalSTD ~ PRECIPlevels + TMEANlevels + lag(TotalSTD, 1) + lag(TotalSTD, 
    2) + lag(TotalSTD, 3) + factor(t) + County.Area, data = pdata)
summary(m3e)  # sig!
## Oneway (individual) effect Within Model
## 
## Call:
## plm(formula = TotalSTD ~ PRECIPlevels + TMEANlevels + lag(TotalSTD, 
##     1) + lag(TotalSTD, 2) + lag(TotalSTD, 3) + factor(t) + County.Area, 
##     data = pdata)
## 
## Balanced Panel: n=15, T=93, N=1395
## 
## Residuals :
##    Min. 1st Qu.  Median 3rd Qu.    Max. 
## -3.0000 -0.3510 -0.0197  0.3540  3.1800 
## 
## Coefficients :
##                     Estimate Std. Error t-value Pr(>|t|)    
## PRECIPlevelsDrought -0.45187    0.17667   -2.56  0.01065 *  
## PRECIPlevelsDry     -0.35976    0.08539   -4.21  2.7e-05 ***
## PRECIPlevelsWet     -0.13430    0.08656   -1.55  0.12103    
## PRECIPlevelsSoaked  -0.10836    0.17484   -0.62  0.53553    
## TMEANlevelsFreezing  0.17014    0.22914    0.74  0.45792    
## TMEANlevelsCold     -0.06191    0.09598   -0.64  0.51907    
## TMEANlevelsWarm      0.01719    0.09872    0.17  0.86179    
## TMEANlevelsHot      -0.35851    0.19236   -1.86  0.06258 .  
## lag(TotalSTD, 1)     0.47567    0.02778   17.12  < 2e-16 ***
## lag(TotalSTD, 2)     0.06622    0.03080    2.15  0.03177 *  
## lag(TotalSTD, 3)     0.10068    0.02770    3.63  0.00029 ***
## factor(t)9           0.43747    0.23169    1.89  0.05922 .  
## factor(t)10          0.33785    0.23142    1.46  0.14457    
## factor(t)11          1.36380    0.23159    5.89  5.0e-09 ***
## factor(t)12         -0.86549    0.23376   -3.70  0.00022 ***
## factor(t)13          0.05549    0.23640    0.23  0.81445    
## factor(t)14          1.19922    0.23572    5.09  4.2e-07 ***
## factor(t)15          0.28414    0.23458    1.21  0.22601    
## factor(t)16          0.63807    0.23780    2.68  0.00739 ** 
## factor(t)17          0.44348    0.23146    1.92  0.05559 .  
## factor(t)18          0.01224    0.23181    0.05  0.95791    
## factor(t)19          0.36565    0.23208    1.58  0.11539    
## factor(t)20          0.14594    0.23182    0.63  0.52913    
## factor(t)21         -0.16077    0.23472   -0.68  0.49350    
## factor(t)22          0.07234    0.23151    0.31  0.75473    
## factor(t)23          2.01393    0.23472    8.58  < 2e-16 ***
## factor(t)24         -0.90113    0.24690   -3.65  0.00027 ***
## factor(t)25         -0.16949    0.23938   -0.71  0.47906    
## factor(t)26          0.78053    0.23621    3.30  0.00098 ***
## factor(t)27          0.15819    0.23350    0.68  0.49823    
## factor(t)28          0.26325    0.23390    1.13  0.26060    
## factor(t)29          1.02863    0.23238    4.43  1.0e-05 ***
## factor(t)30          0.28599    0.23343    1.23  0.22073    
## factor(t)31          0.45908    0.23303    1.97  0.04905 *  
## factor(t)32          0.09834    0.23154    0.42  0.67112    
## factor(t)33          0.12863    0.23124    0.56  0.57812    
## factor(t)34         -0.15625    0.23846   -0.66  0.51243    
## factor(t)35          1.46363    0.24028    6.09  1.5e-09 ***
## factor(t)36         -0.63280    0.23484   -2.69  0.00714 ** 
## factor(t)37         -0.19053    0.23774   -0.80  0.42303    
## factor(t)38          0.70878    0.23357    3.03  0.00246 ** 
## factor(t)39          0.02421    0.23365    0.10  0.91751    
## factor(t)40          0.39594    0.23303    1.70  0.08954 .  
## factor(t)41          0.78983    0.23163    3.41  0.00067 ***
## factor(t)42          0.17023    0.23444    0.73  0.46790    
## factor(t)43          0.62446    0.23238    2.69  0.00730 ** 
## factor(t)44         -0.16386    0.23373   -0.70  0.48338    
## factor(t)45          0.15294    0.23208    0.66  0.51002    
## factor(t)46         -0.00156    0.23705   -0.01  0.99474    
## factor(t)47          1.23485    0.23346    5.29  1.4e-07 ***
## factor(t)48         -0.72884    0.23437   -3.11  0.00191 ** 
## factor(t)49         -0.35399    0.23530   -1.50  0.13272    
## factor(t)50          0.54198    0.23376    2.32  0.02058 *  
## factor(t)51          0.11073    0.23318    0.47  0.63495    
## factor(t)52          0.43810    0.23512    1.86  0.06265 .  
## factor(t)53          0.74169    0.23178    3.20  0.00141 ** 
## factor(t)54          0.12878    0.23410    0.55  0.58236    
## factor(t)55          0.28107    0.23303    1.21  0.22798    
## factor(t)56         -0.05608    0.23305   -0.24  0.80986    
## factor(t)57         -0.25522    0.23263   -1.10  0.27280    
## factor(t)58         -0.49827    0.23181   -2.15  0.03178 *  
## factor(t)59          1.20311    0.23275    5.17  2.7e-07 ***
## factor(t)60         -1.08532    0.23718   -4.58  5.2e-06 ***
## factor(t)61         -0.38853    0.23784   -1.63  0.10259    
## factor(t)62          0.12567    0.23554    0.53  0.59376    
## factor(t)63         -0.09812    0.23603   -0.42  0.67768    
## factor(t)64          0.09998    0.23482    0.43  0.67033    
## factor(t)65          0.45858    0.23389    1.96  0.05013 .  
## factor(t)66          0.28682    0.23760    1.21  0.22760    
## factor(t)67          0.29936    0.23290    1.29  0.19891    
## factor(t)68         -0.01781    0.23185   -0.08  0.93877    
## factor(t)69         -0.29882    0.23197   -1.29  0.19791    
## factor(t)70         -0.29194    0.23247   -1.26  0.20941    
## factor(t)71          1.06875    0.24060    4.44  9.7e-06 ***
## factor(t)72         -1.10950    0.23987   -4.63  4.1e-06 ***
## factor(t)73         -0.21735    0.24019   -0.90  0.36568    
## factor(t)74          0.54687    0.23727    2.30  0.02134 *  
## factor(t)75          0.04309    0.23540    0.18  0.85479    
## factor(t)76          0.09468    0.23530    0.40  0.68748    
## factor(t)77          0.60918    0.23238    2.62  0.00886 ** 
## factor(t)78         -0.01337    0.23311   -0.06  0.95429    
## factor(t)79          0.30717    0.23333    1.32  0.18826    
## factor(t)80          0.03005    0.23189    0.13  0.89693    
## factor(t)81         -0.11861    0.23184   -0.51  0.60901    
## factor(t)82         -0.28538    0.26821   -1.06  0.28752    
## factor(t)83          1.55077    0.23420    6.62  5.2e-11 ***
## factor(t)84         -1.15969    0.23587   -4.92  9.9e-07 ***
## factor(t)85         -0.15274    0.23839   -0.64  0.52182    
## factor(t)86          0.65533    0.23565    2.78  0.00550 ** 
## factor(t)87          0.06248    0.23465    0.27  0.79008    
## factor(t)88          0.15251    0.23397    0.65  0.51462    
## factor(t)89          0.74056    0.23147    3.20  0.00141 ** 
## factor(t)90          0.21359    0.23326    0.92  0.36002    
## factor(t)91          0.27171    0.23229    1.17  0.24235    
## factor(t)92          0.21425    0.23156    0.93  0.35502    
## factor(t)93         -0.14224    0.23132   -0.61  0.53872    
## factor(t)94          0.10611    0.23280    0.46  0.64862    
## factor(t)95          1.33306    0.23151    5.76  1.1e-08 ***
## factor(t)96         -1.02785    0.23513   -4.37  1.3e-05 ***
## factor(t)97          0.26529    0.25136    1.06  0.29143    
## factor(t)98          0.81186    0.23927    3.39  0.00071 ***
## factor(t)99          0.05008    0.23419    0.21  0.83069    
## factor(t)100         0.29305    0.23296    1.26  0.20863    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    1250
## Residual Sum of Squares: 509
## R-Squared      :  0.536 
##       Adj. R-Squared :  0.491 
## F-statistic: 17.9954 on 103 and 1277 DF, p-value: <2e-16
SCtest(m3e)  # non sig serial correlation!
## 
## Call:
## lm(formula = res[-n] ~ res[-1])
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -3.008 -0.350 -0.020  0.353  3.189 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.000175   0.016192    0.01     0.99
## res[-1]     0.002126   0.026802    0.08     0.94
## 
## Residual standard error: 0.605 on 1392 degrees of freedom
## Multiple R-squared:  4.52e-06,   Adjusted R-squared:  -0.000714 
## F-statistic: 0.00629 on 1 and 1392 DF,  p-value: 0.937
xyplot(m3e$residuals ~ fitted(m3e))  # not bad

plot of chunk unnamed-chunk-11

qqPlot(m3e$residuals)  # not bad

plot of chunk unnamed-chunk-11

plot(m3e$residuals ~ m3e$model[[7]], xlab = "Time", ylab = "Residuals")

plot of chunk unnamed-chunk-11

plot(m3e$residuals ~ m3e$model[[8]], xlab = "County", ylab = "Residuals")

plot of chunk unnamed-chunk-11

We decide to use the model with both PRECIPlevels and TMEANlevels as our final model because the coefficients are largely the same as when using levels as predictors in separate models, and because this allows us to interpret the relationships of one level when accounting for the other.

We find that conditions for inference appear to be met in this model. There is no significant serial correlation in the residuals (p-value = 0.76). The residual vs fitted plot reveal few outlier and no apparent trends or patterns. The QQ plot has some issues with the tails, but looks acceptable overall. The boxplot of residuals vs time and county/area shows that residuals seem to have fairly constant variation over time and counties.

These were result from an altered plm model. Below, we show that results are identical with the plm model form we have been using so far. Also, we show that our results are robust to excluding outliers.

# Normal forumla
m3e2 = plm(TotalSTD ~ PRECIPlevels + TMEANlevels + lag(TotalSTD, 1) + lag(TotalSTD, 
    2) + lag(TotalSTD, 3), data = pdata, model = "within", effect = "twoways")
summary(m3e2)
## Twoways effects Within Model
## 
## Call:
## plm(formula = TotalSTD ~ PRECIPlevels + TMEANlevels + lag(TotalSTD, 
##     1) + lag(TotalSTD, 2) + lag(TotalSTD, 3), data = pdata, effect = "twoways", 
##     model = "within")
## 
## Balanced Panel: n=15, T=93, N=1395
## 
## Residuals :
##    Min. 1st Qu.  Median 3rd Qu.    Max. 
## -3.0000 -0.3510 -0.0197  0.3540  3.1800 
## 
## Coefficients :
##                     Estimate Std. Error t-value Pr(>|t|)    
## PRECIPlevelsDrought  -0.4519     0.1767   -2.56  0.01065 *  
## PRECIPlevelsDry      -0.3598     0.0854   -4.21  2.7e-05 ***
## PRECIPlevelsWet      -0.1343     0.0866   -1.55  0.12103    
## PRECIPlevelsSoaked   -0.1084     0.1748   -0.62  0.53553    
## TMEANlevelsFreezing   0.1701     0.2291    0.74  0.45792    
## TMEANlevelsCold      -0.0619     0.0960   -0.64  0.51907    
## TMEANlevelsWarm       0.0172     0.0987    0.17  0.86179    
## TMEANlevelsHot       -0.3585     0.1924   -1.86  0.06258 .  
## lag(TotalSTD, 1)      0.4757     0.0278   17.12  < 2e-16 ***
## lag(TotalSTD, 2)      0.0662     0.0308    2.15  0.03177 *  
## lag(TotalSTD, 3)      0.1007     0.0277    3.63  0.00029 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    787
## Residual Sum of Squares: 509
## R-Squared      :  0.121 
##       Adj. R-Squared :  0.11 
## F-statistic: 63.5052 on 11 and 1277 DF, p-value: <2e-16
SCtest(m3e2)
## 
## Call:
## lm(formula = res[-n] ~ res[-1])
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -3.008 -0.350 -0.020  0.353  3.189 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.000175   0.016192    0.01     0.99
## res[-1]     0.002126   0.026802    0.08     0.94
## 
## Residual standard error: 0.605 on 1392 degrees of freedom
## Multiple R-squared:  4.52e-06,   Adjusted R-squared:  -0.000714 
## F-statistic: 0.00629 on 1 and 1392 DF,  p-value: 0.937
plot(m3e2$residuals ~ fitted(m3e2), xlab = "Fitted", ylab = "Residuals")

plot of chunk unnamed-chunk-12

qqPlot(m3e2$residuals)

plot of chunk unnamed-chunk-12


# Removing outliers
findoutliers = plm(TotalSTD ~ PRECIPlevels + TMEANlevels, effect = "twoways", 
    model = "within", data = pdata)
outliers = which(abs(findoutliers$residuals) > 2)
pdata2 = pdata[-outliers, ]

# New reg without outliers
m3e3 = plm(TotalSTD ~ PRECIPlevels + TMEANlevels + lag(TotalSTD, 1) + lag(TotalSTD, 
    2) + lag(TotalSTD, 3), effect = "twoways", model = "within", data = pdata2)
summary(m3e3)  # still sig
## Twoways effects Within Model
## 
## Call:
## plm(formula = TotalSTD ~ PRECIPlevels + TMEANlevels + lag(TotalSTD, 
##     1) + lag(TotalSTD, 2) + lag(TotalSTD, 3), data = pdata2, 
##     effect = "twoways", model = "within")
## 
## Unbalanced Panel: n=15, T=77-93, N=1335
## 
## Residuals :
##    Min. 1st Qu.  Median 3rd Qu.    Max. 
##  -1.720  -0.341  -0.015   0.348   2.350 
## 
## Coefficients :
##                     Estimate Std. Error t-value Pr(>|t|)    
## PRECIPlevelsDrought  -0.4114     0.1681   -2.45   0.0145 *  
## PRECIPlevelsDry      -0.3520     0.0806   -4.37  1.4e-05 ***
## PRECIPlevelsWet      -0.1224     0.0799   -1.53   0.1260    
## PRECIPlevelsSoaked   -0.2714     0.1663   -1.63   0.1029    
## TMEANlevelsFreezing   0.0812     0.2174    0.37   0.7089    
## TMEANlevelsCold      -0.0394     0.0918   -0.43   0.6683    
## TMEANlevelsWarm      -0.0618     0.0928   -0.67   0.5058    
## TMEANlevelsHot       -0.4182     0.1809   -2.31   0.0209 *  
## lag(TotalSTD, 1)      0.4851     0.0282   17.18  < 2e-16 ***
## lag(TotalSTD, 2)      0.0747     0.0315    2.37   0.0180 *  
## lag(TotalSTD, 3)      0.0735     0.0282    2.60   0.0093 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    631
## Residual Sum of Squares: 409
## R-Squared      :  0.102 
##       Adj. R-Squared :  0.0932 
## F-statistic: 60.1843 on 11 and 1217 DF, p-value: <2e-16
SCtest(m3e3)
## 
## Call:
## lm(formula = res[-n] ~ res[-1])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.7172 -0.3444 -0.0167  0.3462  2.3453 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)
## (Intercept)  0.000163   0.015165    0.01     0.99
## res[-1]     -0.011838   0.027397   -0.43     0.67
## 
## Residual standard error: 0.554 on 1332 degrees of freedom
## Multiple R-squared:  0.00014,    Adjusted R-squared:  -0.00061 
## F-statistic: 0.187 on 1 and 1332 DF,  p-value: 0.666
xyplot(m3e3$residuals ~ fitted(m3e3))  # looks ok

plot of chunk unnamed-chunk-12

qqPlot(m3e3$residuals)  #looks ok

plot of chunk unnamed-chunk-12

The results above show that our result that low levels of precipitation are related to lower retail sales (after accounting for temperature level) is robust and conditions for inference are met. The result regarding high temperature levels is robust to excluding outliers, which makes us wonder if there might potentially be a significant relationship here.

Final model with 2nd set of levels

# Testing TMEANlevels separately
m1f = plm(TotalSTD ~ TMEANlevels2.f + lag(TotalSTD, 1) + lag(TotalSTD, 2) + 
    lag(TotalSTD, 3), data = pdata, model = "within", effect = "twoways")
summary(m1f)  #nonsig
## Twoways effects Within Model
## 
## Call:
## plm(formula = TotalSTD ~ TMEANlevels2.f + lag(TotalSTD, 1) + 
##     lag(TotalSTD, 2) + lag(TotalSTD, 3), data = pdata, effect = "twoways", 
##     model = "within")
## 
## Balanced Panel: n=15, T=93, N=1395
## 
## Residuals :
##    Min. 1st Qu.  Median 3rd Qu.    Max. 
## -2.9700 -0.3600 -0.0253  0.3550  3.1800 
## 
## Coefficients :
##                        Estimate Std. Error t-value Pr(>|t|)    
## TMEANlevels2.fFreezing  -0.1249     0.2209   -0.57   0.5721    
## TMEANlevels2.fCold       0.0293     0.0952    0.31   0.7582    
## TMEANlevels2.fWarm      -0.0176     0.0956   -0.18   0.8542    
## TMEANlevels2.fHot       -0.1950     0.1951   -1.00   0.3180    
## lag(TotalSTD, 1)         0.4890     0.0279   17.53   <2e-16 ***
## lag(TotalSTD, 2)         0.0714     0.0309    2.31   0.0209 *  
## lag(TotalSTD, 3)         0.0810     0.0276    2.93   0.0035 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    787
## Residual Sum of Squares: 520
## R-Squared      :  0.113 
##       Adj. R-Squared :  0.104 
## F-statistic: 94.0884 on 7 and 1281 DF, p-value: <2e-16

# Putting County and t in formula to aid with residual plots (see below for
# model with normal formula)
m3f = plm(TotalSTD ~ PRECIPlevels2.f + TMEANlevels2.f + lag(TotalSTD, 1) + lag(TotalSTD, 
    2) + lag(TotalSTD, 3) + factor(t) + County.Area, data = pdata)
summary(m3f)  # sig
## Oneway (individual) effect Within Model
## 
## Call:
## plm(formula = TotalSTD ~ PRECIPlevels2.f + TMEANlevels2.f + lag(TotalSTD, 
##     1) + lag(TotalSTD, 2) + lag(TotalSTD, 3) + factor(t) + County.Area, 
##     data = pdata)
## 
## Balanced Panel: n=15, T=93, N=1395
## 
## Residuals :
##    Min. 1st Qu.  Median 3rd Qu.    Max. 
##  -2.980  -0.356  -0.020   0.356   3.180 
## 
## Coefficients :
##                        Estimate Std. Error t-value Pr(>|t|)    
## PRECIPlevels2.fDrought -0.47206    0.18181   -2.60  0.00953 ** 
## PRECIPlevels2.fDry     -0.16552    0.08665   -1.91  0.05634 .  
## PRECIPlevels2.fWet     -0.04314    0.08458   -0.51  0.61013    
## PRECIPlevels2.fSoaked  -0.28214    0.18728   -1.51  0.13217    
## TMEANlevels2.fFreezing -0.13668    0.22049   -0.62  0.53545    
## TMEANlevels2.fCold      0.01727    0.09513    0.18  0.85599    
## TMEANlevels2.fWarm     -0.01437    0.09539   -0.15  0.88029    
## TMEANlevels2.fHot      -0.19378    0.19452   -1.00  0.31936    
## lag(TotalSTD, 1)        0.48323    0.02795   17.29  < 2e-16 ***
## lag(TotalSTD, 2)        0.07051    0.03092    2.28  0.02275 *  
## lag(TotalSTD, 3)        0.08702    0.02769    3.14  0.00171 ** 
## factor(t)9              0.47675    0.24034    1.98  0.04751 *  
## factor(t)10             0.32169    0.23271    1.38  0.16711    
## factor(t)11             1.34853    0.23289    5.79  8.8e-09 ***
## factor(t)12            -0.89153    0.23490   -3.80  0.00015 ***
## factor(t)13             0.01692    0.23805    0.07  0.94333    
## factor(t)14             1.18081    0.23795    4.96  7.9e-07 ***
## factor(t)15             0.25280    0.23574    1.07  0.28376    
## factor(t)16             0.56814    0.23787    2.39  0.01706 *  
## factor(t)17             0.42958    0.23285    1.84  0.06528 .  
## factor(t)18            -0.00847    0.23315   -0.04  0.97102    
## factor(t)19             0.27626    0.23317    1.18  0.23632    
## factor(t)20             0.15551    0.23399    0.66  0.50642    
## factor(t)21            -0.12684    0.24075   -0.53  0.59838    
## factor(t)22             0.05514    0.23285    0.24  0.81284    
## factor(t)23             2.01929    0.23585    8.56  < 2e-16 ***
## factor(t)24            -0.98535    0.24746   -3.98  7.2e-05 ***
## factor(t)25            -0.19081    0.24118   -0.79  0.42900    
## factor(t)26             0.80660    0.23750    3.40  0.00070 ***
## factor(t)27             0.11271    0.23466    0.48  0.63109    
## factor(t)28             0.22634    0.23576    0.96  0.33721    
## factor(t)29             1.01466    0.23489    4.32  1.7e-05 ***
## factor(t)30             0.18783    0.23396    0.80  0.42223    
## factor(t)31             0.40695    0.23425    1.74  0.08259 .  
## factor(t)32             0.03696    0.23257    0.16  0.87375    
## factor(t)33             0.11876    0.23317    0.51  0.61060    
## factor(t)34            -0.13354    0.23748   -0.56  0.57401    
## factor(t)35             1.51212    0.24150    6.26  5.2e-10 ***
## factor(t)36            -0.66122    0.23568   -2.81  0.00510 ** 
## factor(t)37            -0.22026    0.24054   -0.92  0.36001    
## factor(t)38             0.71806    0.23492    3.06  0.00229 ** 
## factor(t)39            -0.01044    0.23476   -0.04  0.96453    
## factor(t)40             0.37852    0.23451    1.61  0.10676    
## factor(t)41             0.78339    0.23294    3.36  0.00079 ***
## factor(t)42             0.13986    0.23685    0.59  0.55497    
## factor(t)43             0.57873    0.23384    2.47  0.01345 *  
## factor(t)44            -0.15684    0.23591   -0.66  0.50626    
## factor(t)45             0.08960    0.23351    0.38  0.70128    
## factor(t)46             0.02451    0.24040    0.10  0.91881    
## factor(t)47             1.19760    0.23475    5.10  3.9e-07 ***
## factor(t)48            -0.74132    0.23619   -3.14  0.00174 ** 
## factor(t)49            -0.38711    0.23683   -1.63  0.10239    
## factor(t)50             0.54720    0.23523    2.33  0.02016 *  
## factor(t)51             0.09477    0.23437    0.40  0.68600    
## factor(t)52             0.38137    0.23781    1.60  0.10904    
## factor(t)53             0.71897    0.23305    3.09  0.00208 ** 
## factor(t)54             0.10044    0.23488    0.43  0.66900    
## factor(t)55             0.20721    0.23397    0.89  0.37600    
## factor(t)56            -0.09773    0.23423   -0.42  0.67658    
## factor(t)57            -0.28296    0.23432   -1.21  0.22745    
## factor(t)58            -0.50435    0.23319   -2.16  0.03074 *  
## factor(t)59             1.19794    0.23414    5.12  3.6e-07 ***
## factor(t)60            -1.13250    0.23893   -4.74  2.4e-06 ***
## factor(t)61            -0.40712    0.23945   -1.70  0.08933 .  
## factor(t)62             0.12836    0.23680    0.54  0.58786    
## factor(t)63            -0.12569    0.23677   -0.53  0.59559    
## factor(t)64             0.01970    0.23584    0.08  0.93345    
## factor(t)65             0.42522    0.23472    1.81  0.07029 .  
## factor(t)66             0.15456    0.23818    0.65  0.51651    
## factor(t)67             0.28061    0.23423    1.20  0.23113    
## factor(t)68            -0.05666    0.23313   -0.24  0.80800    
## factor(t)69            -0.30622    0.23362   -1.31  0.19017    
## factor(t)70            -0.30904    0.23378   -1.32  0.18643    
## factor(t)71             1.00067    0.24032    4.16  3.3e-05 ***
## factor(t)72            -1.15184    0.24341   -4.73  2.5e-06 ***
## factor(t)73            -0.25593    0.24279   -1.05  0.29202    
## factor(t)74             0.50138    0.23843    2.10  0.03568 *  
## factor(t)75             0.01650    0.23717    0.07  0.94454    
## factor(t)76             0.03591    0.23627    0.15  0.87922    
## factor(t)77             0.56742    0.23343    2.43  0.01520 *  
## factor(t)78            -0.05920    0.23407   -0.25  0.80037    
## factor(t)79             0.24132    0.23458    1.03  0.30379    
## factor(t)80            -0.00355    0.23318   -0.02  0.98784    
## factor(t)81            -0.13367    0.23325   -0.57  0.56669    
## factor(t)82            -0.09990    0.26022   -0.38  0.70112    
## factor(t)83             1.50488    0.23633    6.37  2.7e-10 ***
## factor(t)84            -1.18136    0.23697   -4.99  7.0e-07 ***
## factor(t)85            -0.17470    0.24000   -0.73  0.46679    
## factor(t)86             0.66978    0.23711    2.82  0.00481 ** 
## factor(t)87             0.00261    0.23569    0.01  0.99116    
## factor(t)88             0.09875    0.23509    0.42  0.67452    
## factor(t)89             0.72038    0.23279    3.09  0.00201 ** 
## factor(t)90             0.18013    0.23409    0.77  0.44175    
## factor(t)91             0.25315    0.23365    1.08  0.27881    
## factor(t)92             0.21144    0.23292    0.91  0.36415    
## factor(t)93            -0.15445    0.23265   -0.66  0.50687    
## factor(t)94             0.10364    0.23310    0.44  0.65669    
## factor(t)95             1.32495    0.23283    5.69  1.6e-08 ***
## factor(t)96            -1.04344    0.23695   -4.40  1.2e-05 ***
## factor(t)97             0.22361    0.25577    0.87  0.38215    
## factor(t)98             0.73022    0.23775    3.07  0.00218 ** 
## factor(t)99             0.01091    0.23510    0.05  0.96298    
## factor(t)100            0.28035    0.23432    1.20  0.23173    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    1250
## Residual Sum of Squares: 515
## R-Squared      :  0.531 
##       Adj. R-Squared :  0.486 
## F-statistic: 17.6322 on 103 and 1277 DF, p-value: <2e-16
SCtest(m3f)  # non sig serial correlation!
## 
## Call:
## lm(formula = res[-n] ~ res[-1])
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -2.986 -0.356 -0.022  0.355  3.193 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.000185   0.016289    0.01     0.99
## res[-1]     0.004841   0.026802    0.18     0.86
## 
## Residual standard error: 0.608 on 1392 degrees of freedom
## Multiple R-squared:  2.34e-05,   Adjusted R-squared:  -0.000695 
## F-statistic: 0.0326 on 1 and 1392 DF,  p-value: 0.857
xyplot(m3f$residuals ~ fitted(m3f))  # not bad

plot of chunk unnamed-chunk-13

qqPlot(m3f$residuals)  # not bad

plot of chunk unnamed-chunk-13

plot(m3f$residuals ~ m3f$model[[7]], xlab = "Time", ylab = "Residuals")

plot of chunk unnamed-chunk-13

plot(m3e$residuals ~ m3f$model[[8]], xlab = "County", ylab = "Residuals")

plot of chunk unnamed-chunk-13


# Normal forumla
m3f2 = plm(TotalSTD ~ PRECIPlevels2.f + TMEANlevels2.f + lag(TotalSTD, 1) + 
    lag(TotalSTD, 2) + lag(TotalSTD, 3), data = pdata, model = "within", effect = "twoways")
summary(m3f2)
## Twoways effects Within Model
## 
## Call:
## plm(formula = TotalSTD ~ PRECIPlevels2.f + TMEANlevels2.f + lag(TotalSTD, 
##     1) + lag(TotalSTD, 2) + lag(TotalSTD, 3), data = pdata, effect = "twoways", 
##     model = "within")
## 
## Balanced Panel: n=15, T=93, N=1395
## 
## Residuals :
##    Min. 1st Qu.  Median 3rd Qu.    Max. 
##  -2.980  -0.356  -0.020   0.356   3.180 
## 
## Coefficients :
##                        Estimate Std. Error t-value Pr(>|t|)    
## PRECIPlevels2.fDrought  -0.4721     0.1818   -2.60   0.0095 ** 
## PRECIPlevels2.fDry      -0.1655     0.0867   -1.91   0.0563 .  
## PRECIPlevels2.fWet      -0.0431     0.0846   -0.51   0.6101    
## PRECIPlevels2.fSoaked   -0.2821     0.1873   -1.51   0.1322    
## TMEANlevels2.fFreezing  -0.1367     0.2205   -0.62   0.5354    
## TMEANlevels2.fCold       0.0173     0.0951    0.18   0.8560    
## TMEANlevels2.fWarm      -0.0144     0.0954   -0.15   0.8803    
## TMEANlevels2.fHot       -0.1938     0.1945   -1.00   0.3194    
## lag(TotalSTD, 1)         0.4832     0.0279   17.29   <2e-16 ***
## lag(TotalSTD, 2)         0.0705     0.0309    2.28   0.0227 *  
## lag(TotalSTD, 3)         0.0870     0.0277    3.14   0.0017 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    787
## Residual Sum of Squares: 515
## R-Squared      :  0.116 
##       Adj. R-Squared :  0.106 
## F-statistic: 61.3591 on 11 and 1277 DF, p-value: <2e-16
SCtest(m3f2)
## 
## Call:
## lm(formula = res[-n] ~ res[-1])
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -2.986 -0.356 -0.022  0.355  3.193 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.000185   0.016289    0.01     0.99
## res[-1]     0.004841   0.026802    0.18     0.86
## 
## Residual standard error: 0.608 on 1392 degrees of freedom
## Multiple R-squared:  2.34e-05,   Adjusted R-squared:  -0.000695 
## F-statistic: 0.0326 on 1 and 1392 DF,  p-value: 0.857
xyplot(m3f2$residuals ~ fitted(m3f2), xlab = "Fitted", ylab = "Residuals")

plot of chunk unnamed-chunk-13

qqPlot(m3f2$residuals)

plot of chunk unnamed-chunk-13


# Removing outliers
findoutliers = plm(TotalSTD ~ PRECIPlevels2.f + TMEANlevels2.f, effect = "twoways", 
    model = "within", data = pdata)
outliers = which(abs(findoutliers$residuals) > 2)
pdata2 = pdata[-outliers, ]

# New reg without outliers
m3f3 = plm(TotalSTD ~ PRECIPlevels2.f + TMEANlevels2.f + lag(TotalSTD, 1) + 
    lag(TotalSTD, 2) + lag(TotalSTD, 3), effect = "twoways", model = "within", 
    data = pdata2)
summary(m3f3)  # still sig, now also 'Soaked'!
## Twoways effects Within Model
## 
## Call:
## plm(formula = TotalSTD ~ PRECIPlevels2.f + TMEANlevels2.f + lag(TotalSTD, 
##     1) + lag(TotalSTD, 2) + lag(TotalSTD, 3), data = pdata2, 
##     effect = "twoways", model = "within")
## 
## Unbalanced Panel: n=15, T=77-93, N=1327
## 
## Residuals :
##     Min.  1st Qu.   Median  3rd Qu.     Max. 
## -1.77000 -0.33900 -0.00889  0.34300  2.49000 
## 
## Coefficients :
##                        Estimate Std. Error t-value Pr(>|t|)    
## PRECIPlevels2.fDrought  -0.4733     0.1730   -2.74   0.0063 ** 
## PRECIPlevels2.fDry      -0.1391     0.0808   -1.72   0.0853 .  
## PRECIPlevels2.fWet      -0.0636     0.0785   -0.81   0.4175    
## PRECIPlevels2.fSoaked   -0.4967     0.1773   -2.80   0.0052 ** 
## TMEANlevels2.fFreezing  -0.2054     0.2065   -0.99   0.3200    
## TMEANlevels2.fCold       0.0713     0.0907    0.79   0.4320    
## TMEANlevels2.fWarm      -0.0323     0.0886   -0.36   0.7156    
## TMEANlevels2.fHot       -0.2909     0.1812   -1.61   0.1087    
## lag(TotalSTD, 1)         0.4946     0.0285   17.36   <2e-16 ***
## lag(TotalSTD, 2)         0.0957     0.0315    3.04   0.0025 ** 
## lag(TotalSTD, 3)         0.0465     0.0282    1.64   0.1003    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    620
## Residual Sum of Squares: 402
## R-Squared      :  0.1 
##       Adj. R-Squared :  0.0912 
## F-statistic: 59.4412 on 11 and 1209 DF, p-value: <2e-16
SCtest(m3f3)
## 
## Call:
## lm(formula = res[-n] ~ res[-1])
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -1.764 -0.340 -0.008  0.348  2.486 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept)  0.00018    0.01513    0.01     0.99
## res[-1]     -0.01384    0.02748   -0.50     0.61
## 
## Residual standard error: 0.551 on 1324 degrees of freedom
## Multiple R-squared:  0.000191,   Adjusted R-squared:  -0.000564 
## F-statistic: 0.254 on 1 and 1324 DF,  p-value: 0.615
xyplot(m3f3$residuals ~ fitted(m3f3))  # looks ok

plot of chunk unnamed-chunk-13

qqPlot(m3f3$residuals)  #looks ok

plot of chunk unnamed-chunk-13

The results for the 2nd set of levels look mostly the same as for the 1st set. Unusually low levels of precipitation are related to lower retail sales, after accounting for temperature level. Temperature level is not significantly related to retail sales in these results, leading us to doubt the importance of the earlier significant coefficient and refrain from stating that there is a significant relationship. The estimated coefficient for Drought is about the same as with the 1st level, indicating that the relationship is of similar magnitude. Interestingly, there is a significant negative coefficient on Soaked in the results after outliers are removed. This could inspire future analysis, but it is not a relationship that is substantiated by our other results when including all observations.

Final model with 3rd set of levels

# Testing TMEANlevels separately
m1g = plm(TotalSTD ~ TMEANlevels3.f + lag(TotalSTD, 1) + lag(TotalSTD, 2) + 
    lag(TotalSTD, 3), data = pdata, model = "within", effect = "twoways")
summary(m1g)  #nonsig
## Twoways effects Within Model
## 
## Call:
## plm(formula = TotalSTD ~ TMEANlevels3.f + lag(TotalSTD, 1) + 
##     lag(TotalSTD, 2) + lag(TotalSTD, 3), data = pdata, effect = "twoways", 
##     model = "within")
## 
## Balanced Panel: n=15, T=93, N=1395
## 
## Residuals :
##    Min. 1st Qu.  Median 3rd Qu.    Max. 
## -2.9700 -0.3610 -0.0228  0.3560  3.1700 
## 
## Coefficients :
##                    Estimate Std. Error t-value Pr(>|t|)    
## TMEANlevels3.fCold  -0.0924     0.0970   -0.95   0.3413    
## TMEANlevels3.fWarm  -0.0042     0.0960   -0.04   0.9652    
## lag(TotalSTD, 1)     0.4889     0.0278   17.60   <2e-16 ***
## lag(TotalSTD, 2)     0.0704     0.0309    2.28   0.0228 *  
## lag(TotalSTD, 3)     0.0813     0.0276    2.94   0.0033 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    787
## Residual Sum of Squares: 520
## R-Squared      :  0.113 
##       Adj. R-Squared :  0.104 
## F-statistic: 131.764 on 5 and 1283 DF, p-value: <2e-16

# Putting County and t in formula to aid with residual plots (see below for
# model with normal formula)
m3g = plm(TotalSTD ~ PRECIPlevels3.f + TMEANlevels3.f + lag(TotalSTD, 1) + lag(TotalSTD, 
    2) + lag(TotalSTD, 3) + factor(t) + County.Area, data = pdata)
summary(m3g)  # sig
## Oneway (individual) effect Within Model
## 
## Call:
## plm(formula = TotalSTD ~ PRECIPlevels3.f + TMEANlevels3.f + lag(TotalSTD, 
##     1) + lag(TotalSTD, 2) + lag(TotalSTD, 3) + factor(t) + County.Area, 
##     data = pdata)
## 
## Balanced Panel: n=15, T=93, N=1395
## 
## Residuals :
##    Min. 1st Qu.  Median 3rd Qu.    Max. 
## -2.9800 -0.3580 -0.0213  0.3540  3.1800 
## 
## Coefficients :
##                     Estimate Std. Error t-value Pr(>|t|)    
## PRECIPlevels3.fDry -0.256173   0.086479   -2.96  0.00311 ** 
## PRECIPlevels3.fWet -0.123414   0.084101   -1.47  0.14250    
## TMEANlevels3.fCold -0.107002   0.096927   -1.10  0.26982    
## TMEANlevels3.fWarm -0.000846   0.095750   -0.01  0.99295    
## lag(TotalSTD, 1)    0.484021   0.027720   17.46  < 2e-16 ***
## lag(TotalSTD, 2)    0.066874   0.030788    2.17  0.03003 *  
## lag(TotalSTD, 3)    0.087924   0.027603    3.19  0.00148 ** 
## factor(t)9          0.408875   0.232927    1.76  0.07943 .  
## factor(t)10         0.317828   0.232133    1.37  0.17119    
## factor(t)11         1.344406   0.232340    5.79  9.0e-09 ***
## factor(t)12        -0.888118   0.234305   -3.79  0.00016 ***
## factor(t)13         0.033176   0.235899    0.14  0.88818    
## factor(t)14         1.216358   0.235863    5.16  2.9e-07 ***
## factor(t)15         0.253459   0.235210    1.08  0.28142    
## factor(t)16         0.616653   0.237081    2.60  0.00940 ** 
## factor(t)17         0.425776   0.232274    1.83  0.06702 .  
## factor(t)18        -0.010795   0.232481   -0.05  0.96297    
## factor(t)19         0.297547   0.232608    1.28  0.20107    
## factor(t)20         0.135045   0.232588    0.58  0.56160    
## factor(t)21        -0.183667   0.233730   -0.79  0.43212    
## factor(t)22         0.056430   0.232243    0.24  0.80806    
## factor(t)23         2.008310   0.235272    8.54  < 2e-16 ***
## factor(t)24        -1.055011   0.240754   -4.38  1.3e-05 ***
## factor(t)25        -0.193563   0.240254   -0.81  0.42059    
## factor(t)26         0.783266   0.236978    3.31  0.00098 ***
## factor(t)27         0.118444   0.234133    0.51  0.61303    
## factor(t)28         0.245314   0.235060    1.04  0.29686    
## factor(t)29         1.023348   0.232491    4.40  1.2e-05 ***
## factor(t)30         0.177738   0.233341    0.76  0.44637    
## factor(t)31         0.402217   0.233379    1.72  0.08505 .  
## factor(t)32         0.027805   0.231999    0.12  0.90462    
## factor(t)33         0.123188   0.232231    0.53  0.59589    
## factor(t)34        -0.157192   0.236087   -0.67  0.50564    
## factor(t)35         1.462959   0.239011    6.12  1.2e-09 ***
## factor(t)36        -0.666511   0.235188   -2.83  0.00467 ** 
## factor(t)37        -0.207582   0.237932   -0.87  0.38313    
## factor(t)38         0.711861   0.234352    3.04  0.00243 ** 
## factor(t)39        -0.009111   0.233900   -0.04  0.96893    
## factor(t)40         0.381213   0.233866    1.63  0.10334    
## factor(t)41         0.763715   0.232032    3.29  0.00102 ** 
## factor(t)42         0.102410   0.234312    0.44  0.66214    
## factor(t)43         0.563015   0.232848    2.42  0.01575 *  
## factor(t)44        -0.170099   0.234326   -0.73  0.46803    
## factor(t)45         0.076684   0.232340    0.33  0.74142    
## factor(t)46        -0.001573   0.238868   -0.01  0.99475    
## factor(t)47         1.212886   0.232193    5.22  2.0e-07 ***
## factor(t)48        -0.750787   0.235610   -3.19  0.00147 ** 
## factor(t)49        -0.371675   0.236034   -1.57  0.11558    
## factor(t)50         0.543085   0.234492    2.32  0.02071 *  
## factor(t)51         0.087867   0.233845    0.38  0.70716    
## factor(t)52         0.388617   0.236681    1.64  0.10085    
## factor(t)53         0.716320   0.232277    3.08  0.00209 ** 
## factor(t)54         0.092591   0.234168    0.40  0.69261    
## factor(t)55         0.183151   0.232706    0.79  0.43140    
## factor(t)56        -0.067439   0.233501   -0.29  0.77277    
## factor(t)57        -0.230592   0.233162   -0.99  0.32286    
## factor(t)58        -0.509256   0.232571   -2.19  0.02873 *  
## factor(t)59         1.192234   0.233487    5.11  3.8e-07 ***
## factor(t)60        -1.090743   0.237644   -4.59  4.9e-06 ***
## factor(t)61        -0.408064   0.238609   -1.71  0.08748 .  
## factor(t)62         0.125373   0.236209    0.53  0.59567    
## factor(t)63        -0.132897   0.236115   -0.56  0.57363    
## factor(t)64         0.020499   0.235183    0.09  0.93056    
## factor(t)65         0.421273   0.233917    1.80  0.07195 .  
## factor(t)66         0.216383   0.235827    0.92  0.35903    
## factor(t)67         0.276140   0.233612    1.18  0.23741    
## factor(t)68        -0.084110   0.232570   -0.36  0.71767    
## factor(t)69        -0.299963   0.232994   -1.29  0.19818    
## factor(t)70        -0.304482   0.233115   -1.31  0.19174    
## factor(t)71         1.054888   0.236092    4.47  8.6e-06 ***
## factor(t)72        -1.076326   0.241704   -4.45  9.2e-06 ***
## factor(t)73        -0.206010   0.241298   -0.85  0.39340    
## factor(t)74         0.498956   0.237760    2.10  0.03605 *  
## factor(t)75         0.033503   0.236581    0.14  0.88741    
## factor(t)76         0.035103   0.235686    0.15  0.88162    
## factor(t)77         0.573707   0.232854    2.46  0.01388 *  
## factor(t)78        -0.059875   0.233525   -0.26  0.79769    
## factor(t)79         0.237796   0.233966    1.02  0.30965    
## factor(t)80        -0.011420   0.232499   -0.05  0.96083    
## factor(t)81        -0.126143   0.232655   -0.54  0.58778    
## factor(t)82        -0.114587   0.239245   -0.48  0.63205    
## factor(t)83         1.541805   0.234075    6.59  6.5e-11 ***
## factor(t)84        -1.189499   0.236385   -5.03  5.5e-07 ***
## factor(t)85        -0.169049   0.239130   -0.71  0.47974    
## factor(t)86         0.659623   0.236493    2.79  0.00536 ** 
## factor(t)87         0.001932   0.235142    0.01  0.99344    
## factor(t)88         0.107644   0.234439    0.46  0.64620    
## factor(t)89         0.703932   0.232317    3.03  0.00249 ** 
## factor(t)90         0.171447   0.233325    0.73  0.46260    
## factor(t)91         0.250168   0.233052    1.07  0.28328    
## factor(t)92         0.201570   0.232212    0.87  0.38553    
## factor(t)93        -0.158734   0.232089   -0.68  0.49414    
## factor(t)94         0.097672   0.232199    0.42  0.67409    
## factor(t)95         1.319495   0.232267    5.68  1.7e-08 ***
## factor(t)96        -1.052974   0.235313   -4.47  8.3e-06 ***
## factor(t)97         0.140831   0.242560    0.58  0.56161    
## factor(t)98         0.717754   0.237067    3.03  0.00251 ** 
## factor(t)99         0.010820   0.234565    0.05  0.96321    
## factor(t)100        0.264233   0.233398    1.13  0.25780    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    1250
## Residual Sum of Squares: 516
## R-Squared      :  0.53 
##       Adj. R-Squared :  0.487 
## F-statistic: 18.3503 on 99 and 1281 DF, p-value: <2e-16
SCtest(m3g)  # non sig serial correlation!
## 
## Call:
## lm(formula = res[-n] ~ res[-1])
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -3.001 -0.356 -0.021  0.354  3.202 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.000178   0.016302    0.01     0.99
## res[-1]     0.010084   0.026801    0.38     0.71
## 
## Residual standard error: 0.609 on 1392 degrees of freedom
## Multiple R-squared:  0.000102,   Adjusted R-squared:  -0.000617 
## F-statistic: 0.142 on 1 and 1392 DF,  p-value: 0.707
xyplot(m3g$residuals ~ fitted(m3g))  # not bad

plot of chunk unnamed-chunk-14

qqPlot(m3g$residuals)  # not terrible

plot of chunk unnamed-chunk-14

plot(m3g$residuals ~ m3f$model[[7]], xlab = "Time", ylab = "Residuals")

plot of chunk unnamed-chunk-14

plot(m3g$residuals ~ m3f$model[[8]], xlab = "County", ylab = "Residuals")

plot of chunk unnamed-chunk-14


# Normal forumla
m3g2 = plm(TotalSTD ~ PRECIPlevels3.f + TMEANlevels3.f + lag(TotalSTD, 1) + 
    lag(TotalSTD, 2) + lag(TotalSTD, 3), data = pdata, model = "within", effect = "twoways")
summary(m3g2)
## Twoways effects Within Model
## 
## Call:
## plm(formula = TotalSTD ~ PRECIPlevels3.f + TMEANlevels3.f + lag(TotalSTD, 
##     1) + lag(TotalSTD, 2) + lag(TotalSTD, 3), data = pdata, effect = "twoways", 
##     model = "within")
## 
## Balanced Panel: n=15, T=93, N=1395
## 
## Residuals :
##    Min. 1st Qu.  Median 3rd Qu.    Max. 
## -2.9800 -0.3580 -0.0213  0.3540  3.1800 
## 
## Coefficients :
##                     Estimate Std. Error t-value Pr(>|t|)    
## PRECIPlevels3.fDry -0.256173   0.086479   -2.96   0.0031 ** 
## PRECIPlevels3.fWet -0.123414   0.084101   -1.47   0.1425    
## TMEANlevels3.fCold -0.107002   0.096927   -1.10   0.2698    
## TMEANlevels3.fWarm -0.000846   0.095750   -0.01   0.9930    
## lag(TotalSTD, 1)    0.484021   0.027720   17.46   <2e-16 ***
## lag(TotalSTD, 2)    0.066874   0.030788    2.17   0.0300 *  
## lag(TotalSTD, 3)    0.087924   0.027603    3.19   0.0015 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    787
## Residual Sum of Squares: 516
## R-Squared      :  0.116 
##       Adj. R-Squared :  0.106 
## F-statistic: 96.2618 on 7 and 1281 DF, p-value: <2e-16
SCtest(m3g2)
## 
## Call:
## lm(formula = res[-n] ~ res[-1])
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -3.001 -0.356 -0.021  0.354  3.202 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.000178   0.016302    0.01     0.99
## res[-1]     0.010084   0.026801    0.38     0.71
## 
## Residual standard error: 0.609 on 1392 degrees of freedom
## Multiple R-squared:  0.000102,   Adjusted R-squared:  -0.000617 
## F-statistic: 0.142 on 1 and 1392 DF,  p-value: 0.707
xyplot(m3g2$residuals ~ fitted(m3g2), xlab = "Fitted", ylab = "Residuals")

plot of chunk unnamed-chunk-14

qqPlot(m3g2$residuals)

plot of chunk unnamed-chunk-14


# Removing outliers
findoutliers = plm(TotalSTD ~ PRECIPlevels3.f + TMEANlevels3.f, effect = "twoways", 
    model = "within", data = pdata)
outliers = which(abs(findoutliers$residuals) > 2)
pdata2 = pdata[-outliers, ]

# New reg without outliers
m3g3 = plm(TotalSTD ~ PRECIPlevels3.f + TMEANlevels3.f + lag(TotalSTD, 1) + 
    lag(TotalSTD, 2) + lag(TotalSTD, 3), effect = "twoways", model = "within", 
    data = pdata2)
summary(m3g3)  # still sig, now also high precipitation (commented on in previous results excluding outliers)
## Twoways effects Within Model
## 
## Call:
## plm(formula = TotalSTD ~ PRECIPlevels3.f + TMEANlevels3.f + lag(TotalSTD, 
##     1) + lag(TotalSTD, 2) + lag(TotalSTD, 3), data = pdata2, 
##     effect = "twoways", model = "within")
## 
## Unbalanced Panel: n=15, T=77-93, N=1331
## 
## Residuals :
##    Min. 1st Qu.  Median 3rd Qu.    Max. 
## -1.7000 -0.3430 -0.0143  0.3470  2.4100 
## 
## Coefficients :
##                    Estimate Std. Error t-value Pr(>|t|)    
## PRECIPlevels3.fDry  -0.2299     0.0817   -2.81   0.0050 ** 
## PRECIPlevels3.fWet  -0.1660     0.0780   -2.13   0.0334 *  
## TMEANlevels3.fCold  -0.0798     0.0923   -0.86   0.3874    
## TMEANlevels3.fWarm  -0.0611     0.0887   -0.69   0.4907    
## lag(TotalSTD, 1)     0.4970     0.0282   17.60   <2e-16 ***
## lag(TotalSTD, 2)     0.0909     0.0315    2.89   0.0039 ** 
## lag(TotalSTD, 3)     0.0471     0.0281    1.67   0.0942 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    625
## Residual Sum of Squares: 407
## R-Squared      :  0.0999 
##       Adj. R-Squared :  0.0914 
## F-statistic: 93.1746 on 7 and 1217 DF, p-value: <2e-16
SCtest(m3g3)
## 
## Call:
## lm(formula = res[-n] ~ res[-1])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.7014 -0.3458 -0.0118  0.3495  2.4111 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)
## (Intercept)  0.000164   0.015173    0.01     0.99
## res[-1]     -0.005085   0.027439   -0.19     0.85
## 
## Residual standard error: 0.553 on 1328 degrees of freedom
## Multiple R-squared:  2.59e-05,   Adjusted R-squared:  -0.000727 
## F-statistic: 0.0343 on 1 and 1328 DF,  p-value: 0.853
xyplot(m3g3$residuals ~ fitted(m3g3))  # looks ok

plot of chunk unnamed-chunk-14

qqPlot(m3g3$residuals)  #looks ok

plot of chunk unnamed-chunk-14

The results for the 3rd set of levels look mostly the same as for the two others. Unusually low levels of precipitation are related to lower retail sales, after accounting for temperature level. Temperature levels are again not significantly related to retail sales. The estimated coefficient for Dry is of lower magnitude than the ones for Drought in the earlier models which makes sense. The varying levels of the coefficient estimates makes us hesitant to conclude anything about the precice magnitude of the relationship between unseasonably low levels of precipitation and retail sales.

Overall, low levels of precipitation are the only consistently significant predictors of retail sales in our models. Most of the variation in retail sales cannot be explained by our weather variables, but there does seem to be small portion that can be. Precisely determining the relationship would require much deeper study. As discussed in our paper, the scope of inference for these results is limited by our non-random selection of counties and small data set.