1

I am very new to R, and trying to reproduce a Stata Output. I have the following Regression

formula2 <- as.formula(paste("lnwd ~  dreformd + ", paste("", PredictorVar2,  collapse='+'), "+", paste("", PredictorYr, collapse='+')))

with dreformd being endogenous. I want to run a 2SLS by regressing dreformd on three instruments

datatwo$qz1 <- factor (with (datatwo, ifelse ((q1 == 1), 1, 0)))
datatwo$qz2 <- factor (with (datatwo, ifelse ((q1 == 2), 1, 0)))
datatwo$qz3 <- factor (with (datatwo, ifelse ((q1 == 0|q1 == 3), 1, 0)))

This would be my code:

library(car)
iv = ivregress(formula2, dreformd ~ qz1 + z2 + qz3, datatwo)

And all I get as Output is

Error in ivregress(formula2, dreformd ~ qz1 + qz2 + qz3, datatwo) : 
could not find function "linearHypothesis"

I am lost here, I've tried everything and have no clue where the problem is. I've also tried using the ivreg function, but R cannot find that one either. The AER and CAR packages are installed. What am I missing ?

EDIT: tried installing CAR and AER with dependencies, still get the same error. The car package cannot load, and there is no pbkrtest package. Tried installing it, I get this error:

Warning in install.packages :
  package ‘pbkrtest’ is not available (for R version 3.2.1)
Marie
  • 21
  • 2
  • 7
  • Loading the `AER` package? Have you tried library(AER)? – Alex Jun 19 '16 at 15:23
  • 1
    is [this](https://gist.github.com/tony91782/950834#file-ivregress-r-L34) where you are getting that function? – rawr Jun 19 '16 at 15:23
  • I've loaded it, doesn't change anything. I just get an error message that the car package could not be loaded (not sure why this happens when trying to load AER) @Alex – Marie Jun 19 '16 at 15:24
  • @rawr yes, exactly – Marie Jun 19 '16 at 15:24
  • As hinted by Alex, `AER` has a `ivreg` function. There is also a package called `ivpack` that might be worth a look. – lmo Jun 19 '16 at 15:31
  • Tried using ivreg as well, all I get is Error: could not find function "ivreg" – Marie Jun 19 '16 at 15:32
  • I'm not getting this error. are you sure `library('car')` works without error? – rawr Jun 19 '16 at 15:36
  • Do you have `AER` installed and loaded? `install.packages(AER, dependencies=TRUE); library(AER)`. – lmo Jun 19 '16 at 15:36
  • Yes I do, when I load AER I get an error though `Lade nötiges Paket: car` `Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : es gibt kein Paket namens ‘pbkrtest’ In addition: Warning messages: 1: Paket ‘AER’ wurde unter R Version 3.2.5 erstellt 2: Paket ‘car’ wurde unter R Version 3.2.5 erstellt Error: Paket ‘car’ konnte nicht geladen werden` – Marie Jun 19 '16 at 15:40
  • Basically it tells me there is no package named "pbkrtest" (whatever that is) and that the car package could not be loaded. – Marie Jun 19 '16 at 15:41
  • Maybe it's worth mentioning that all other packages are working fine, and regular regressions run smoothly as well. It's just the IV stuff that refuses to cooperate D: – Marie Jun 19 '16 at 15:42
  • http://stackoverflow.com/questions/35207624/package-pbkrtest-is-not-available-for-r-version-3-2-2 maybe you are using an old version of r. then you should update the packages after updating r. check your `sessionInfo()` and add it to your question – rawr Jun 19 '16 at 15:59
  • Have you updated R? The current stable Version is 3.3.0 . – Alex Jun 19 '16 at 19:06

1 Answers1

2

I was struggling with this too. You have to install car. R is going to ask you to install several other packages in the process. I went one by one (as far as I remember there were 7 or 8 different packages) and at the end could run library(car) and then R accept the function linearHypothesis

NelsonGon
  • 13,015
  • 7
  • 27
  • 57