Verbeek5. Modern Econometrics Using R - Chap 5

### Chapter 5. Endogeneity, Instrumental Variables and GMM

#### Table 5.1

library(haven)
library(AER)
library(stargazer)
library(gmm)

Wage equation estimated by OLS

df <- read_dta("Data/schooling.dta")
df$exp76sq <- df$exp76**2
summary(OLS1 <- lm(lwage76 ~ ed76 + exp76 + exp76sq + black + smsa76 + south76, data=df))
##
## Call:
## lm(formula = lwage76 ~ ed76 + exp76 + exp76sq + black + smsa76 +
##     south76, data = df)
##
## Residuals:
##      Min       1Q   Median       3Q      Max
## -1.59297 -0.22315  0.01893  0.24223  1.33190
##
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)
## (Intercept)  4.7336643  0.0676026  70.022  < 2e-16 ***
## ed76         0.0740090  0.0035054  21.113  < 2e-16 ***
## exp76        0.0835958  0.0066478  12.575  < 2e-16 ***
## exp76sq     -0.0022409  0.0003178  -7.050 2.21e-12 ***
## black       -0.1896315  0.0176266 -10.758  < 2e-16 ***
## smsa76       0.1614230  0.0155733  10.365  < 2e-16 ***
## south76     -0.1248615  0.0151182  -8.259  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.3742 on 3003 degrees of freedom
## Multiple R-squared:  0.2905, Adjusted R-squared:  0.2891
## F-statistic: 204.9 on 6 and 3003 DF,  p-value: < 2.2e-16

#### Table 5.2

Reduced form for schooling, estimated by OLS

df$age76sq <- df$age76**2
summary(OLS2 <- lm(ed76 ~ age76 + age76sq + black + smsa76 + south76 + nearc4, data=df))
##
## Call:
## lm(formula = ed76 ~ age76 + age76sq + black + smsa76 + south76 +
##     nearc4, data = df)
##
## Residuals:
##     Min      1Q  Median      3Q     Max
## -12.511  -1.722  -0.296   1.876   7.199
##
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.869524   4.298357  -0.435 0.663638
## age76        1.061441   0.301398   3.522 0.000435 ***
## age76sq     -0.018760   0.005231  -3.586 0.000341 ***
## black       -1.468367   0.115443 -12.719  < 2e-16 ***
## smsa76       0.835403   0.109252   7.647 2.76e-14 ***
## south76     -0.459700   0.102434  -4.488 7.47e-06 ***
## nearc4       0.347105   0.106997   3.244 0.001191 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.516 on 3003 degrees of freedom
## Multiple R-squared:  0.1185, Adjusted R-squared:  0.1168
## F-statistic: 67.29 on 6 and 3003 DF,  p-value: < 2.2e-16

#### Table 5.3

Wage equation estimated by IV

summary(IV1 <- ivreg(lwage76 ~ ed76 + exp76 + exp76sq + black + smsa76 + south76 | age76 + age76sq + nearc4 + black + smsa76 + south76, data=df))
##
## Call:
## ivreg(formula = lwage76 ~ ed76 + exp76 + exp76sq + black + smsa76 +
##     south76 | age76 + age76sq + nearc4 + black + smsa76 + south76,
##     data = df)
##
## Residuals:
##      Min       1Q   Median       3Q      Max
## -1.82400 -0.25248  0.02286  0.26349  1.31561
##
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)
## (Intercept)  4.0656674  0.6084961   6.682 2.81e-11 ***
## ed76         0.1329473  0.0513794   2.588 0.009712 **
## exp76        0.0559614  0.0259944   2.153 0.031412 *
## exp76sq     -0.0007957  0.0013403  -0.594 0.552797
## black       -0.1031403  0.0773729  -1.333 0.182624
## smsa76       0.1079848  0.0497399   2.171 0.030010 *
## south76     -0.0981752  0.0287645  -3.413 0.000651 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.4032 on 3003 degrees of freedom
## Multiple R-Squared: 0.1764,  Adjusted R-squared: 0.1747
## Wald test: 148.1 on 6 and 3003 DF,  p-value: < 2.2e-16

#### Table 5.4

OLS results explaining GDP per capita

df <- read_dta("Data/institutions.dta")
OLS3 <- lm(loggdp ~ qi + latitude, data=df)
OLS4 <- lm(loggdp ~ qi + latitude + africa + asia + malfal94, data=df)
stargazer(OLS3, OLS4, no.space=TRUE, type="text",
keep.stat=c("n", "rsq" ), title = "Table 5.4 OLS results explaining GDP per capita")
##
## Table 5.4 OLS results explaining GDP per capita
## =========================================
##                  Dependent variable:
##              ----------------------------
##                         loggdp
##                   (1)            (2)
## -----------------------------------------
## qi              0.468***      0.364***
##                 (0.064)        (0.056)
## latitude        1.577**         0.234
##                 (0.710)        (0.625)
## africa                         -0.414*
##                                (0.226)
## asia                          -0.457**
##                                (0.221)
## malfal94                      -0.788***
##                                (0.278)
## Constant        4.728***      6.178***
##                 (0.397)        (0.404)
## -----------------------------------------
## Observations       64            62
## R2               0.574          0.740
## =========================================
## Note:         *p<0.1; **p<0.05; ***p<0.01

#### Table 5.5

Table 5.5 OLS results reduced form (QI explained from exogenous variables

OLS5a <- lm(qi ~ logem4 + latitude, data=df)
OLS5b <- lm(qi ~ logem4 + euro1900 + latitude, data=df)
OLS6a <- lm(qi ~ logem4 + latitude + africa + asia + malfal94, data=df)
OLS6b <- lm(qi ~ logem4 + euro1900 + latitude + africa + asia + malfal94, data=df)
stargazer(OLS5a, OLS5b, OLS6a, OLS6b, no.space=TRUE, type="text",
keep.stat=c("n", "rsq"),
title = "Table 5.5 OLS results reduced form (QI explained from exogenous variables)")
##
## Table 5.5 OLS results reduced form (QI explained from exogenous variables)
## =================================================
##                      Dependent variable:
##              ------------------------------------
##                               qi
##                 (1)      (2)      (3)      (4)
## -------------------------------------------------
## logem4       -0.510*** -0.368**  -0.328   -0.031
##               (0.141)  (0.149)  (0.199)  (0.187)
## euro1900               0.021**           0.044***
##                        (0.008)           (0.010)
## latitude       2.002    0.200    1.888    -1.654
##               (1.337)  (1.495)  (1.457)  (1.515)
## africa                           0.135   1.272**
##                                 (0.527)  (0.531)
## asia                             0.487   1.989***
##                                 (0.519)  (0.572)
## malfal94                         -0.774  -1.241**
##                                 (0.695)  (0.617)
## Constant     8.529***  7.853*** 7.872*** 5.861***
##               (0.812)  (0.831)  (0.963)  (0.962)
## -------------------------------------------------
## Observations    64        63       62       62
## R2             0.296    0.367    0.322    0.493
## =================================================
## Note:                 *p<0.1; **p<0.05; ***p<0.01

#### Table 5.6

IV results explaining GDP per capita

IV2a = ivreg(loggdp ~ qi + latitude | latitude + logem4, data=df)
IV2b = ivreg(loggdp ~ qi + latitude | latitude + logem4 + euro1900, data=df)
IV3a = ivreg(loggdp ~ qi + latitude + africa + asia + malfal94 | latitude + africa + asia + malfal94 + logem4, data=df)
IV3b = ivreg(loggdp ~ qi + latitude + africa + asia + malfal94 | latitude + africa + asia + malfal94 + logem4 + euro1900, data=df)
stargazer(IV2a, IV2b,IV3a, IV3b, no.space=TRUE, type="text",
title = "Table 5.6 IV results explaining GDP per capita)")
##
## Table 5.6 IV results explaining GDP per capita)
## ===================================================================================
##                                           Dependent variable:
##                     ---------------------------------------------------------------
##                                                 loggdp
##                           (1)             (2)             (3)             (4)
## -----------------------------------------------------------------------------------
## qi                     0.996***        0.946***         0.893**        0.548***
##                         (0.222)         (0.173)         (0.420)         (0.115)
## latitude                -0.647          -0.597          -1.070          -0.220
##                         (1.335)         (1.186)         (1.425)         (0.723)
## africa                                                  -0.445          -0.425*
##                                                         (0.365)         (0.247)
## asia                                                    -0.825*        -0.585**
##                                                         (0.455)         (0.250)
## malfal94                                                -0.106          -0.550*
##                                                         (0.691)         (0.328)
## Constant                 1.692          1.995*           2.772         4.991***
##                         (1.293)         (1.018)         (2.717)         (0.764)
## -----------------------------------------------------------------------------------
## Observations              64              63              62              62
## R2                       0.102           0.174           0.329           0.690
## Adjusted R2              0.073           0.147           0.270           0.663
## Residual Std. Error 1.005 (df = 61) 0.958 (df = 60) 0.883 (df = 56) 0.600 (df = 56)
## ===================================================================================
## Note:                                                   *p<0.1; **p<0.05; ***p<0.01

#### Table 5.7

GMM estimation results consumption-based asset pricing model

moment <- function(parm,x=NULL) {
n.col = ncol(x)
sdf = parm[1]*x[,1]^(-parm[2])
d1 = sdf*x[,2] - 1
d2 = as.matrix(rep(sdf,(n.col-2))*x[,3:n.col])
return(cbind(d1,d2))
}
df = read_csv("Data/pricing.csv")
df = df[,-1]
df.matrix = as.matrix(df)
n.col = ncol(df.matrix)
exRet = apply(df.matrix[,2:(n.col-1)],2,
function(x,y){x-y},
df.matrix[,"RF"])
matrices = cbind(df.matrix[,"CONS"], 1+df.matrix[,"RF"],
exRet)
colnames(matrices)[1] = "CONS"
colnames(matrices)[2] = "RF"

start.vals = c(1,5)
names(start.vals) = c("delta","gamma")
summary(IterGMM <- gmm(g=moment, x=matrices, t0=start.vals, type="iterative",  vcov="iid", optfct="optim"))
##
## Call:
## gmm(g = moment, x = matrices, t0 = start.vals, type = "iterative",
##     vcov = "iid", optfct = "optim")
##
##
## Method:  iterative
##
## Coefficients:
##        Estimate    Std. Error  t value     Pr(>|t|)
## delta  8.2736e-01  1.1616e-01  7.1228e+00  1.0578e-12
## gamma  5.7395e+01  3.4221e+01  1.6772e+00  9.3504e-02
##
## J-Test: degrees of freedom is 9
##                 J-test   P-value
## Test E(g)=0:    5.76329  0.76336
##
## Initial values of the coefficients
##     delta     gamma
##  0.699629 91.404383
##
## #############
## Information related to the numerical optimization
## Convergence code =  0
## Function eval. =  63
## Gradian eval. =  NA
summary(OneStepGMM <- gmm(g=moment, x=matrices, t0=coef(IterGMM), type="cue", vcov="iid", optfct="optim"))
##
## Call:
## gmm(g = moment, x = matrices, t0 = coef(IterGMM), type = "cue",
##     vcov = "iid", optfct = "optim")
##
##
## Method:  cue
## Coefficients:
##        Estimate    Std. Error  t value     Pr(>|t|)
## delta  6.9741e-01  1.1886e-01  5.8676e+00  4.4212e-09
## gamma  9.6193e+01  3.1617e+01  3.0425e+00  2.3466e-03
##
## J-Test: degrees of freedom is 9
##                 J-test   P-value
## Test E(g)=0:    5.14334  0.82164
##
## Initial values of the coefficients
##      delta      gamma
##  0.8273564 57.3947461
##
## #############
## Information related to the numerical optimization
## Convergence code =  0
## Function eval. =  99
## Gradian eval. =  NA