Finding conditional variance I know the marginal Variance of $\operatorname{Var}(Y) = E(Y^2)- (E(Y))^2$ and conditional variance of $\operatorname{Var}(Y|X)$ is $E((Y-E(Y|X))^2\mid X=x)$.
I am trying to expand out the last expression.
\begin{align}\operatorname{Var}(Y|X) &=
= E((Y-E(Y|X))^2|X=x)\\
&=E(Y^2-2YE(Y|X)+(E(Y|X))^2|X=x)\\
&=E(Y^2|X=x) -2E(YE(Y|X)|X=x)+E(E(Y|X))^2|X=x)\\
&=E(Y^2|X=x) -2E(YE(Y|X))  +E(E(Y|X))^2\\
&=E(Y^2|X=x) - 2E(YE(Y|X)) + Y^2\\
&=E(Y^2|X=x) - 2Y^2 + Y^2\\
&=E(Y^2|X=x) - Y^2 
\end{align}
Am I right? Two things I was not very sure: what is the value of $E(E(Y|X)|X=x)$ and $E(YE(Y|X))$?
If i am wrong anywhere, do correct me...
 A: In general, $E(E(Y|X)^2|X)\ne E(E(Y|X))^2$ (what you use) and $E(E(Y|X)^2|X)\ne E(E(Y|X)^2)$ (what you might want to use instead). Rather, since $E(Y\mid X)$ is $\sigma(X)$-measurable,
$$
E(E(Y|X)^2|X)=E(Y|X)^2.
$$
Likewise, $E(YE(Y|X)|X)\ne E(YE(Y|X))$ in general, rather
$$
E(YE(Y|X)|X)=E(Y|X)^2.
$$
Edit: For every $\mathcal G$-measurable random variable $\xi$ and every random variable $\eta$, $E(\eta|\mathcal G)$ is $\mathcal G$-measurable and $E(\xi\eta|\mathcal G)=\xi E(\eta|\mathcal G)$. Applying these to suitable choices of $\xi$ and $\eta$ and to $\mathcal G=\sigma(X)$ should give you everything you need.
A: \begin{align}
\text{var}\left(Y\mid X\right) &= \mathbb{E}\left\{\left(Y-\mathbb{E}\left(Y\mid X\right)\right)^2\mid X\right\}\\
&=\mathbb{E}\left(Y^2\mid X\right)-2\mathbb{E}\left\{Y\mathbb{E}\left(Y\mid X\right)\mid X\right\}+\mathbb{E}\left\{\left(\mathbb{E}\left(Y\mid X\right)\right)^2\mid X\right\}\\
\end{align}
Now, given $X$, you have that
\begin{align}
\mathbb{E}\left\{Y\mathbb{E}\left(Y\mid X\right)\mid X\right\} = \mathbb{E}\left(Y\mid X\right)\mathbb{E}\left(Y\mid X\right) = \left(\mathbb{E}\left(Y\mid X\right)\right)^2
\end{align}
and that
\begin{align}
\mathbb{E}\left\{\left(\mathbb{E}\left(Y\mid X\right)\right)^2\mid X\right\} = \left(\mathbb{E}\left(Y\mid X\right)\right)^2
\end{align}
Thus,
\begin{align}
\text{var}\left(Y\mid X\right) &=\mathbb{E}\left(Y^2\mid X\right)-\left(\mathbb{E}\left(Y\mid X\right)\right)^2
\end{align}
