Suppose $Y$ is a continuous variable and $Z$ is a dummy variable that equals $1$ with probability $p$.
$$\operatorname{Cov} (Z,Y) = p(1-p) {\left(E[Y\mid Z=1] -E[Y\mid Z=0]\right)}$$
How is this derived? I know that $$\begin{aligned}\operatorname{Cov} (Z,Y) &= E(ZY) -E(Z)E(Y) =E(ZY)-E(Y)p \\&= E(ZY)-p\left(pE[Y|Z=1]+(1-p)E[Y|Z=0]\right)\end{aligned}$$
But how do I move on from there? How can $E(ZY)$ be represented in this case?
Thank you
Firstly observe that $ZY$ is equal to $$ZY=\begin{cases}Y, & \text{ with probability } p\\ 0, & \text{ with probability } 1-p\end{cases}$$ Thus, by the formula of conditional probability (conditioning on $Z$) you get $$\begin{aligned}\mathbb E[ZY]&=P(Z=1)\Bbb E[ZY\mid Z=1]+P(Z=0)\mathbb E[ZY\mid Z=0]\\[0.2cm]&=p\Bbb E[1\cdot Y\mid Z=1]+(1-p)\Bbb E[0\cdot Y\mid Z=0]\\[0.2cm]&=p\Bbb E[Y\mid Z=1]\end{aligned}$$