Solution (source code)

= Solution

For binary $A$, conditional covariance satisfies
$$
\operatorname{Cov}(A,Y\mid X)
=\pi(X)\{1-\pi(X)\}
\left\{\mathbb E(Y\mid A=1,X)-\mathbb E(Y\mid A=0,X)\right\}.
$$
By <conditional exchangeability> and <consistency of potential outcomes>, the difference in braces is $\mathbb E[Y(1)-Y(0)\mid X]$. Consequently
$$
\beta
=\mathbb E\!\left[
\pi(X)\{1-\pi(X)\}\{Y(1)-Y(0)\}
\right],
$$
so the required weight is
$$
w(X)=\pi(X)\{1-\pi(X)\}.
$$
This <overlap weight> emphasizes covariate strata with treatment probabilities near one half and downweights strata near a violation of <positivity in causal inference>.