Verbeek5. Modern Econometrics Using R - Chap 10

### Chapter 10. Models Based on Panel Data

#### TABLE 10.2

library(haven)
library(stargazer)
library(plm)
library(dplyr)
library(AER)

Estimation results wage equation, males 1980-1987

df <- read_dta("Data/males.dta")
df$EXPER2 <- df$EXPER**2
df <- pdata.frame(df, index = c("NR", "YEAR"))

wBetween <- plm(WAGE ~ SCHOOL + EXPER + EXPER2  +  UNION + MAR + BLACK + HISP +
PUB, model="between", data=df)
wFixed = plm(WAGE ~ SCHOOL + EXPER + EXPER2 + UNION + MAR + BLACK + HISP +
PUB, model="within", data=df)
wOLS <- plm(WAGE ~ SCHOOL + EXPER +EXPER2 + UNION + MAR + BLACK + HISP + PUB,
model="pooling", data=df)
wRandom <- plm(WAGE ~ SCHOOL + EXPER + EXPER2 + UNION + MAR + BLACK + HISP + PUB, model="random", data=df, effect = "twoway")
stargazer(wBetween, wFixed, wOLS, wRandom, column.labels = c("Between", "FE", "OLS", "RE"), keep.stat = c("N", "rsq"), no.space = T, type="text")
##
## ====================================================
##                        Dependent variable:
##              ---------------------------------------
##                               WAGE
##               Between     FE        OLS       RE
##                 (1)       (2)       (3)       (4)
## ----------------------------------------------------
## SCHOOL       0.095***            0.099***  0.100***
##               (0.011)             (0.005)   (0.009)
## EXPER         -0.050   0.116***  0.089***  0.116***
##               (0.050)   (0.008)   (0.010)   (0.009)
## EXPER2         0.005   -0.004*** -0.003*** -0.004***
##               (0.003)   (0.001)   (0.001)   (0.001)
## UNION        0.274***  0.081***  0.180***  0.105***
##               (0.047)   (0.019)   (0.017)   (0.018)
## MAR          0.145***   0.045**  0.108***  0.063***
##               (0.041)   (0.018)   (0.016)   (0.017)
## BLACK        -0.139***           -0.144*** -0.144***
##               (0.049)             (0.024)   (0.048)
## HISP           0.005               0.016     0.020
##               (0.043)             (0.021)   (0.043)
## PUB           -0.056     0.035     0.004     0.030
##               (0.109)   (0.039)   (0.037)   (0.036)
## Constant      0.490**             -0.034    -0.098
##               (0.221)             (0.065)   (0.116)
## ----------------------------------------------------
## Observations    545      4,360     4,360     4,360
## R2             0.220     0.178     0.187     0.105
## ====================================================
## Note:                    *p<0.1; **p<0.05; ***p<0.01

#### TABLE 10.3

OLS, within and OLS-FD estimation results dynamic model

df <- read_dta("Data/debtratio.dta") #Unbalanced Panel Data

tlag <- function(x, n = 1L, time) {
index <- match(time - n, time, incomparables = NA)
x[index]
}

df <- df %>%
group_by(gvkey) %>%
mutate(mdrlag = tlag(mdr, 1, time = yeara),
mdrlag2 = tlag(mdr, 2, time = yeara),
dmdr = mdr - tlag(mdr, 1, time = yeara),
dmdrlag = mdrlag - tlag(mdrlag, 1, time = yeara),
dmdrlag2 = tlag(dmdrlag, 1, time = yeara),
dlagebit_ta = lagebit_ta - tlag(lagebit_ta, 1, time = yeara),
dlagmb = lagmb - tlag(lagmb, 1, time = yeara),
dlagdep_ta = lagdep_ta - tlag(lagdep_ta, 1, time = yeara),
dlaglnta = laglnta - tlag(laglnta, 1, time = yeara),
dlagfa_ta = lagfa_ta - tlag(lagfa_ta, 1, time = yeara),
dlagrd_dum = lagrd_dum - tlag(lagrd_dum, 1, time = yeara),
dlagrd_ta = lagrd_ta - tlag(lagrd_ta, 1, time = yeara),
dlagindmedian = lagindmedian - tlag(lagindmedian, 1, time = yeara),
dlagrated = lagrated - tlag(lagrated, 1, time = yeara)
)
form <- mdr ~ mdrlag + lagebit_ta + lagmb + lagdep_ta + laglnta + lagfa_ta + lagrd_dum + lagrd_ta + lagindmedian + lagrated

summary(OLS <- lm(form, data=df))
##
## Call:
## lm(formula = form, data = df)
##
## Residuals:
##      Min       1Q   Median       3Q      Max
## -0.78380 -0.05925 -0.02252  0.05580  0.76923
##
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)
## (Intercept)   0.0581818  0.0108941   5.341 9.36e-08 ***
## mdrlag        0.8835036  0.0045568 193.888  < 2e-16 ***
## lagebit_ta   -0.0323378  0.0057074  -5.666 1.48e-08 ***
## lagmb         0.0016432  0.0007814   2.103 0.035484 *
## lagdep_ta    -0.2605179  0.0334661  -7.785 7.34e-15 ***
## laglnta      -0.0006704  0.0006057  -1.107 0.268405
## lagfa_ta      0.0201215  0.0051479   3.909 9.31e-05 ***
## lagrd_dum     0.0068896  0.0020229   3.406 0.000661 ***
## lagrd_ta     -0.1202051  0.0142376  -8.443  < 2e-16 ***
## lagindmedian  0.0321225  0.0091084   3.527 0.000422 ***
## lagrated      0.0071341  0.0029114   2.450 0.014280 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.1253 on 19562 degrees of freedom
##   (8189 observations deleted due to missingness)
## Multiple R-squared:  0.7409, Adjusted R-squared:  0.7408
## F-statistic:  5595 on 10 and 19562 DF,  p-value: < 2.2e-16
summary(Within <- plm(form, model="within", data=df))
## Oneway (individual) effect Within Model
##
## Call:
## plm(formula = form, data = df, model = "within")
##
## Unbalanced Panel: n = 3777, T = 1-15, N = 19573
##
## Residuals:
##       Min.    1st Qu.     Median    3rd Qu.       Max.
## -0.6174822 -0.0493743 -0.0020841  0.0431051  0.5756810
##
## Coefficients:
##                 Estimate  Std. Error t-value  Pr(>|t|)
## mdrlag        5.3498e-01  7.6646e-03 69.7992 < 2.2e-16 ***
## lagebit_ta   -5.0033e-02  8.0860e-03 -6.1876 6.260e-10 ***
## lagmb         2.2776e-03  1.1358e-03  2.0052   0.04495 *
## lagdep_ta    -1.2395e-01  5.7544e-02 -2.1541   0.03125 *
## laglnta       3.8030e-02  2.0593e-03 18.4678 < 2.2e-16 ***
## lagfa_ta      5.9344e-02  1.2635e-02  4.6969 2.664e-06 ***
## lagrd_dum     5.9768e-05  5.8840e-03  0.0102   0.99190
## lagrd_ta     -6.5676e-02  2.7093e-02 -2.4241   0.01536 *
## lagindmedian  1.6722e-01  1.8959e-02  8.8201 < 2.2e-16 ***
## lagrated      2.0590e-02  4.6521e-03  4.4259 9.670e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares:    307.38
## Residual Sum of Squares: 202.75
## R-Squared:      0.3404
## F-statistic: 814.653 on 10 and 15786 DF, p-value: < 2.22e-16
summary(FD <- plm(dmdr ~ dmdrlag + dlagebit_ta + dlagmb + dlagdep_ta + dlaglnta + dlagfa_ta + dlagrd_dum + dlagrd_ta + dlagindmedian + dlagrated +0, model="pooling", data=df))
## Pooling Model
##
## Call:
## plm(formula = dmdr ~ dmdrlag + dlagebit_ta + dlagmb + dlagdep_ta +
##     dlaglnta + dlagfa_ta + dlagrd_dum + dlagrd_ta + dlagindmedian +
##     dlagrated + 0, data = df, model = "pooling")
##
## Unbalanced Panel: n = 2996, T = 1-14, N = 15039
##
## Residuals:
##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max.
## -0.83303 -0.04583 -0.00160  0.00812  0.05930  0.77226
##
## Coefficients:
##                 Estimate Std. Error  t-value  Pr(>|t|)
## dmdrlag       -0.1104090  0.0093859 -11.7633 < 2.2e-16 ***
## dlagebit_ta   -0.0460275  0.0076391  -6.0252 1.728e-09 ***
## dlagmb         0.0027553  0.0011577   2.3800  0.017327 *
## dlagdep_ta     0.1837711  0.0654743   2.8068  0.005011 **
## dlaglnta       0.0727863  0.0038149  19.0796 < 2.2e-16 ***
## dlagfa_ta      0.1012892  0.0157913   6.4143 1.457e-10 ***
## dlagrd_dum    -0.0173716  0.0078249  -2.2200  0.026430 *
## dlagrd_ta     -0.0516802  0.0278544  -1.8554  0.063563 .
## dlagindmedian  0.1787605  0.0251423   7.1099 1.213e-12 ***
## dlagrated      0.0114568  0.0063668   1.7995  0.071966 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares:    238.04
## Residual Sum of Squares: 232.43
## R-Squared:      0.027872
## F-statistic: 36.286 on 10 and 15029 DF, p-value: < 2.22e-16

#### Table 10.4

IV and GMM estimation results dynamic model

summary(AH1 <- ivreg(dmdr ~ 0 + dmdrlag + dlagebit_ta + dlagmb + dlagdep_ta + dlaglnta + dlagfa_ta + dlagrd_dum + dlagrd_ta + dlagindmedian + dlagrated | . - dmdrlag + dmdrlag2, data=df))
##
## Call:
## ivreg(formula = dmdr ~ 0 + dmdrlag + dlagebit_ta + dlagmb + dlagdep_ta +
##     dlaglnta + dlagfa_ta + dlagrd_dum + dlagrd_ta + dlagindmedian +
##     dlagrated | . - dmdrlag + dmdrlag2, data = df)
##
## Residuals:
##      Min       1Q   Median       3Q      Max
## -5.09229 -0.42934  0.02599  0.42502  8.68711
##
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)
## dmdrlag        8.55515    8.57745   0.997    0.319
## dlagebit_ta    1.48062    1.51993   0.974    0.330
## dlagmb         0.29550    0.28919   1.022    0.307
## dlagdep_ta    -2.43942    2.61657  -0.932    0.351
## dlaglnta      -0.66857    0.73741  -0.907    0.365
## dlagfa_ta     -1.33701    1.43235  -0.933    0.351
## dlagrd_dum    -0.02319    0.06878  -0.337    0.736
## dlagrd_ta      1.06815    1.14790   0.931    0.352
## dlagindmedian -4.11835    4.26046  -0.967    0.334
## dlagrated     -0.33763    0.35064  -0.963    0.336
##
## Residual standard error: 0.924 on 11722 degrees of freedom
## Multiple R-Squared: -55.61,  Adjusted R-squared: -55.66
## Wald test: 0.6109 on 10 and 11722 DF,  p-value: 0.8059
summary(AH2 <- ivreg(dmdr ~ 0 + dmdrlag + dlagebit_ta + dlagmb + dlagdep_ta + dlaglnta + dlagfa_ta + dlagrd_dum + dlagrd_ta + dlagindmedian + dlagrated | . - dmdrlag + mdrlag2, data=df))
##
## Call:
## ivreg(formula = dmdr ~ 0 + dmdrlag + dlagebit_ta + dlagmb + dlagdep_ta +
##     dlaglnta + dlagfa_ta + dlagrd_dum + dlagrd_ta + dlagindmedian +
##     dlagrated | . - dmdrlag + mdrlag2, data = df)
##
## Residuals:
##      Min       1Q   Median       3Q      Max
## -1.37975 -0.07620  0.00654  0.08633  1.09717
##
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)
## dmdrlag        1.124607   0.313929   3.582 0.000342 ***
## dlagebit_ta    0.162941   0.054237   3.004 0.002667 **
## dlagmb         0.039781   0.009555   4.164 3.15e-05 ***
## dlagdep_ta    -0.150639   0.128208  -1.175 0.240028
## dlaglnta      -0.031919   0.027172  -1.175 0.240128
## dlagfa_ta     -0.123924   0.061705  -2.008 0.044627 *
## dlagrd_dum    -0.020626   0.011509  -1.792 0.073123 .
## dlagrd_ta      0.099272   0.056028   1.772 0.076445 .
## dlagindmedian -0.462765   0.167036  -2.770 0.005605 **
## dlagrated     -0.041951   0.016468  -2.548 0.010860 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.1824 on 15029 degrees of freedom
## Multiple R-Squared: -1.082,  Adjusted R-squared: -1.083
## Wald test: 18.31 on 10 and 15029 DF,  p-value: < 2.2e-16