[Gmm-commits] r217 - pkg/momentfit/vignettes

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jan 25 23:40:49 CET 2024


Author: chaussep
Date: 2024-01-25 23:40:48 +0100 (Thu, 25 Jan 2024)
New Revision: 217

Modified:
   pkg/momentfit/vignettes/weak.Rmd
   pkg/momentfit/vignettes/weak.pdf
Log:
worked in the vignette

Modified: pkg/momentfit/vignettes/weak.Rmd
===================================================================
--- pkg/momentfit/vignettes/weak.Rmd	2024-01-25 20:13:45 UTC (rev 216)
+++ pkg/momentfit/vignettes/weak.Rmd	2024-01-25 22:40:48 UTC (rev 217)
@@ -326,7 +326,7 @@
 the method. It returns an object of class `summaryKclass`.
 
 ```{r}
-summary(liml)
+(s <- summary(liml))
 ```
 
 Note that the specification test is based on Anderson and Rubin. It is
@@ -339,6 +339,44 @@
 specTest(liml)
 ```
 
+We can compare the standard error we get here and the one we get from
+the `ivmodel` package. Note that only inference about the coefficient
+of the endogenous variable is provided by `ivmodel`.
+
+```{r}
+s at coef["educ",]
+mod$LIML$std.err
+```
+
+The result is quite different. But we can see why. In the following I
+recompute the standard error using the formula
+$\hat{\sigma}^2(W_\kappa'X)^{-1}$. We now get the same result. As mentioned
+before, this expression is only valid for $\kappa=1$.
+
+```{r}
+spec <- modelDims(mod2)
+u <- residuals(liml)
+sig <- sum(u^2)/(spec$n-spec$k)
+W <- model.matrix(liml at model, "instruments")
+myX <- model.matrix(liml at model)
+sqrt(diag(sig*solve(t(W)%*%myX)))[2]
+```
+
+For Heteroskedastic errors. We have to redefine the models. 
+
+```{r, eval=FALSE}
+mod <- ivmodel(Y=Y,D=D,Z=Z,X=X,heteroSE=TRUE)
+mod2 <- momentModel(g, h, data=card.data, vcov="MDS")
+liml <- kclassfit(mod2, resK)
+summary(liml)@coef["educ",]
+c(mod$LIML$point.est, mod$LIML$std.err)
+```
+
+The above code is not run because the `ivmodel` is very inefficient to
+compute the meat matrix. It is done using a loop. It you run the code
+you should get identical point estimate and both standard errors are
+equal to 0.0576098.
+
 # Weak Instruments (For later use)
 
 

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



More information about the Gmm-commits mailing list