How to specify an instrumental variable model with felm()?

Viewed 2695

Due to implemented cluster standard error methods, I'd like to estimate an instrumental variable model with felm(). With AER::ivreg() and plm::plm() I can generate the same results. Specifying the function in felm(), however, doesn't seem very straightforward to me and I've failed.

I'm using the example of the ivreg() help, where tdiff and I(tax/cpi) both are instruments for log(rprice):

library(AER)
aer.hat <- ivreg(log(packs) ~ log(rprice) + log(rincome) | log(rincome) + tdiff + I(tax/cpi),
                 data=CigarettesSW, subset=year == "1995")
> coef(aer.hat)
 (Intercept)  log(rprice) log(rincome) 
   9.8949555   -1.2774241    0.2804048 

With plm() I could easily generate the same result:

library(plm)
plm.hat <- plm(log(packs) ~ log(rprice) + log(rincome) | log(rincome) + tdiff + I(tax/cpi),
               data=CigarettesSW[CigarettesSW$year == 1995, ], model="pooling")
> coef(plm.hat)
 (Intercept)  log(rprice) log(rincome) 
   9.8949555   -1.2774241    0.2804048 

But I failed with lfe::felm():

library(lfe)
felm.hat <- felm(log(packs) ~ log(rprice) + log(rincome) | 0 | log(rprice) ~ tdiff + I(tax/cpi) | 0 ,
               data=CigarettesSW[CigarettesSW$year == 1995, ])
> coef(felm.hat)
  (Intercept)         tdiff    I(tax/cpi) 
 1.000000e+00 -8.187404e-17 -3.294448e-17 

How can we do this in felm()?

data

data("CigarettesSW", package="AER")
CigarettesSW$rprice <- with(CigarettesSW, price/cpi)
CigarettesSW$rincome <- with(CigarettesSW, income/population/cpi)
CigarettesSW$tdiff <- with(CigarettesSW, (taxs - tax)/cpi)
1 Answers

We have

felm.hat <- felm(log(packs) ~ log(rincome) | 0 | (log(rprice) ~ tdiff + I(tax/cpi)),
                 data = CigarettesSW[CigarettesSW$year == 1995, ])
coef(felm.hat)
#        (Intercept)       log(rincome) `log(rprice)(fit)` 
#          9.8949555          0.2804048         -1.2774241 

Point 1: instrumented variable log(rprice) only needs to be in the third part, no need to also add it to the first one.

Point 2: in the third part I added parentheses; ?felm says something about interference between ~ and |, but I'm not sure why parentheses are needed in this case .

Also I removed | 0 at the end, it is not necessary.

Related