Proving the 'pull out property of conditional expectation Can someone please help me prove the following:
For discrete random variables $X$ and $Y$ defined on the same sample space,
$$
E(Yg(X)|X = x) = g(X)E(Y|X = x).
$$
I read that since we are conditioning on $\{X=x\}$, $g(X)$ is a constant, so it can be pulled out, but I don't think this is a proof.
What I got so far:
$g(X)E(Y|X = x) = g(X)$ summation over $y \, ( yP(Y=y | X = x) )$
$E(Yg(X)|X = x) =$ summation over $y \,( yg(x)P({X=x},{Y=y} | X=x) )$
I am quite confused.
Are the two lines above correct? Is $P(\{X=x\},\{Y=y\} | X=x) = P(Y=y | X = x)$ ?
The summations are over y, so we can pull out $g(x)$ but we want $g(X)$, or are they really the same thing?
Sorry, I don't know LaTex.
 A: By definition of conditional expectation (discrete case)
$$ E[Y g(X)| X = x] = \dfrac{\sum_z z P(Y g(X) = z, X = x)}{P(X=x)} $$
where the sum is over all possible values of $Y g(X)$, and we're assuming $P(X=x) \ne 0$.
Since we are requiring $X = x$, only the possible values when $X = x$ need to be
considered, and these are $y g(x)$ where $y$ is a possible value of $Y$.
If $g(x)$ happens to be $0$, then $z = 0$ is the only possible value and the sum
is $0$.  So in this case $E[Y g(X)|X=x] = 0 = g(x) E[Y|X=x]$.  Otherwise,
  $P(Y g(X) = y g(x), X = x) = P(Y = y, X=x)$, so
$$   \eqalign{\dfrac{\sum_z z P(Y g(X) = z, X = x)}{P(X=x)} &= \dfrac{\sum_y y g(x) P(Y = y, X = x)}{P(X=x)}\cr
&= g(x) \dfrac{\sum_y y P(Y = y, X = x)}{P(X=x)} \cr
&=  g(x) E(Y|X=x)}$$
Actually, there is a bit of a caveat: we need
to assume $E(Y|X=x)$ exists, otherwise the right side $g(x) E[Y|X=x]$ 
is undefined.  Of course if $g(x) \ne 0$ the left side would also
be undefined, but in the case $g(X) = 0$ (where  we don't want to assign a value to $0 \times undefined$) the left side would be $0$.
