Find Cov(x,y) as a function of x Prove that in any bivariate distribution,
$$Cov[x,y] = Cov_x[x,E[y|x]] = \int_x(x - E[x]) E[y|x] f_x(x) dx. $$
(Note that this is the covariance of x and function of x.)
Source: Econometric Ananlyis (William Greene) Appendix B.8.1
Edit: The question is not a homework problem, although I was looking to prove it on my own. Prior to reading the answer below, I was stuck regarding how the $y$ in $Cov[x,y]$ got replaced by $E[y|x]$ in $Cov_x[x,E[y|x]]$. I guessed that was not much progress, so refrained from posting my attempt at solving. Thank you.

First write the definition of covariance,
$$cov_x(X,E(Y|X)) = E_x (X E(Y|X)) - E(X)E_x(E(Y|X)).$$
Continue by writing the definition of expected value of continuous R.V
$$\int_x x E(Y|X) f_x dx - E(X) \int_x E(Y|X) f_x dx = \int_x (x - E(X)) E(Y|X) f_xdx.$$
According to the law of total expectation, the second term is $E(X)E_x(E(Y|X)) = E(X)E(Y)$. We will write the first term as,
$$\int_x x E(Y|X) f_x dx = \int_x x f_x \int_y y f_{y|x} dy dx = \int_x x f_x \int_y y \frac{f_{x,y}}{f_x}dy dx = \int_x \int_y x y f_{x,y} dy dx $$
We obtain that,
$$ \int_x \int_y x y f_{x,y} dy dx = E(XY).$$
Combining the two, we obtain the first equality.
