I have the following model:
$$ y_{i} = \alpha + \beta{d_{i}} + X^{'}_{i}\gamma + \epsilon_{i} $$
Where $d_{i}$ is a dummy variable and $X^{'}_{i}$ is a vector of control variables. I want to estimate the the causal effect of $d_{i}$. Suppose that the regression is saturated in $X_{i}$ so that $E(d_{i}|X_{i})$ is linear. But suppose also that the model above is not actually the conditional expectation function (which is non-linear).
I want to find how $\beta$ is related to $E(y_{1,i}-y_{0,i})$ (the causal effect on $y_{i}$ of switching the dummy $d_{i}$ on and off).
Now since the regression is saturated in $X_{i}$ I can write $\beta$ as $\frac{Cov(y_{i},\hat{d_{i}})}{Var(\hat{d_{i}})}$ where $d_{i}$ is the residual from regressing $d_{i}$ on the covariates $X^{'}_{i}$. And I know $\hat{d_{i}} = d_{i} - E(d_{i}|X_{i})$ so therefore:
$$ \beta = \frac{E(y_{i}(d_{i}-E(d_{i}|X_{i})))}{E((d_{i}-E(d_{i}|X_{i}))^{2})} $$
So here's my question: in the notes I am working from, the next step is written as:
$$ \beta = \frac{E(E(y_{i}|d_{i},X_{i})(d_{i}-E(d_{i}|X_{i})))}{E((d_{i}-E(d_{i}|X_{i}))^{2})} $$
I am confused because if this step has been reached using the Law of Iterated Expectations, then why hasn't the expectation sign also been applied to the second term inside the bracket (I am assuming they can be separated due to Conditional Independence)? And wouldn't that term equal zero?