Difference between E(Y) and E(Y|X) in regression In linear regression, we postulate a model for estimating $E(Y|X)= \beta_0 + \beta_1 x$
We also propose $Y= \beta_0 + \beta_1 x + \mu$ where μ is an error team with expectation equal to zero. We also assume $X$ are fixed, i.e. not random.
If we replace the first equation into the second, it will result:
$$Y=E(Y|X) + \mu$$
If we take expectation:
$$E(Y) = EE(Y|X) + E(\mu)$$
The first sumand is E(Y) by the law of iterated expectation. The second is 0 by assumption. So we have:
$$E(Y)=E(Y)$$ which is correct.
But if we directly took expectation in the second equation without replacing, it yields:
$$E(Y) = \beta_0 + \beta_1 x + E(\mu)$$
since $\beta_0 + \beta_1 x$ are not random. So it results:
$$E(Y)= \beta_0 + \beta_1 x \equiv E(Y|X)$$
So we finally arrive to $E(Y) = E(Y|X)$ which is not correct.
What's the explanation about this contradiction? When am I being wrong? Thank you in advance
 A: If $X$ is not random (i.e. just some constant), then $E[Y|X] = E[Y]$ so it is correct. If $X$ was random then $E[Y] = \beta_0 + \beta_1 E[X] + E[\mu]$ and so, $E[Y|X]$ would not be equal to $E[Y]$ in general
A: $\bullet$ You must bear in mind $\mathbb E[\boldsymbol \varepsilon |\mathbf X]=\mathbf 0\implies \mathbb E[\boldsymbol \varepsilon]=\mathbf 0$ but not $\mathbb E[\boldsymbol \varepsilon]=\mathbf 0\implies \mathbb E[\boldsymbol\varepsilon |\mathbf X]=\mathbf 0.$
$\bullet$ For non-stochastic regressors, you can straightforward use the unconditional conditions rather than conditional. However, when they are random, be careful with conditional and unconditional aspects.
A: Disclaimer: I only read your question correctly after i wrote this. If $X$ is non random then yeah $E(Y|X) = E(Y)$.
Your mistake comes down to an abuse of notation. Within usual notation $X$ is a random variable which for simplicity, takes values in the reals. $x$ is one such value $X$ could take. Let's sensibly define
$$ Y := \beta_0 + \beta_1X + \mu$$
with $E(\mu|X = x) = 0$ for  all $x \in \mathbb{R}$
Now just as $X$ and $x$ are nor the same thing $E(Y|X)$ and  $E(Y|X = x)$ are also not the same. The first conditions on the random value of $X$ making it itself a random value while the second conditions on the specific event of $X=x$ meaning it is not random anymore. Just dependent on the chosen value of $x$.
To finish out:
$E(E(Y|X)) = E(\beta_0 + \beta_1X) = \beta_0 + \beta_1E(X) = E(Y)$
$E(E(Y|X =x)) = E(\beta_0 + \beta_1x) = \beta_0 + \beta_1x = E(Y|X=x)$ because that already isn't random anymore and so the second $E$ doesn't do anything.
Speaking of  notation abuse: $\mu$ usually refers to a mean while error terms are expressed with something like $\epsilon$ or $e$
