Chapter13: Simple Panel Data Methods

library(wooldridge)

Example 13.1

data("fertil1")

s.lm.1 <- summary(lm.1 <- lm(kids ~ educ + age + agesq + black + east + northcen + west +
                          farm + othrural + town + smcity +
                          y74 + y76 + y78 + y80 + y82 + y84, data = fertil1))

s.lm.1
## 
## Call:
## lm(formula = kids ~ educ + age + agesq + black + east + northcen + 
##     west + farm + othrural + town + smcity + y74 + y76 + y78 + 
##     y80 + y82 + y84, data = fertil1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.9878 -1.0086 -0.0767  0.9331  4.6548 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -7.742457   3.051767  -2.537 0.011315 *  
## educ        -0.128427   0.018349  -6.999 4.44e-12 ***
## age          0.532135   0.138386   3.845 0.000127 ***
## agesq       -0.005804   0.001564  -3.710 0.000217 ***
## black        1.075658   0.173536   6.198 8.02e-10 ***
## east         0.217324   0.132788   1.637 0.101992    
## northcen     0.363114   0.120897   3.004 0.002729 ** 
## west         0.197603   0.166913   1.184 0.236719    
## farm        -0.052557   0.147190  -0.357 0.721105    
## othrural    -0.162854   0.175442  -0.928 0.353481    
## town         0.084353   0.124531   0.677 0.498314    
## smcity       0.211879   0.160296   1.322 0.186507    
## y74          0.268183   0.172716   1.553 0.120771    
## y76         -0.097379   0.179046  -0.544 0.586633    
## y78         -0.068666   0.181684  -0.378 0.705544    
## y80         -0.071305   0.182771  -0.390 0.696511    
## y82         -0.522484   0.172436  -3.030 0.002502 ** 
## y84         -0.545166   0.174516  -3.124 0.001831 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.555 on 1111 degrees of freedom
## Multiple R-squared:  0.1295, Adjusted R-squared:  0.1162 
## F-statistic: 9.723 on 17 and 1111 DF,  p-value: < 2.2e-16
s.lm.2 <- summary(lm.2 <- lm(kids ~ educ + age + agesq + black + east + northcen + west +
                          farm + othrural + town + smcity,data = fertil1))

anova(lm.1, lm.2)
## Analysis of Variance Table
## 
## Model 1: kids ~ educ + age + agesq + black + east + northcen + west + 
##     farm + othrural + town + smcity + y74 + y76 + y78 + y80 + 
##     y82 + y84
## Model 2: kids ~ educ + age + agesq + black + east + northcen + west + 
##     farm + othrural + town + smcity
##   Res.Df    RSS Df Sum of Sq      F    Pr(>F)    
## 1   1111 2685.9                                  
## 2   1117 2771.0 -6   -85.139 5.8695 4.855e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Example 13.2

data("cps78_85")

s.lm.1 <- summary(lm.1 <- lm(lwage ~ y85 + educ + y85educ + exper + expersq +
                               union + female + y85fem, data = cps78_85))

s.lm.1
## 
## Call:
## lm(formula = lwage ~ y85 + educ + y85educ + exper + expersq + 
##     union + female + y85fem, data = cps78_85)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.56098 -0.25828  0.00864  0.26571  2.11669 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  4.589e-01  9.345e-02   4.911 1.05e-06 ***
## y85          1.178e-01  1.238e-01   0.952   0.3415    
## educ         7.472e-02  6.676e-03  11.192  < 2e-16 ***
## y85educ      1.846e-02  9.354e-03   1.974   0.0487 *  
## exper        2.958e-02  3.567e-03   8.293 3.27e-16 ***
## expersq     -3.994e-04  7.754e-05  -5.151 3.08e-07 ***
## union        2.021e-01  3.029e-02   6.672 4.03e-11 ***
## female      -3.167e-01  3.662e-02  -8.648  < 2e-16 ***
## y85fem       8.505e-02  5.131e-02   1.658   0.0977 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4127 on 1075 degrees of freedom
## Multiple R-squared:  0.4262, Adjusted R-squared:  0.4219 
## F-statistic:  99.8 on 8 and 1075 DF,  p-value: < 2.2e-16

Example 13.3

data("kielmc")

s.lm.1 <- summary(lm.1 <- lm(rprice ~ nearinc, data = kielmc[kielmc$year==1981,]))
s.lm.1
## 
## Call:
## lm(formula = rprice ~ nearinc, data = kielmc[kielmc$year == 1981, 
##     ])
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -60678 -19832  -2997  21139 136754 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   101308       3093  32.754  < 2e-16 ***
## nearinc       -30688       5828  -5.266 5.14e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 31240 on 140 degrees of freedom
## Multiple R-squared:  0.1653, Adjusted R-squared:  0.1594 
## F-statistic: 27.73 on 1 and 140 DF,  p-value: 5.139e-07
s.lm.2 <- summary(lm.2 <- lm(rprice ~ nearinc, data = kielmc[kielmc$year == 1978,]))
s.lm.2
## 
## Call:
## lm(formula = rprice ~ nearinc, data = kielmc[kielmc$year == 1978, 
##     ])
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -56517 -16605  -3193   8683 236307 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    82517       2654  31.094  < 2e-16 ***
## nearinc       -18824       4745  -3.968 0.000105 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 29430 on 177 degrees of freedom
## Multiple R-squared:  0.08167,    Adjusted R-squared:  0.07648 
## F-statistic: 15.74 on 1 and 177 DF,  p-value: 0.0001054
s.lm.3.1 <- summary(lm.3.1 <- lm(rprice ~ y81 + nearinc + y81nrinc, data = kielmc))
s.lm.3.1
## 
## Call:
## lm(formula = rprice ~ y81 + nearinc + y81nrinc, data = kielmc)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -60678 -17693  -3031  12483 236307 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    82517       2727  30.260  < 2e-16 ***
## y81            18790       4050   4.640 5.12e-06 ***
## nearinc       -18824       4875  -3.861 0.000137 ***
## y81nrinc      -11864       7457  -1.591 0.112595    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 30240 on 317 degrees of freedom
## Multiple R-squared:  0.1739, Adjusted R-squared:  0.1661 
## F-statistic: 22.25 on 3 and 317 DF,  p-value: 4.224e-13
s.lm.3.2 <- summary(lm.3.2 <- lm(rprice ~ y81 + nearinc + y81nrinc + age + agesq, data = kielmc))
s.lm.3.2
## 
## Call:
## lm(formula = rprice ~ y81 + nearinc + y81nrinc + age + agesq, 
##     data = kielmc)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -79349 -14431  -1711  10069 201486 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  8.912e+04  2.406e+03  37.039  < 2e-16 ***
## y81          2.132e+04  3.444e+03   6.191 1.86e-09 ***
## nearinc      9.398e+03  4.812e+03   1.953 0.051713 .  
## y81nrinc    -2.192e+04  6.360e+03  -3.447 0.000644 ***
## age         -1.494e+03  1.319e+02 -11.333  < 2e-16 ***
## agesq        8.691e+00  8.481e-01  10.248  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 25540 on 315 degrees of freedom
## Multiple R-squared:  0.4144, Adjusted R-squared:  0.4052 
## F-statistic: 44.59 on 5 and 315 DF,  p-value: < 2.2e-16
s.lm.3.3 <- summary(lm.3.3 <- lm(rprice ~ y81 + nearinc + y81nrinc + age + agesq +
                                   intst + land + area + rooms + baths, data = kielmc))
s.lm.3.3
## 
## Call:
## lm(formula = rprice ~ y81 + nearinc + y81nrinc + age + agesq + 
##     intst + land + area + rooms + baths, data = kielmc)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -76721  -8885   -252   8433 136649 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.381e+04  1.117e+04   1.237  0.21720    
## y81          1.393e+04  2.799e+03   4.977 1.07e-06 ***
## nearinc      3.780e+03  4.453e+03   0.849  0.39661    
## y81nrinc    -1.418e+04  4.987e+03  -2.843  0.00477 ** 
## age         -7.395e+02  1.311e+02  -5.639 3.85e-08 ***
## agesq        3.453e+00  8.128e-01   4.248 2.86e-05 ***
## intst       -5.386e-01  1.963e-01  -2.743  0.00643 ** 
## land         1.414e-01  3.108e-02   4.551 7.69e-06 ***
## area         1.809e+01  2.306e+00   7.843 7.16e-14 ***
## rooms        3.304e+03  1.661e+03   1.989  0.04758 *  
## baths        6.977e+03  2.581e+03   2.703  0.00725 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 19620 on 310 degrees of freedom
## Multiple R-squared:   0.66,  Adjusted R-squared:  0.6491 
## F-statistic: 60.19 on 10 and 310 DF,  p-value: < 2.2e-16
s.lm.4.1 <- summary(lm.4.1 <- lm(lprice ~ y81 + nearinc + y81nrinc, data = kielmc))
s.lm.4.1
## 
## Call:
## lm(formula = lprice ~ y81 + nearinc + y81nrinc, data = kielmc)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.11957 -0.20328  0.02226  0.18909  1.66604 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 11.28542    0.03051 369.839  < 2e-16 ***
## y81          0.45700    0.04532  10.084  < 2e-16 ***
## nearinc     -0.33992    0.05456  -6.231 1.48e-09 ***
## y81nrinc    -0.06265    0.08344  -0.751    0.453    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3384 on 317 degrees of freedom
## Multiple R-squared:  0.4091, Adjusted R-squared:  0.4035 
## F-statistic: 73.15 on 3 and 317 DF,  p-value: < 2.2e-16
s.lm.4.2 <- summary(lm.4.2 <- lm(lrprice ~ y81 + nearinc + y81nrinc + age + agesq + 
                                   lintst + lland + larea + rooms + baths, data = kielmc))
s.lm.4.2
## 
## Call:
## lm(formula = lrprice ~ y81 + nearinc + y81nrinc + age + agesq + 
##     lintst + lland + larea + rooms + baths, data = kielmc)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.18441 -0.09947  0.01478  0.10985  0.74872 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  7.652e+00  4.159e-01  18.399  < 2e-16 ***
## y81          1.621e-01  2.850e-02   5.687 2.99e-08 ***
## nearinc      3.223e-02  4.749e-02   0.679 0.497805    
## y81nrinc    -1.315e-01  5.197e-02  -2.531 0.011885 *  
## age         -8.359e-03  1.411e-03  -5.924 8.36e-09 ***
## agesq        3.764e-05  8.668e-06   4.342 1.92e-05 ***
## lintst      -6.145e-02  3.151e-02  -1.950 0.052045 .  
## lland        9.985e-02  2.449e-02   4.077 5.81e-05 ***
## larea        3.508e-01  5.149e-02   6.813 4.98e-11 ***
## rooms        4.733e-02  1.733e-02   2.732 0.006661 ** 
## baths        9.428e-02  2.773e-02   3.400 0.000761 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2038 on 310 degrees of freedom
## Multiple R-squared:  0.7326, Adjusted R-squared:  0.7239 
## F-statistic: 84.92 on 10 and 310 DF,  p-value: < 2.2e-16

Example 13.4

data("injury")

s.lm.1 <- summary(lm.1 <- lm(ldurat ~ afchnge + highearn + afhigh, data = injury))
s.lm.1
## 
## Call:
## lm(formula = ldurat ~ afchnge + highearn + afhigh, data = injury)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.0128 -0.7214 -0.0171  0.7714  4.0047 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.19934    0.02711  44.241  < 2e-16 ***
## afchnge      0.02364    0.03970   0.595  0.55164    
## highearn     0.21520    0.04336   4.963 7.11e-07 ***
## afhigh       0.18835    0.06279   2.999  0.00271 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.298 on 7146 degrees of freedom
## Multiple R-squared:  0.01584,    Adjusted R-squared:  0.01543 
## F-statistic: 38.34 on 3 and 7146 DF,  p-value: < 2.2e-16

Hmmm, more observations in this estimation and the results differ…

Section 13.3

data("crime2")

s.lm.1 <- summary(lm.1 <- lm(crmrte ~ unem, data = crime2[crime2$year == 87,]))
s.lm.1
## 
## Call:
## lm(formula = crmrte ~ unem, data = crime2[crime2$year == 87, 
##     ])
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -57.55 -27.01 -10.56  18.01  79.75 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  128.378     20.757   6.185  1.8e-07 ***
## unem          -4.161      3.416  -1.218     0.23    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 34.6 on 44 degrees of freedom
## Multiple R-squared:  0.03262,    Adjusted R-squared:  0.01063 
## F-statistic: 1.483 on 1 and 44 DF,  p-value: 0.2297
s.lm.2 <- summary(lm.2 <- lm(crmrte ~ d87 + unem, data = crime2))
s.lm.2
## 
## Call:
## lm(formula = crmrte ~ d87 + unem, data = crime2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -53.474 -21.794  -6.266  18.297  75.113 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  93.4202    12.7395   7.333 9.92e-11 ***
## d87           7.9404     7.9753   0.996    0.322    
## unem          0.4265     1.1883   0.359    0.720    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 29.99 on 89 degrees of freedom
## Multiple R-squared:  0.01221,    Adjusted R-squared:  -0.009986 
## F-statistic: 0.5501 on 2 and 89 DF,  p-value: 0.5788

Generate differences

crmrte.d <- crime2$crmrte[seq(2,length(crime2$unem), by = 2)] - crime2$crmrte[seq(1, (length(crime2$unem) - 1), by = 2)]
unem.d <- crime2$unem[seq(2, length(crime2$unem), by = 2)] - crime2$unem[seq(1, (length(crime2$unem) - 1), by = 2)]

I suppose there is a better way to do this. I will revise it when I go througth the new edition of the textbook.

Estimate

s.lm.3 <- summary(lm.3 <- lm(crmrte.d ~ unem.d))
s.lm.3
## 
## Call:
## lm(formula = crmrte.d ~ unem.d)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -36.912 -13.369  -5.507  12.446  52.915 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)   
## (Intercept)  15.4022     4.7021   3.276  0.00206 **
## unem.d        2.2180     0.8779   2.527  0.01519 * 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 20.05 on 44 degrees of freedom
## Multiple R-squared:  0.1267, Adjusted R-squared:  0.1069 
## F-statistic: 6.384 on 1 and 44 DF,  p-value: 0.01519

Example 13.5

data("slp75_81")

with(slp75_81, {
     d.slpnap <- slpnap81-slpnap75
     d.totwrk <- totwrk81-totwrk75
     d.educ <- educ81-educ75
     d.marr <- marr81-marr75
     d.yngkid <- yngkid81-yngkid75
     d.gdhlth <- gdhlth81-gdhlth75
     summary(lm(d.slpnap ~ d.totwrk + d.educ + d.marr + d.yngkid + d.gdhlth))
    })
## 
## Call:
## lm(formula = d.slpnap ~ d.totwrk + d.educ + d.marr + d.yngkid + 
##     d.gdhlth)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2454.2  -307.2    79.8   334.4  2037.9 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -92.63404   45.86590  -2.020   0.0446 *  
## d.totwrk     -0.22667    0.03605  -6.287 1.58e-09 ***
## d.educ       -0.02447   48.75938  -0.001   0.9996    
## d.marr      104.21395   92.85536   1.122   0.2629    
## d.yngkid     94.66540   87.65252   1.080   0.2813    
## d.gdhlth     87.57785   76.59913   1.143   0.2541    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 598.6 on 233 degrees of freedom
## Multiple R-squared:  0.1495, Adjusted R-squared:  0.1313 
## F-statistic: 8.191 on 5 and 233 DF,  p-value: 3.827e-07

Example 13.6

data("crime3")

with(crime3, {
  d.lcrime <- lcrime[year==78] - lcrime[year==72]
  d.clrprc1 <- clrprc1[year==78] - clrprc1[year==72]
  d.clrprc2 <- clrprc2[year==78] - clrprc2[year==72]
  summary(lm(d.lcrime ~ d.clrprc1 + d.clrprc2))
})
## 
## Call:
## lm(formula = d.lcrime ~ d.clrprc1 + d.clrprc2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.0335 -0.2351  0.0299  0.2178  0.8263 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)  
## (Intercept)  0.085656   0.063782   1.343   0.1854  
## d.clrprc1   -0.004048   0.004720  -0.858   0.3952  
## d.clrprc2   -0.013197   0.005195  -2.540   0.0142 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3446 on 50 degrees of freedom
## Multiple R-squared:  0.1933, Adjusted R-squared:  0.1611 
## F-statistic: 5.992 on 2 and 50 DF,  p-value: 0.004649

Section 13.4

data("jtrain")

with(jtrain, {
  d.scrap <- scrap[year == 1988] - scrap[year == 1987]
  d.grant <- grant[year == 1988] - grant[year == 1987]
  summary(lm(d.scrap ~ d.grant))
})
## 
## Call:
## lm(formula = d.scrap ~ d.grant)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -9.4363 -0.0638  0.5437  0.8283  5.5637 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept)  -0.5637     0.4049  -1.392    0.170
## d.grant      -0.7394     0.6826  -1.083    0.284
## 
## Residual standard error: 2.396 on 52 degrees of freedom
##   (103 observations deleted due to missingness)
## Multiple R-squared:  0.02207,    Adjusted R-squared:  0.003261 
## F-statistic: 1.173 on 1 and 52 DF,  p-value: 0.2837

With logs of scrap

with(jtrain, {
  d.lscrap <- lscrap[year == 1988] - lscrap[year == 1987]
  d.grant <- grant[year == 1988] - grant[year == 1987]
  summary(lm(d.lscrap ~ d.grant))
})
## 
## Call:
## lm(formula = d.lscrap ~ d.grant)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.1277 -0.2372  0.0237  0.2142  2.4553 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)  
## (Intercept) -0.05744    0.09721  -0.591   0.5572  
## d.grant     -0.31706    0.16388  -1.935   0.0585 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.5751 on 52 degrees of freedom
##   (103 observations deleted due to missingness)
## Multiple R-squared:  0.06715,    Adjusted R-squared:  0.04921 
## F-statistic: 3.743 on 1 and 52 DF,  p-value: 0.05847

Example 13.7

data("traffic1")

with(traffic1, {
  d.dthrte <- dthrte90 - dthrte85
  d.open <- open90 - open85
  d.admn <- admn90 - admn85
  summary(lm(d.dthrte ~ d.open + d.admn))
})
## 
## Call:
## lm(formula = d.dthrte ~ d.open + d.admn)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.25261 -0.14337 -0.00321  0.19679  0.79679 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.49679    0.05243  -9.476 1.43e-12 ***
## d.open      -0.41968    0.20559  -2.041   0.0467 *  
## d.admn      -0.15060    0.11682  -1.289   0.2035    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3435 on 48 degrees of freedom
## Multiple R-squared:  0.1187, Adjusted R-squared:  0.08194 
## F-statistic: 3.231 on 2 and 48 DF,  p-value: 0.04824

Example 13.8

data("ezunem")

with(ezunem,{
  d.luclms <- luclms[year == 1981] - luclms[year == 1980]
  d.luclms <- append(d.luclms, luclms[year == 1982] - luclms[year == 1981])
  d.luclms <- append(d.luclms, luclms[year == 1983] - luclms[year == 1982])
  d.luclms <- append(d.luclms, luclms[year == 1984] - luclms[year == 1983])
  d.luclms <- append(d.luclms, luclms[year == 1985] - luclms[year == 1984])
  d.luclms <- append(d.luclms, luclms[year == 1986] - luclms[year == 1985])
  d.luclms <- append(d.luclms, luclms[year == 1987] - luclms[year == 1986])
  d.luclms <- append(d.luclms, luclms[year == 1988] - luclms[year == 1987])  
  
  d.ez <- ez[year == 1981] - ez[year == 1980]
  d.ez <- append(d.ez, ez[year == 1982] - ez[year == 1981])
  d.ez <- append(d.ez, ez[year == 1983] - ez[year == 1982])
  d.ez <- append(d.ez, ez[year == 1984] - ez[year == 1983])
  d.ez <- append(d.ez, ez[year == 1985] - ez[year == 1984])
  d.ez <- append(d.ez, ez[year == 1986] - ez[year == 1985])
  d.ez <- append(d.ez, ez[year == 1987] - ez[year == 1986])
  d.ez <- append(d.ez, ez[year == 1988] - ez[year == 1987])
  
  d.82 <- c()
  for (i in 1981:1988) {
    d.82 <- append(d.82,d82[year == i] - d82[year == (i - 1)])
  }
  
  d.83 <- c()
  for (i in 1981:1988) {
    d.83 <- append(d.83,d83[year == i] - d83[year == (i - 1)])
  }
  
  d.84 <- c()
  for (i in 1981:1988) {
    d.84 <- append(d.84,d84[year == i] - d84[year == (i - 1)])
  }
  
  d.85 <- c()
  for (i in 1981:1988) {
    d.85 <- append(d.85,d85[year == i] - d85[year == (i - 1)])
  }
  
  d.86 <- c()
  for (i in 1981:1988) {
    d.86 <- append(d.86,d86[year == i] - d86[year == (i - 1)])
  }
  
  d.87 <- c()
  for (i in 1981:1988) {
    d.87 <- append(d.87,d87[year == i] - d87[year == (i - 1)])
  }
  
  d.88 <- c()
  for (i in 1981:1988) {
    d.88 <- append(d.88,d88[year == i] - d88[year == (i - 1)])
  }
  
  summary(lm(d.luclms ~ d.ez + d.82 + d.83 + d.84 + d.85 + d.86 + d.87 + d.88))
})
## 
## Call:
## lm(formula = d.luclms ~ d.ez + d.82 + d.83 + d.84 + d.85 + d.86 + 
##     d.87 + d.88)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.4925 -0.1427 -0.0092  0.1495  0.6062 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.32163    0.04606  -6.982 6.55e-11 ***
## d.ez        -0.18188    0.07819  -2.326 0.021209 *  
## d.82         0.77876    0.06514  11.954  < 2e-16 ***
## d.83         0.74564    0.11283   6.608 4.99e-10 ***
## d.84         0.72850    0.16099   4.525 1.14e-05 ***
## d.85         1.05158    0.20905   5.030 1.25e-06 ***
## d.86         1.34374    0.25479   5.274 4.09e-07 ***
## d.87         1.39769    0.30064   4.649 6.74e-06 ***
## d.88         1.38063    0.34654   3.984 0.000101 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2161 on 167 degrees of freedom
## Multiple R-squared:  0.623,  Adjusted R-squared:  0.6049 
## F-statistic:  34.5 on 8 and 167 DF,  p-value: < 2.2e-16

Example 13.9

data("crime4")

with(crime4, {
  d.lcrmrte <- c()
  for (i in 82:87) {
    d.lcrmrte <- append(d.lcrmrte, lcrmrte[year==i] - lcrmrte[year==(i - 1)])
  }
  
  d.lprbarr <- c()
  for (i in 82:87) {
    d.lprbarr <- append(d.lprbarr, lprbarr[year==i] - lprbarr[year==(i - 1)])
  }
  
  d.lprbconv <- c()
  for (i in 82:87) {
    d.lprbconv <- append(d.lprbconv, lprbconv[year==i] - lprbconv[year==(i - 1)])
  }
  
  d.lprbpris <- c()
  for (i in 82:87) {
    d.lprbpris <- append(d.lprbpris, lprbpris[year==i] - lprbpris[year==(i - 1)])
  }
  
  d.lavgsen <- c()
  for (i in 82:87) {
    d.lavgsen <- append(d.lavgsen, lavgsen[year==i] - lavgsen[year==(i - 1)])
  }
  
  d.lpolpc <- c()
  for (i in 82:87) {
    d.lpolpc <- append(d.lpolpc, lpolpc[year==i] - lpolpc[year==(i - 1)])
  }
  
  d.83 <- c()
  for (i in 82:87) {
    d.83 <- append(d.83, d83[year==i] - d83[year==(i - 1)])
  }

  d.84 <- c()
  for (i in 82:87) {
    d.84 <- append(d.84, d84[year==i] - d84[year==(i - 1)])
  }
  
  d.85 <- c()
  for (i in 82:87) {
    d.85 <- append(d.85, d85[year==i] - d85[year==(i - 1)])
  }
  
  d.86 <- c()
  for (i in 82:87) {
    d.86 <- append(d.86, d86[year==i] - d86[year==(i - 1)])
  }
  
  d.87 <- c()
  for (i in 82:87) {
    d.87 <- append(d.87, d87[year==i] - d87[year==(i - 1)])
  }
    
  summary(lm(d.lcrmrte ~ d.83 + d.84 + d.85 + d.86 + d.87 + d.lprbarr + d.lprbconv +
               d.lprbpris + d.lavgsen + d.lpolpc))
})
## 
## Call:
## lm(formula = d.lcrmrte ~ d.83 + d.84 + d.85 + d.86 + d.87 + d.lprbarr + 
##     d.lprbconv + d.lprbpris + d.lavgsen + d.lpolpc)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.65936 -0.07838  0.00296  0.07504  0.68307 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.007713   0.017058   0.452 0.651320    
## d.83        -0.099866   0.023895  -4.179 3.42e-05 ***
## d.84        -0.147803   0.041279  -3.581 0.000374 ***
## d.85        -0.152414   0.058400  -2.610 0.009315 ** 
## d.86        -0.124900   0.076004  -1.643 0.100909    
## d.87        -0.084073   0.094000  -0.894 0.371518    
## d.lprbarr   -0.327494   0.029980 -10.924  < 2e-16 ***
## d.lprbconv  -0.238107   0.018234 -13.058  < 2e-16 ***
## d.lprbpris  -0.165046   0.025969  -6.356 4.49e-10 ***
## d.lavgsen   -0.021761   0.022091  -0.985 0.325050    
## d.lpolpc     0.398426   0.026882  14.821  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1543 on 529 degrees of freedom
## Multiple R-squared:  0.4325, Adjusted R-squared:  0.4218 
## F-statistic: 40.32 on 10 and 529 DF,  p-value: < 2.2e-16