AER::ivreg
希望您在一个分隔符|
之后 for each 回归变量提供一个工具,所以不是
> library(AER)
> ivreg(log(packs) ~ population + tax | log(rprice) | rtdiff, data=c1995)
Error in ivreg(log(packs) ~ population + tax | log(rprice) | rtdiff, data = c1995) :
length(formula)[2] %in% 1:2 is not TRUE
它是
> ivreg(log(packs) ~ log(rprice) + population + tax | rtdiff + population + tax, data=c1995)
Call:
ivreg(formula = log(packs) ~ log(rprice) + population + tax | rtdiff + population + tax, data = c1995)
Coefficients:
(Intercept) log(rprice) population tax
7.241e+00 -5.089e-01 -7.907e-09 -4.202e-03
你可以考虑lfe::felm
,这更简洁,也可能更符合你的直觉.
> library(lfe)
> felm(log(packs) ~ population + tax | 0 | (log(rprice) ~ rtdiff), data=c1995)
(Intercept) population tax `log(rprice)(fit)`
7.241e+00 -7.907e-09 -4.202e-03 -5.089e-01
Data:个
> data("CigarettesSW", package="AER")
> CigarettesSW <- transform(CigarettesSW,
+ rprice=price/cpi,
+ rtdiff=(taxs - tax)/cpi
+ )
> c1995 <- subset(CigarettesSW, year == "1995")