使用R中的ivreg工具变量三部分右侧符号表示法。

huangapple go评论72阅读模式
英文:

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)

huangapple
  • 本文由 发表于 2023年1月9日 17:02:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/75055025.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定