我已经有了这个 IV 规范,我想将其绘制为 x1 对 y 的边际效应作为 x2 的函数:
ivreg2 y= (x1 x1#x2 = z1 z1#x2), endog(x1 x1#x2)
具有
x1
和 x2
连续和 z1
二进制。
我尝试这样做,但置信区间似乎是线性的。这正常吗?
generate baseline = 1 if e(sample)
matrix b1 = e(b1)
matrix b2 = e(b2)
scalar b1 = b[1,1]
scalar b2 = b[1,2]
scalar varb1 = V[1,1]
scalar varb2 = V[2,2]
scalar covb1b2 = V[1,2]
generate MVL = x2
gen conbl = b1 + b2 * MVL
gen consl = sqrt(varb1 + varb2 * (MVL^2) + 2 * covb1b2 * MVL)
gen al = 1.65 * consl
gen upperl = conbl + al
gen lowerl = conbl - al
graph twoway line conbl MVL, lpattern(solid) clwidth(medium) clcolor(black) || line upperl MVL, clpattern(longdash) clwidth(thin) clcolor(gs8) sort || line lowerl MVL, clpattern(longdash) clwidth(thin) clcolor(gs8) sort ||, yscale(noline) xscale(noline) yline(0, lcolor(black)) xtitle("x2", size(3)) xsca(titlegap(2)) ysca(titlegap(2)) ytitle("Marginal Effect of x1", size(3)) scheme(s2mono) graphregion(fcolor(white)) legend(off)
谢谢你!
试试这个:
use "http://fmwww.bc.edu/ec-p/data/hayashi/griliches76.dta," clear
ivreg2 lw (c.iq c.iq#c.s = c.med c.med#c.s)
margins, dydx(iq) at(s = (9(1)18))
marginsplot