# Simple Appplication of Law of Iterated Expectation

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 law of iterated expectations?

I believe, you can; we can think over $$E[Y_i|T_i=1,D_i=1]$$ first. By the law of iterated expectations, we have $$E[Y_i|T_i=1,D_i=1] = E[ E[Y_i|T_i=1,D_i=1,M_i] ] \\ =\int{E[Y_i|T_i=1,D_i=1,M_i=m]\ \ f_{M_i|D_i=1}(m)dm}$$ assuming independence of $$M_i$$ and $$T_i$$ given $$D_i$$. Finally, we have $$f_{M_i|D_i}(m)dm=dF_{M_i|D_i=1}(m)$$. So, for the first summand, you have exactly the same expression and for the second summand this follows exactly the same way.