Hi,
I am trying to run the following program to estimate direct and indirect effects. I constantly get errors when I do this with –mi-. Like “pp” not found. Moreover, the commands for –matrix- don’t seem to work with –mi-
Any feed is highly appreciated.
program myprog , rclass
capture drop lo pp io wt
mi estimate, saving(miest, replace): logit x m1 m2 c1 c2
mi predict lo using miest
mi xeq: gen pp = exp(lo)/(1+exp(lo))
mi xeq: gen io = ((1-pp)/pp)
mi xeq: gen wt = 1 if x==0
mi xeq: replace wt = io if x==1
mi estimate, saving(miest, replace) eform post: glm y x c1 c2, fam(poisson) link(log) vce(robust)
matrix bb_total= e(b)
scalar b_total=(bb_total[1,1])
return scalar b_total=bb_total[1,1]
mi estimate, saving(miest, replace) eform post: glm y x c1 c2 [pweight=wt] , fam(poisson) link(log) vce(robust)
matrix bb_direct = e(b)
scalar b_direct=(bb_direct[1,1])
return scalar b_direct=bb_direct[1,1]
return scalar b_indirect = b_total-b_direct
end
bootstrap exp(r(b_indirect)) exp(r(b_direct)) exp(r(b_total)), seed(32222) reps(50): myprog
estat bootstrap, all
I am trying to run the following program to estimate direct and indirect effects. I constantly get errors when I do this with –mi-. Like “pp” not found. Moreover, the commands for –matrix- don’t seem to work with –mi-
Any feed is highly appreciated.
program myprog , rclass
capture drop lo pp io wt
mi estimate, saving(miest, replace): logit x m1 m2 c1 c2
mi predict lo using miest
mi xeq: gen pp = exp(lo)/(1+exp(lo))
mi xeq: gen io = ((1-pp)/pp)
mi xeq: gen wt = 1 if x==0
mi xeq: replace wt = io if x==1
mi estimate, saving(miest, replace) eform post: glm y x c1 c2, fam(poisson) link(log) vce(robust)
matrix bb_total= e(b)
scalar b_total=(bb_total[1,1])
return scalar b_total=bb_total[1,1]
mi estimate, saving(miest, replace) eform post: glm y x c1 c2 [pweight=wt] , fam(poisson) link(log) vce(robust)
matrix bb_direct = e(b)
scalar b_direct=(bb_direct[1,1])
return scalar b_direct=bb_direct[1,1]
return scalar b_indirect = b_total-b_direct
end
bootstrap exp(r(b_indirect)) exp(r(b_direct)) exp(r(b_total)), seed(32222) reps(50): myprog
estat bootstrap, all
Comment