# Law of Iterated Expectations Example

Consider a randomized experiment (AB test), where $$n$$ units are randomized into the treatment group $$T_i=1$$ and control group $$T_i=0$$. Let $$M_i\in P$$ denote the observed value of a continuous variable that is realized after the exposure to the treatment where $$P$$ is the support of $$M_i$$. $$D_i$$ is a binary variable. $$F$$ represents the distribution function. Can we re-write the expression:

$$x=\int \{\mathbb{E}(Y_i|T_i=1, M_i=m, D_i=1) - \mathbb{E}(Y_i|T_i=0, M_i=m, D_i=1)\}\mathrm{d} F_{M_i|D_i=1}(m),$$

into

$$x = \mathbb{E}(Y_i|T_i=1, D_i=1) - \mathbb{E}(Y_i|T_i=0, D_i=1)$$

by using the (general) law of iterated expectations?

Without further assumption it is not correct. From the definition of a conditional expectation and the properties of a density we have (for $$Y$$ continuous):
$$\mathbb{E}(Y_i|T_i=1, D_i=1) - \mathbb{E}(Y_i|T_i=0, D_i=1) \\ = \int y f_Y(y|T_i=1, D_i=1) dy - \int y f_Y(y|T_i=0, D_i=1)dy \\ = \int y \int f_{Y|M}(y|T_i=1, M_i=m, D_i=1)f_M(m|T_i=1, D_i=1)dm dy \\ - \int y \int f_{Y|M}(y|T_i=0, M_i=m, D_i=1)f_M(m|T_i=0, D_i=1)dm dy$$
The density of $$M$$ is conditional to $$T_i=1$$ in the first case but conditional to $$T_i=0$$ in the last line, and cannot be factorized. However, if $$M_i|D_i$$ and $$T_i$$ are statistically independent, then it works, because $$f_M(m|T_i=1, D_i=1)=f_M(m|T_i=0, D_i=1)$$ in that case.