I have a questions about the so-called "zero conditional mean" assumption often made in the context of regression analysis. I am struggling to see how it could be violated, or rather where it is violated.
$ E[\hat \beta] = E[\left(\mathbf X' \mathbf X\right)^{-1}\mathbf X' \mathbf Y] = \beta + E[\left(\mathbf X' \mathbf X\right)^{-1}\mathbf X' \mathbf \varepsilon] $
Above, I give the expectation of the OLS estimate in matrix form. My problem is that I do not see how it is possible for $\ E[X' \varepsilon]$ to not equal zero. Now before you all give me examples from the literature on endogeneity of when there is this bias, the reason I have trouble with this is because whenever we formulate our population regression function as a conditional expectation, by definition the $E[\ X' \varepsilon] =0 $. In other words, in any population regression function defined as a conditional expectation, we have that the errors are uncorrelated with our regressors. This is because their correlation is defined to be zero. To put it formally (and by the Law of Iterated Expectations):
$ \ E[Y|X]=B_{0}+B_{1}X_{i} \Rightarrow Y_{i}=E[Y|X]+\varepsilon _{i}\Rightarrow E[Y|X_{i}]=E[Y|X]+E[\varepsilon|X ]\Rightarrow E[\varepsilon_{i}|X]=0\ $
But this raises the question: what is the correlation term in the OLS estimates referring to, and how can it be that the assumption does not hold?
EDIT: Some of the comments have suggested that I am confusing errors with residuals. However, this is not obviously the case. My point is as follows. When running a regression, we use OLS to tell us about: $ \ E[Y|X]$. However, for any way in which I specify $ \ E[Y|X]$ it seems as though I am mathematically committing myself to $\ E[\varepsilon_{i}|X]=0\ $. Could someone perhaps specify a population regression function (as a conditional expectation) where this is not the case?
For example, if we consider $\ E[Y|X] = B_{0}+B_{1}X_{i}+B_{2}X_{i} $ and we suppose that $ E[\varepsilon_{i}|X] = g(x) $. Then, by iterated expectations we get that:
$\ Y_{i}=B_{0}+B_{1}X_{i}+B_{2}X_{i}+\varepsilon_{i} $
$\ E[Y|X]=E[B_{0}+B_{1}X_{i}+B_{2}X_{i}|X] + E[\varepsilon|X] $
$\ E[Y|X]=E[Y|X] + E[\varepsilon|X] $
$\ E[Y|X]=E[Y|X] +g(x) $
$\ g(x)=0$
If $\ g(x) $ does not equal zero, then we have a mathematical contradiction, and therefore I have no idea how in the OLS estimates, we can have anything other than $ \ E[X' \varepsilon=0]\ $.
EDIT 2:
It seems I have found a potential solution to my problem:
CEF: $\ E[Y|X]=B_{0}+B_{1}X_{i}+B_{2}X_{i} $
Regression $\ Y_{i}= B_{0}+B_{1}X_{i}+B_{2}X_{i} + \varepsilon_{i} $
The idea is that $\ E[X|\varepsilon]=0 $ must hold for the CEF, but it may not hold for the regression function. Is this on the right track?