英文:
Instrument variable three-part right side notation with ivreg in R
问题
"The vignette of ivreg
(https://cran.r-project.org/web/packages/ivreg/vignettes/ivreg.html) states: 当右侧公式中列出外生变量变得繁琐时,如果有很多外生变量,可以使用三部分右侧的便捷选项,如 y ~ x1 | x2 | z1 + z2,分别列出外生、内生和工具变量(仅对内生变量而言)。
我完全同意,重复许多变量确实很繁琐。我错过了使用三部分表示法的什么?
# 数据
data("SchoolingReturns")
# ivreg 基础
library(ivreg)
ivreg(log(packs) ~ log(rprice) + log(rincome) | salestax + log(rincome), data = CigaretteDemand)
# 不想重复所有内生变量
# ivreg 公式 DV ~ exo | endo | instrument
# 三部分右侧不起作用
ivreg(log(packs) ~ log(rprice) | log(rincome) | salestax, data = CigaretteDemand)
"
英文:
The vignette of ivreg
https://cran.r-project.org/web/packages/ivreg/vignettes/ivreg.html says As listing exogenous variables in both parts on the right-hand side of the formula may become tedious if there are many of them, an additional convenience option is to use a three-part right side like y ~ x1 | x2 | z1 + z2, listing the exogenous, endogenous, and instrumental variables (for the endogenous variables only), respectively.
I absolutely agree, that repeating a lot of variables is tedious. What am I missing to use the three-part notation?
# data
data("SchoolingReturns")
# ivreg basic
library(ivreg)
ivreg(log(packs) ~ log(rprice) + log(rincome) | salestax + log(rincome), data = CigaretteDemand)
# don't want to repeat all endogenous variables
# ivreg formulas DV ~ exo | endo | instrument
# three part right hand side not working
ivreg(log(packs) ~ log(rprice) | log(rincome) | salestax, data = CigaretteDemand)
答案1
得分: 0
ivreg
被另一个iv包屏蔽。 问题:
data("SchoolingReturns")
library(ivreg)
library(AER)
ivreg(log(packs) ~ log(rincome) | log(rprice) | salestax, data = CigaretteDemand)
Error in ivreg(log(packs) ~ log(rincome) | log(rprice) | salestax, data = CigaretteDemand) :
length(formula)[2] %in% 1:2 ist nicht TRUE
一切正常:
data("SchoolingReturns")
library(ivreg)
ivreg(log(packs) ~ log(rincome) | log(rprice) | salestax, data = CigaretteDemand)
英文:
ivreg
was masked by another iv-package. Problematic:
data("SchoolingReturns")
library(ivreg)
library(AER)
ivreg(log(packs) ~ log(rincome) | log(rprice) | salestax, data = CigaretteDemand)
Error in ivreg(log(packs) ~ log(rincome) | log(rprice) | salestax, data = CigaretteDemand) :
length(formula)[2] %in% 1:2 ist nicht TRUE
All good:
data("SchoolingReturns")
library(ivreg)
ivreg(log(packs) ~ log(rincome) | log(rprice) | salestax, data = CigaretteDemand)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论