Hi,
I am trying to run the following program to estimate direct and indirect effects using the approach proposed by Eric Tchetgen.
Ref: Tchetgen Tchetgen EJ. Inverse odds ratio-weighted estimation for causal mediation analysis. Stat Med. 2013;32(26):4567–4580.
I first imputed data using –mi-. Than here is the stata commands I am using to estimate total, direct, and indirect effects;
program myprog , rclass
capture drop lo pp io wt
mi estimate, saving(miest): 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) 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) 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
The first error I get is:
-myprog already defined-
I change the program name to something else, but it would be nice not having to do that.
The second problem (after giving a new name to program) is that the total observations in the results indicate that the analysis does not use imputed datasets. So the bootstrapping is only giving results (estimates for b_indirect, b_direct, and b_total) for the complete cases.
The third issue is that the confidence intervals do not correspond with the p value. The CI include 1, but the p value is <0.01.
I'm not a programming expert so any feedback is highly appreciated.
Thankfully,
Massao
I am trying to run the following program to estimate direct and indirect effects using the approach proposed by Eric Tchetgen.
Ref: Tchetgen Tchetgen EJ. Inverse odds ratio-weighted estimation for causal mediation analysis. Stat Med. 2013;32(26):4567–4580.
I first imputed data using –mi-. Than here is the stata commands I am using to estimate total, direct, and indirect effects;
program myprog , rclass
capture drop lo pp io wt
mi estimate, saving(miest): 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) 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) 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
The first error I get is:
-myprog already defined-
I change the program name to something else, but it would be nice not having to do that.
The second problem (after giving a new name to program) is that the total observations in the results indicate that the analysis does not use imputed datasets. So the bootstrapping is only giving results (estimates for b_indirect, b_direct, and b_total) for the complete cases.
The third issue is that the confidence intervals do not correspond with the p value. The CI include 1, but the p value is <0.01.
I'm not a programming expert so any feedback is highly appreciated.
Thankfully,
Massao
Comment