R- is it safe to use the package sandwich for instrumental variable or GMM models? Both of the following approaches should lead to the same results in my opinion.
This is a modified example from ?ivreg where I wanted to use vcovHAC from the package sandwich to compute heteroscedastic and autocorrelation consistent standard errors. Is it possible/safe to use the package vcovHAC for instrumental variable or GMM models? (If you look at the estfun in vcovHAC it seems to me that the instrumental variables are not considered? )
     require(AER,gmm)
    data("CigarettesSW", package = "AER")
    CigarettesSW$rprice <- with(CigarettesSW, price/cpi)
    CigarettesSW$rincome <- with(CigarettesSW, income/population/cpi)
    CigarettesSW$tdiff <- with(CigarettesSW, (taxs - tax)/cpi)

tsls1 <- tsls(log(packs) ~ log(rprice) + log(rincome),
          ~   1+ log(rincome) + tdiff + I(tax/cpi),
          data = CigarettesSW)

gmmhac <- gmm(log(packs) ~ log(rprice) + log(rincome),
          ~   1+ log(rincome) + tdiff + I(tax/cpi),
          data = CigarettesSW,vcov="HAC", method="2step")



print("HAC:")
print(coeftest(tsls1, vcovHAC(tsls1))[,1:2])
print(coeftest(gmmhac)[,1:2])

Thank you for answers/help.
The question is related to this question link
 A: You write: 

Both of the following approaches should lead to the same results in my
  opinion

As I have outlined in my earlier answer, I think this is not correct. The reason is first: as far as I can tell, gmm estimates everything numerically. Second, there are many defaults and you do not know which defaults have been implemented. For instance, consider the following:
gmmout <- coeftest(gmmhac)[,2]
coef1 <- coeftest(tsls1, vcovHAC(tsls1))[,2]
coef2 <- coeftest(tsls1, vcovHAC(tsls1, prewhite=T))[,2]
coef3 <- coeftest(tsls1, vcovHAC(tsls1, adjust=F))[,2]
coef4 <- coeftest(tsls1, vcovHAC(tsls1, weights=weightsLumley))[,2]
ivpack <- ivpack::robust.se(tsls1)[, 2]

rbind(gmmout, coef1, coef2, coef3, coef4, ivpack)
       (Intercept) log(rprice) log(rincome)
gmmout   0.5390832   0.1612205    0.1504473
coef1    0.5148805   0.1549164    0.1528369
coef2    0.5467551   0.1671742    0.1580528
coef3    0.5067717   0.1524766    0.1504298
coef4    0.5147232   0.1547453    0.1527562
ivpack   0.5066168   0.1523082    0.1503504

There is quite some variation in robust standard errors here. I have achieved this by just changing the defaults in vcovHAC which you can see when you look at the helpfile (?vcovHAC), plus I have added the output of the function robust.se from the ivpack package, which computes robust standard errors for the IV case. Note that I have just changed one default value at a time. Maybe you can play around with them to find a set of default values so that the output with the gmm function is the same. 
Unless all defaults are the same, there is no reason to believe that these values should be the same. Having said that, the differences are rather small, and while there certainly are some defaults that are better for your data, it probably won't matter much. 
If you think that sandwich does not work properly, I would propose testing it against a different software to convince yourself. See e.g. here.
