# Proof Law of Iterated Expectations

I'm reviewing the proof of the law of iterated expectations from Hansen's book of econometrics. I'd like to know why in the first line of the proof it integrates with respect to the conditional density $$x_2$$ given $$x_1$$. Should it not be integrated with respect to the marginal function of $$x_1$$ since this conditional value is only a function of this variable?

$$\begin{split} E_{X_3|X_1}[X_3|X_1] =& E_{X_2|X_1}[E_{X_3|X_2 X_1}[X_3|X_2,X_1]|X_1]\\ =& \int^\infty_{-\infty} \left( \int^\infty_{-\infty} x_3 f_{X_3|X_2 X_1} (x_3|x_2,x_1) dx_3 \right) f_{X2|X1} (x_2|x_1) dx_2\\ =& \int^\infty_{-\infty} \int^\infty_{-\infty} x_3 f_{X_3|X_2 X_1} (x_3|x_2,x_1) f_{X2|X1} (x_2|x_1) dx_3 dx_2\\ =& \int^\infty_{-\infty} \int^\infty_{-\infty} x_3 f_{X_3 X_2|X_1} (x_3,x_2|x_1) dx_3 dx_2\\ =& \int^\infty_{-\infty} \int^\infty_{-\infty} x_3 f_{X_3|X_1} (x_3|x_1) f_{X_2|X_3 X_1} (x_2|x_3,x_1) dx_3 dx_2\\ =& \int^\infty_{-\infty} x_3 \left( \int^\infty_{-\infty} f_{X_2|X_3 X_1} (x_2|x_3,x_1) dx_2 \right) f_{X_3|X_1} (x_3|x_1) dx_3 \\ =& \int^\infty_{-\infty} x_3 \left( 1 \right) f_{X_3|X_1} (x_3|x_1) dx_3 \\ =& E_{X_3|X_1}[X_3|X_1] \end{split}$$

Subscripts are unnecessary, so the equality to prove is indeed $$E[X_3|X_1]=E[E[X_3|X_1,X_2]|X_1]$$
Note that $$E[X_3|X_1,X_2]$$ is a function of $$X_1,X_2$$, i.e. $$g(X_1,X_2)$$, which means we want $$E[g(X_1,X_2)|X_1]=\int g(X_1,X_2)f_{X_2|X_1}(x_2)dx_2$$
We integrate wrt $$f_{X_2|X_1}(x_2)$$ because, inside the expression, $$X_1$$ is treated as a fixed number and $$X_2$$ is the only random element.