[Gmm-commits] r219 - in pkg/momentfit: . R man vignettes

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Feb 2 17:25:37 CET 2024


Author: chaussep
Date: 2024-02-02 17:25:36 +0100 (Fri, 02 Feb 2024)
New Revision: 219

Added:
   pkg/momentfit/man/weakTest.Rd
Removed:
   pkg/momentfit/man/CDtest.Rd
Modified:
   pkg/momentfit/NAMESPACE
   pkg/momentfit/R/weak.R
   pkg/momentfit/vignettes/empir.bib
   pkg/momentfit/vignettes/weak.Rmd
   pkg/momentfit/vignettes/weak.pdf
Log:
added the Sanderson and Windmeijer (2016) test for weak instruments

Modified: pkg/momentfit/NAMESPACE
===================================================================
--- pkg/momentfit/NAMESPACE	2024-01-30 16:16:12 UTC (rev 218)
+++ pkg/momentfit/NAMESPACE	2024-02-02 16:25:36 UTC (rev 219)
@@ -44,7 +44,7 @@
        rhoET, rhoEL, rhoEEL, rhoHD, Wu_lam, EEL_lam, REEL_lam, getLambda, 
        solveGel, rhoETEL, rhoETHD, ETXX_lam, gelFit, evalGel, getImpProb,
        evalGelObj, momFct, gel4, setCoef, lse, getK, kclassfit, CDtest,
-       SYTables)
+       SYTables, SWtest)
  
 ###  S3 methods ###
 

Modified: pkg/momentfit/R/weak.R
===================================================================
--- pkg/momentfit/R/weak.R	2024-01-30 16:16:12 UTC (rev 218)
+++ pkg/momentfit/R/weak.R	2024-02-02 16:25:36 UTC (rev 219)
@@ -193,7 +193,7 @@
 
 ## Stock and Yogo (2005)
 
-CDtest <- function(object, print=TRUE, ...)
+CDtest <- function(object, print=TRUE, SWcrit=FALSE, ...)
 {
     if (!inherits(object, "linearModel"))
         stop("object must be of class linearModel")
@@ -205,6 +205,14 @@
     X2 <- X[,spec$isEndo, drop=FALSE]
     secS <- lm.fit(Z, X2)        
     Z2 <- Z[,z2n,drop=FALSE]
+    df <- ncol(Z2)    
+    if (ncol(Z2)==1 & SWcrit)
+    {
+        warning("The Sanderson and Windmeijer modification of CD-test and rejection rule only applies to models with more than 1 endogenous variables")
+        SWcrit <- FALSE
+    } else if (SWcrit) {       
+        df <- ncol(Z2)-ncol(X2)+1
+    }
     tmp <- if (ncol(X2)>1)
                Z[,z2n,drop=FALSE]%*%secS$coef[z2n,,drop=FALSE]
            else
@@ -212,26 +220,46 @@
     e <- secS$residuals
     e2 <- lm.fit(X1, X2)$residuals
     e <- crossprod(e)/(spec$n-spec$q)
-    e2 <- crossprod(e2, tmp)/ncol(Z2)
-    test <- min(eigen(solve(e,e2))$val)
+    e2 <- crossprod(e2, tmp)
+    test <- min(eigen(solve(e,e2))$val)/df
     if (!print)
         return(test)
     cat("Cragg and Donald Test for Weak Instruments\n",
         "******************************************\n", sep="")
-    cat("Number of included Endogenous: ", ncol(X2), "\n", sep="")
-    cat("Number of excluded Exogenous: ", ncol(Z2), "\n", sep="")
+    if (SWcrit)
+    {
+        cat("Sanderson and Windmeijer specification\n")
+        add1 <- "(-1 for the SW critical value)"
+        add2 <- paste("(-", ncol(X2)-1, ")", sep="")
+    } else {
+        add1 <- add2 <- ""
+    }
+    cat("Number of included Endogenous: ", ncol(X2), add1, "\n", sep="")
+    cat("Number of excluded Exogenous: ", ncol(Z2), add2, "\n", sep="")
     cat("Statistics: ", formatC(test, ...), "\n\n", sep="")
-    SYTables(object)
+    SYTables(object, TRUE, SWcrit)
 }
 
-SYTables <- function(object, print=TRUE)
+SYTables <- function(object, print=TRUE, SWcrit=FALSE)
 {
     if (!inherits(object, "linearModel"))
         stop("object must be of class linearModel")
     s <- modelDims(object)
     l <- sum(s$isEndo)
-    k <- s$q - (s$k - l)       
+    k <- s$q - (s$k - l)
+    if (l==1 & SWcrit)
+        SWcrit <- FALSE
+    if (SWcrit)
+    {
+        k <- k-l+1        
+        l <- l-1
+    }
     t <- sizeTSLS
+    if (l>2)
+    {
+        cat("No critical values for models with more than 2 endogenous variables\n")
+        return(invisible())
+    }
     sizeTSLS <- t[attr(t, "excExo") == k, attr(t, "incEndo") == l]
     names(sizeTSLS) <- paste("size=",
                              attr(t, "size")[attr(t, "incEndo") == l], sep="")
@@ -266,6 +294,8 @@
     
     cat("Stock and Yogo (2005) critical values\n")
     cat("*************************************\n")
+    if (SWcrit)
+        cat("Critical value adjusted to Sanderson and Windmeijer (2016) specification\n\n")
     for (i in 1:4)
     {
         if (!is.null(crit[[i]]))
@@ -277,3 +307,53 @@
     }
     invisible()
 }
+
+## Sanderson and Windmeijer (2016)
+
+SWtest <- function(object, j=1, print=TRUE, ...)
+{
+    if (!inherits(object, "linearModel"))
+        stop("object must be of class linearModel")
+    spec <- modelDims(object)
+    if (sum(spec$isEndo)<1)
+    {
+        warning("The model does not contain an endogenous variable")
+        return(NA)
+    }
+    if (sum(spec$isEndo)==1)
+    {
+        warning(paste("The number of endgenous variables is equal to 1\n",
+                      "Returning the F-test", sep=""))
+        return(CDtest(object, print))
+    }
+    Z <- model.matrix(object, "instrument")
+    X <- model.matrix(object)
+    X2 <- X[, spec$isEndo, drop=FALSE]
+    X1 <- X[, !spec$isEndo, drop=FALSE]
+    if (ncol(X1))
+    {
+        z2n <- !(colnames(Z) %in% colnames(X1))
+        fitX1 <- lm.fit(X1, Z[,z2n])
+        Z <- as.matrix(fitX1$residuals)
+        X2 <- qr.resid(fitX1$qr, X2)
+    }
+    Xj <- X2[,j]
+    Xjm <- X2[,-j,drop=FALSE]
+    fsReg <- lm.fit(Z, Xjm)
+    Xjmhat <- as.matrix(fsReg$fitted)
+    fit <- lm.fit(Xjmhat, Xj)
+    e <- Xj-c(Xjm%*%fit$coefficients)
+    ehat <- qr.fitted(fsReg$qr, e)
+    sig <- sum((e-ehat)^2)/(spec$n-spec$q)
+    test <- sum(ehat^2)/sig/(ncol(Z)-ncol(Xjm))
+    if (!print)
+        return(test)
+    cat("Sanderson and Windmeijer Test for Weak Instruments\n")
+    cat("***************************************************\n", sep="")
+    add1 <- "(-1 for the critical values)"
+    add2 <- paste("(-", ncol(X2)-1, " for the critical values)", sep="")
+    cat("Number of included Endogenous: ", ncol(X2), add1, "\n", sep="")
+    cat("Number of excluded Exogenous: ", sum(z2n), add2, "\n", sep="")
+    cat("Statistics: ", formatC(test, ...), "\n\n", sep="")
+    SYTables(object, TRUE, TRUE)
+}

Deleted: pkg/momentfit/man/CDtest.Rd
===================================================================
--- pkg/momentfit/man/CDtest.Rd	2024-01-30 16:16:12 UTC (rev 218)
+++ pkg/momentfit/man/CDtest.Rd	2024-02-02 16:25:36 UTC (rev 219)
@@ -1,73 +0,0 @@
-\name{CDtest}
-\alias{CDtest}
-\alias{SYTables}
-\title{
-Cragg and Donald test for Weak Instruments
-}
-\description{
-The Cragg and Donald test is based on the F-test from the first stage
-regression. For models with one endogenous variable, it is the usual
-F-test. For more than one endogenous variables, it is the smallest
-eigenvalue of the matrix representation of the F statistic. Along with
-the statistics, the critical values of Stock and Yogo (2005) for the
-null hypothesis of weak instruments are provided. 
-}
-\usage{
-
-CDtest(object, print=TRUE, ...)
-
-SYTables(object, print=TRUE)
-
-}
-
-\arguments{
-  \item{object}{
-    A model of class \code{linearModel}
-  }
-  \item{print}{
-    If code{TRUE}, the result is printed and nothing is returned. See
-    below for details on what the functions return when it is set to
-    \code{FALSE}
-  }
-  \item{...}{Arguments passed to \code{\link{formatC}} to print the statistic.
-  }
-}
-
-\details{ The \code{CDtest} function computes the test for the model
-  object and runs \code{SYTables} to extract the critical values that are
-  specific to the model. }
-
-\value{
-  The function \code{CDtest} returns the Cragg anb Donald statistic when
-  \code{print} is set to \code{FALSE}.
-
-  The function \code{SYTable} returns a list with the following elements
-  when \code{print} is set to \code{FALSE}:
-
-  \item{biasTSLS, biasFuller}{Named vectors of critical values for TSLS
-  or Fuller (see \code{\link{kclassfit}}). These critical values are
-  used to achieve the maximum relative bias given by their names. The
-  values are defined only for models with a number of overidentifying
-  restrictions greater or equal to 2.} 
-
-  \item{sizeTSLS, sizeLIML}{A named vector of critical values for TSLS
-  or LIML (see \code{\link{kclassfit}}). These critical values are used
-  to acheive a size that does not exceed the one given by their names.}
-
- Both functions return \code{NULL} invisibly when \code{print} is set to
- \code{TRUE}
-
-}  
-\examples{
-
-data(simData)
-theta <- c(beta0=1,beta1=2)
-model1 <- momentModel(y~x1, ~z1+z2, data=simData)
-CDtest(model1)
-}
- 
-\keyword{LIML}
-\keyword{Fuller}
-\keyword{Weak Instruments Test}
-\keyword{Two Stage Least Squares}
-

Added: pkg/momentfit/man/weakTest.Rd
===================================================================
--- pkg/momentfit/man/weakTest.Rd	                        (rev 0)
+++ pkg/momentfit/man/weakTest.Rd	2024-02-02 16:25:36 UTC (rev 219)
@@ -0,0 +1,107 @@
+\name{weakTest}
+\alias{CDtest}
+\alias{SWtest}
+\alias{SYTables}
+\title{
+Tests for weak Instruments
+}
+\description{
+This is a collection of tests for weak instruments. It includes the
+Cragg and Donald test for the reduced rank hypothesis and the conditional
+F-test of Sanderson and Windmeijer (2016). The critical values of Stock
+and Yogo (2005) for the null hypothesis of weak instruments are also
+provided.  
+}
+\usage{
+
+SWtest(object, j=1, print=TRUE, ...)
+
+CDtest(object, print=TRUE, SWcrit=FALSE, ...)
+
+SYTables(object, print=TRUE, SWcrit=FALSE)
+
+}
+
+\arguments{
+  \item{object}{
+    A model of class \code{linearModel}
+  }
+
+  \item{j}{The Sanderson and Windmeijer test is based on the regression
+  of \eqn{y_j-\delta y_{-j}} on the set on instruments, where \eqn{y_j}
+  is the jth included endogenous variable and \eqn{y_{-j}} is the vector
+  of the other included endogenous variables.
+  }
+    
+  \item{print}{
+    If code{TRUE}, the result is printed and nothing is returned. See
+    below for details on what the functions return when it is set to
+    \code{FALSE}
+  }
+
+  \item{SWcrit}{If true, the critical values and the test are ajusted to
+  Sanderson and Windmeijer (2016). See details.}
+  
+  \item{...}{Arguments passed to \code{\link{formatC}} to print the statistic.
+  }
+}
+
+\details{ The \code{CDtest} function computes the test for the model
+  object and runs \code{SYTables} to extract the critical values that are
+  specific to the model.
+
+  Let \eqn{l} be the number of included endogenous variables and \eqn{s}
+  be the number of excluded exogenous. The Stock and Yogo (2005) tables
+  are based on these two values and they are only available for
+  \eqn{l=1,2} and \eqn{s=1,...,30}. For the SW test, which is only
+  defined for $l>1$, we compare the statistic with the critical values
+  associated with \eqn{l=l-1} and \eqn{s=s-l+1}. These are the critical
+  values that are returned when the argument \code{SWcrit} of
+  \code{SYTables} is set to \code{TRUE}. This allows us to test for weak
+  instruments in models with 2 or 3 included endogenous variable using
+  the same tables of critical values.
+
+  Sanderson and Windmeijer (2016) show that we can use the same critical
+  values if we modify the CD test by multiplying it by \eqn{s/(s-l+1)},
+  which is what the function \code{CDtest} returns if the argument
+  \code{SWcrit} is set to \code{TRUE}.
+
+  }
+
+\value{
+  The function \code{CDtest} returns the Cragg anb Donald statistic when
+  \code{print} is set to \code{FALSE}.
+
+  The function \code{SYTable} returns a list with the following elements
+  when \code{print} is set to \code{FALSE}:
+
+  \item{biasTSLS, biasFuller}{Named vectors of critical values for TSLS
+  or Fuller (see \code{\link{kclassfit}}). These critical values are
+  used to achieve the maximum relative bias given by their names. The
+  values are defined only for models with a number of overidentifying
+  restrictions greater or equal to 2.} 
+
+  \item{sizeTSLS, sizeLIML}{A named vector of critical values for TSLS
+  or LIML (see \code{\link{kclassfit}}). These critical values are used
+  to acheive a size that does not exceed the one given by their names.}
+
+ Both functions return \code{NULL} invisibly when \code{print} is set to
+ \code{TRUE}
+
+}  
+\examples{
+
+data(simData)
+theta <- c(beta0=1,beta1=2)
+model1 <- momentModel(y~x1, ~z1+z2, data=simData)
+CDtest(model1)
+model2 <- momentModel(y~y1+y2+x1, ~z1+z2+z3+z4+x1, data=simData)
+SWtest(model2, 1, FALSE)
+SWtest(model2, 2, FALSE)
+}
+ 
+\keyword{LIML}
+\keyword{Fuller}
+\keyword{Weak Instruments Test}
+\keyword{Two Stage Least Squares}
+

Modified: pkg/momentfit/vignettes/empir.bib
===================================================================
--- pkg/momentfit/vignettes/empir.bib	2024-01-30 16:16:12 UTC (rev 218)
+++ pkg/momentfit/vignettes/empir.bib	2024-02-02 16:25:36 UTC (rev 219)
@@ -1,3 +1,56 @@
+ at article{montiel-olea-pflueger13,
+  AUTHOR={Montiel Olea, J. and Pflueger, C.},
+  TITLE={A robust test for weak instruments},
+  JOURNAL={Journal of Business and Economic Statistics},
+  VOLUME={31},
+  PAGES={358--369},
+  YEAR={2013}
+ } 
+
+ at article{sanderson-windmeijer16,
+  AUTHOR={Sanderson, E. and Windmeijer, F.},
+  TITLE={A weak instrument F-test in linear IV models with multiple
+  endogenous variables},
+  JOURNAL={Journal of Econometrics},
+  VOLUME={190},
+  PAGES={212--221},
+  YEAR={2016}
+ } 
+
+
+
+ at article{nagar59,
+  AUTHOR={Nagar, A.L.},
+  TITLE={Testing Identifiability and Specification in Instrumental Variable Models},
+  JOURNAL={Econometrica},
+  VOLUME={27},
+  PAGES={575--595},
+  YEAR={1959}
+ } 
+
+
+ at article{cragg-donald93,
+  AUTHOR={Cragg, J.G. and Donald, S.G.},
+  TITLE={Testing Identifiability and Specification in Instrumental Variable Models},
+  JOURNAL={Econometric Theory},
+  VOLUME={9},
+  PAGES={222--240},
+  YEAR={1993}
+ } 
+
+
+ at book{stock-yogo05,
+author = {Stock, J.H. and Yogo, M.},
+title = {Testing for weak instruments in linear IV regression. In Identification and Inference for
+Econometric Models: Essays in Honor of Thomas Rothenberg.},  
+year = {2005},
+publisher = {Cambridge University Press},
+edition = {Edited by Donald W. K. Andrews and James H. Stock},
+address = {Cambridge},
+pages={80--108}
+} 
+
+
 @book{davidson-mackinnon04,
 author = {Davidson, R. and MacKinnon, J. G.},
 title = {Econometric Theory and Methods},

Modified: pkg/momentfit/vignettes/weak.Rmd
===================================================================
--- pkg/momentfit/vignettes/weak.Rmd	2024-01-30 16:16:12 UTC (rev 218)
+++ pkg/momentfit/vignettes/weak.Rmd	2024-02-02 16:25:36 UTC (rev 219)
@@ -64,10 +64,11 @@
 $X_2$, or the first stage regression, is therefore:
 
 \[
-X_2 = Z\Pi + e\,,
+X_2 = X_1\Pi_1 + Z_2\Pi_2 + e \equiv Z\Pi + e\,,
 \]
 
-where $\Pi$ is $q\times k_2$ and $e$ is $n\times k_2$. 
+where $\Pi_1$ is $k_1\times k_2$, $\Pi_2$ is $l_2\times k_2$, $\Pi$ is
+$q \times k_2$ and $e$ is $n\times k_2$.
 
 
 # K-class Estimator and LIML
@@ -269,13 +270,13 @@
 The function that computes the K-Class estimator is `kclassfit`. The
 arguments are: `object`, the model object, `k`, the value of $\kappa$,
 `type`, the type of $\kappa$ to compute when `k` is missing (`"LIML"`,
-`"Fuller"` or `"BTSLS"` for the biased corrected TSLE) and `alpha`,
-the parameter of the Fuller method (the default is 1). Note first that
-the estimator is a TSLS estimator when `k=1` and a LSE when it is
-equal to 0. The package already has a `tsls` method for `linearModel`
-objects, which is what `kclassfit` calls when `k=1`. For the LSE, a
-new method was created to facilitate the estimation of model objects
-by least squares. The method is `lse`:
+`"Fuller"` or `"BTSLS"` for the biased corrected TSLE of @nagar59) and
+`alpha`, the parameter of the Fuller method (the default is 1). Note
+first that the estimator is a TSLS estimator when `k=1` and a LSE when
+it is equal to 0. The package already has a `tsls` method for
+`linearModel` objects, which is what `kclassfit` calls when `k=1`. For
+the LSE, a new method was created to facilitate the estimation of
+model objects by least squares. The method is `lse`:
 
 ```{r}
 lse(mod2)
@@ -385,10 +386,11 @@
 
 # Weak Instruments 
 
-## Testing for weak instrument: Stock-Yogo (2005)
+## Testing for weak instrument: @stock-yogo05
 
 This test and the critical values are for model with homoskedastic
-errors. The test is the smallest eigenvalue of the following:
+errors. The test is the smallest eigenvalue of the following
+expression (@cragg-donald93):
 
 \[
 \hat\Sigma_e^{-1/2}
@@ -395,25 +397,61 @@
 \Big[
 X_2'M_1Z_2(Z_2'M_1Z_2)^{-1}Z_2'M_1X_2 
 \Big]
-\hat\Sigma_e^{-1/2} = [M_1 X_2]'[Z_2\hat\Pi_2]
+\hat\Sigma_e^{-1/2} = \hat\Sigma_e^{-1/2}[M_1 X_2]'[Z_2\hat\Pi_2]\hat\Sigma_e^{-1/2}
 \]
 
-where $\hat\Sigma_e = \hat{e}'\hat{e}/(n-l_2-k_1)$. The function
-`CDtest`, which stands for Cragg and Donald test, computes this
-statistic. We can see that it returns the F-statistics when the number
-of endogenous variables is equal to 1:
+where $\hat\Sigma_e = \hat{e}'\hat{e}/(n-l_2-k_1)$. If the number of
+included endogenous variables $k_2$ is equal to 1, this is just the F
+statistic for the null hypothesis $H_0:\Pi_2=0$. For $k_2>1$, it is a
+test of rank reduction. Under the null the rank of $\Pi_2$ is $k_2-1$
+and under the alternative it is equal to $k_2$. The function `CDtest`,
+which stands for Cragg and Donald test, computes this statistic. By
+using the `momentStrength` method, which computes the first stage F
+statistics for each included endogenous variable, we can see they are
+both the same when $k_2=1$:
 
 ```{r}
-CDtest(mod2, print=FALSE)
+(CD2 <- CDtest(mod2, print=FALSE))
 momentStrength(mod2)
 ```
 
-Here is what we obtain for `mod3`
+However, it does not return a p-value like the F-test computed by
+`momentStrength`. Instead, it comes with the critical values computed
+by @stock-yogo05. If we let the function `CDtest` print the result
+(the default), we see the statistics and the critical values that are
+relevant to our model (they depend on the number of included
+endogenous and excluded exogenous variables). 
 
 ```{r}
-CDtest(mod3)
+CDtest(mod2)
 ```
+	
+We reject the null hypothesis that the instruments are weak if the
+statistic is greater than the critical value of interest. To
+understand the critical values, let's first consider the ones under
+"Target size for TSLS". If are willing to accept a wrong size of at
+most 10\% for hypothesis tests on coefficients at 5\%, the statistic
+must exceed 19.93 for the instruments to be considered strong
+enough. Since the statistic for `mod2` does not, we should expect a
+higher size distortion. In fact, our statistic is equal to `r round(CD2,4)`, 
+so we can expect the size to be as high as 25\% since
+the statistic is greater than 7.25. Under "Target size for LIML", we
+have the same critical values but for models estimated by LIML. We see
+that the size distortion is not as severe for LIML. Since the
+statistic is between the first and the second critical value, the size
+should be between 10\% and 15\%.
 
+We also have critical values that are based on the worst bias relative
+ to the OLS bias. For example, if the model is estimated by the Fuller
+ method and we are willing to accept a relative bias of at most 5\%,
+ we need the statistic to exceed 15.60. Since the statistic of `mod2`
+ is only greater than 6.62 (the last critical value), the relative
+ bias may be as large as 30\%. Note that the critical values based on
+ the relative bias are only available for TSLS when the number of
+ over-identifying restrictions are greater or equal to 2. For the
+ following model, all critical values are available. In this case, the
+ instruments are very strong. But are they valid?
+
 ```{r}
 g <- reformulate(c("educ", Xname), "lwage")
 h <- reformulate(c(c("nearc4","nearc2","IQ","KWW"), Xname))
@@ -421,9 +459,81 @@
 CDtest(mod5)
 ```
 
+## Testing for weak instrument: @sanderson-windmeijer16
 
+This test was derived for models with at least 2 endogenous variables
+($k_2>2$ in our model). Let $X_{2,j}$ be the j$^\mathrm{th}$ included
+endogenous variable and and $X_{2,-j}$ be the $k_2-1$ remaining
+included endogenous variables, then the procedure is :
 
+- Estimate the model $$X_{2,j} = X_{2,-j}\delta_1 + X_1 \delta_2 + v$$
+  by TSLS using the instruments $Z$ and save the residuals $\hat{v}$.
 
+- Estimate the model $$\hat{v} = X_1\kappa_1+Z_2\kappa_2 + \xi$$ by
+  OLS
+
+- Compute the F-test for $H_0: \kappa_2=0$. Let $\tilde{F}$ be the
+  value of the statistics.
+
+- Compute the @sanderson-windmeijer16 statistics
+  $F_{j|-j}=\tilde{F}[l_2/(l_2-k_2+1)]$.
+
+
+To illustrate the procedure, we consider the following model based on
+the simulated dataset `simData`:
+
+\[ 
+y = \beta_0 + \beta_1 y_1 + \beta_2 y_2 + \beta_3 y_3 + \beta_4
+x_1 + \beta_5 x_2 + u\,, 
+\]
+
+where `y1`, `y2` and `y3` are assumed to be endogenous. We want to
+estimate the model using the 5 excluded exogenous variables `z1` to
+`z5`. To use our notation, we have $X_1=\{$`x1`, `x2`$\}$,
+$X_2=\{$`y1`, `y2`, `y3`$\}$ and $Z_2=\{$`z1`, `z2`, `z3`, `z4`,
+`z5`$\}$. Following the above procedure the statistic using `j=1` is:
+
+```{r, message=FALSE}
+data(simData)
+## Step 1
+m <- tsls(y1~y2+y3+x1+x2, ~z1+z2+z3+z4+z5+x1+x2, data=simData)
+e <- residuals(m)
+## Step 2
+fit <- lm(e~z1+z2+z3+z4+z5+x1+x2, simData)
+fitr <- lm(e~x1+x2, simData)
+F <- anova(fit, fitr)$F[2]
+## Step 4
+(sw1 <- F*5/(5-2))
+```
+
+The function `SWtest` computes this test and returns the 
+
+```{r}
+smod <- momentModel(y~y1+y2+y3+x1+x2, ~z1+z2+z3+z4+z5+x1+x2, data=simData)
+SWtest(smod,1,FALSE)
+```
+
+Following @sanderson-windmeijer16, for models with $k_2$ endogenous
+variables and $l_2$ excluded exogenous, we compare the statistic with
+the @stock-yogo05 critical values for models with $l_2-1$ endogeous
+variables and $k_2-l_2+1$ excluded exogenous. This allows us to test
+the intruments for models with 3 endogenous variables without
+generating new tables. This is how the critical values are selected in
+`SWtest`:
+
+```{r}
+SWtest(smod)
+```
+
+These critical values are obtained by running the function `SYTables`
+with the argument `SWcrit` set to `TRUE`. Note that the authors show
+also that the same critical values can be used if we multiply the
+Cragg and Donald statistic by $k_2/(k_2-l_2+1)$.
+
+
+## Testing for weak instrument: @montiel-olea-pflueger13
+
+
 ## Data Generating Process (for later use)
 
 The following function is used to generate dataset with $k$

Modified: pkg/momentfit/vignettes/weak.pdf
===================================================================
(Binary files differ)



More information about the Gmm-commits mailing list