Hello,

I am trying to obtain direct and indirect effects for multiple mediators with multiply imputed data using the inverse odds weighting approach. I’ve been working with the following code (from Sheikh, M. A., Abelsen, B., & Olsen, J. A. (2017). Education and health and well-being: direct and indirect effects with multiple mediators and interactions with multiple imputed data in Stata. Journal of Epidemiology and Community Health, 71(11), 1037-1045. doi:10.1136/jech-2016-208671):

Code:
program IOWMI , rclass
 
capture drop linpred predprob inverseodds wt_iow

* Fit a logistic regression model for IV (0, 1) conditional on the mediators and confounding variables.
mi estimate, saving(miest): logit IV M1 M2 M3 M4 confounding_variables

*Calculate linear prediction for each observation and use that to calculate predicted probabilities and inverse odds;
mi predict linpred using miest, xb
mi passive: gen predprob = exp(linpred)/(1+exp(linpred))
mi passive: gen inverseodds = ((1-predprob)/predprob)

*Calculate inverse odds weights, assign the IOW of each observation in the unexposed group (IV= 0) equal to 1.
mi passive: gen wt_iow = 1 if IV==0

* Compute an IOW by taking the inverse of the predicted log odds for each observation in the exposed group (IV=1).
mi passive: replace wt_iow = inverseodds if IV==1
 
*Estimate the total effect of IV using a generalized linear model (family=Poisson) of the regression of the outcome on IV and confounding variables, with link=log function;
mi estimate, saving(miest1) eform post: glm outcome IV confounding_variables , fam(poisson) link(log) vce(robust)
matrix bb_total= e(b_mi)
scalar b_total=(bb_total[1,1])
return scalar b_total=bb_total[1,1]
 
* Estimate the natural direct effect of IV via weighted generalized linear model *(family=Poisson) of the regression of the outcome on IV and confounding factors, with *link=log function and the weights obtained earlier
mi estimate, saving(miest2) eform post: glm outcome IV confounding_variables [pweight=wt_iow], fam(poisson) link(log) vce(robust)
matrix bb_direct = e(b_mi)
scalar b_direct=(bb_direct[1,1])
return scalar b_direct=bb_direct[1,1]
 
* Calculate the natural indirect effects of IV on the outcome via the proposed mediators by subtracting the direct effects from the total effects as;
return scalar b_indirect = b_total-b_direct
end
 
*Estimate 95% confidence intervals with bootstrapping
bootstrap exp(r(b_indirect)) exp(r(b_direct)) exp(r(b_total)), seed(12345) reps(100): IOWMI
estat bootstrap, all
Every time I run the code, I get the following warning:

Warning: Because IOWMI is not an estimation command or does not set e(sample), bootstrap has no way to determine which observations are used in calculating the statistics and so assumes that all observations are used. This means that no observations will be excluded from the resampling because of missing values or other reasons.

If the assumption is not true, press Break, save the data, and drop the observations that are to be excluded. Be sure that the dataset in memory contains only the relevant data.
And the following error code:

insufficient observations to compute bootstrap standard errors no results will be saved
r(2000);
I’ve tried including esample(total) and esample(direct) in the respective estimation codes to save the estimation samples e.g.

Code:
* Estimate the natural direct effect of IV via weighted generalized linear model *(family=Poisson) of the
regression of the outcome on IV and confounding factors, with *link=log function and the weights
obtained earlier
mi estimate, saving(miest2) eform  esample(direct) post: glm outcome IV confounding_variables [pweight=wt_iow], fam(poisson) link(log) vce(robust)
matrix bb_direct = e(b_mi)
scalar b_direct=(bb_direct[1,1])
return scalar b_direct=bb_direct[1,1]
However, I still get the same warning and error code.

When I check to see how the e(sample) is set using
Code:
. estimates esample
I get the following message:
e(sample) not set (0 assumed)
I know that with regular estimation you can set e(sample) using
Code:
. estimates esample: exp
But I don’t know how to adapt it for this situation. I’d appreciate any help you can provide.

Thanks,
Wumi