First I have to say I am sorry because I have not been so clear in my previous e-mails. I will try to explain clearer what it is my problem.
I have the following model: lnP=Sc+Ag+Ag2+Var+R+D In this model the variable Sc is endogenous and the rest are all objective exogenous variables. I verified that Sc is endogenous through a standard Hausman test. To determine this I defined before a new instrumental variable, I2. Also I detected through a Breusch Pagan Test a problem of heteroskedasticity. With the intention to avoid the problem of the endogenous variable and the heteroskedasticity I want to apply first the technique 2SLS and then based in these results I want to obtain the t-tests of the coefficients applying Heteroskedasticity Consistent Standard Errors (HCSE) or Huber-White errors. Like I showed above I have just one structural equation in the model. In this situation, to apply 2SLS in R until I know there two possible ways: First to use the function tsls() from package sem, or second, to use the function systemfit() from package systemfit. I thought that systemfit was for situations when there are more than one structural equation in the model. Anyway I probed with the two ways and I obtained similar results. Below, I show the program lines: *Program lines 1:* * * *>#### First option: applying tsls ####* *>library (sem)* *>Reg1 <-tsls (LnP~Sc+Ag+Ag2+Var+R+D,~I2+Ag+Ag2+Var+R+D) * *>summary (Reg1)* * * *>#### Second option: applying systemfit ####* *>library (systemfit)* *>RS <- LnP~Sc+Ag+Ag2+Var+R+D # structural equation* *>Inst <- ~I2+Ag+Ag2+Var+R+D # instrumental variables* *>labels <- list("RS")* *>system <- list(RS)* *>Reg2 <- systemfit("2SLS", system, labels, Inst, saveMemory=TRUE) * *>summary (Reg2)* Now I want to obtain the t-tests of the coefficients but applying the HCSE. I know two different ways to obtain them: First, applying the function robcov() from package Design, or Second, applying coeftest() and vcovHV() from packages lmtest and sandwich. The program lines are the following: *Program lines 2:* *>#### First option: using robcov() ####* *>library (Design)* *>options(scipen=20)* *>robcov(Reg1) ### I tried with Reg 2 too* ** ** ** ***>####Second option: using coeftest and vcovHC ####* *>library (lmtest)* *>library (sandwich)* *>coeftest (Reg1, vcov=vcovHC(Reg1 or Reg2, type="HC0")) ### I tried with Reg 2 too* In the two cases after trying to apply robcov or coeftest I obtained a message of error: *With robcov:* *> Error in rep.default(1, p) : rep() incorrect type for second argument * * * *With coeftest:* *>** **Error in terms.default(object) : no terms component* In the following lines I copy all the sequence together from R. If I try with systemfit instead of tsls I obtain the same result: *Program lines 3:* *>ibrary (sem)* *> Reg1 <-tsls(LnP~Sc+Ag+Ag2+Var+R+D,~I2+Ag+Ag2+Var+R+D)* *> library (Design)* *Loading required package: Hmisc* *Loading required package: chron* *Hmisc library by Frank E Harrell Jr* *Type library(help='Hmisc'), ?Overview, or ?Hmisc.Overview')* *to see overall documentation.* *NOTE:Hmisc no longer redefines [.factor to drop unused levels when* *subsetting. To get the old behavior of Hmisc type dropUnusedLevels().* *Loading required package: survival* *Loading required package: splines* *Attaching package: 'survival'* * The following object(s) are masked from package:Hmisc :* * untangle.specials * *Design library by Frank E Harrell Jr* *Type library(help='Design'), ?Overview, or ?Design.Overview')* *to see overall documentation.* *Attaching package: 'Design'* * The following object(s) are masked from package:survival :* * cox.zph Surv survfit * * The following object(s) are masked from package:Hmisc :* * .noGenenerics .R. .SV4. * *> options(scipen=20)* *> robcov(Reg1)* *Error in rep.default(1, p) : rep() incorrect type for second argument* *> library (lmtest)* *Loading required package: zoo* *Attaching package: 'lmtest'* * The following object(s) are masked from package:Design :* * lrtest * *> library (sandwich)* *> coeftest (Reg1, vcov=vcovHC(Reg1, type="HC0"))* *Error in terms.default(object) : no terms component* *>* I would like to solve these problems and to understand what the meanings of the errors messages are. Also I want to know if there is another way to obtain the HCSE through a function, because if I can not fix the problem my last alternative is to do it manually. I will thank a lot if somebody can help me Best wishes Guillermo [[alternative HTML version deleted]] ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.