# How to obtain expressions for coefficients from OLS formula?

Consider the standard linear regression model: $y_i = \alpha + \beta D_i + e_i$ where the coefficients are defined by linear projections and $D_i$ is a dummy variable. In the population, the coefficients are given by:

$$\alpha = E[y_i \mid D_i =0] \ \text{and} \ \beta = E[y_i \mid D_i = 1] - E[y_i \mid D_i =0]$$

Using OLS to estimate the coefficients, we get:

$$\widehat{\alpha} = \frac{1}{\sum_{i=1}^{N}1(D_i=0)}\sum_{i=1}^{N}1(D_i=0)y_i$$

$$\widehat{\beta} = \frac{1}{\sum_{i=1}^{N}1(D_i=1)}\sum_{i=1}^{N}1(D_i=1)y_i-\frac{1}{\sum_{i=1}^{N}1(D_i=0)}\sum_{i=1}^{N}1(D_i=0)y_i$$

In other words, $\widehat{\alpha}$ is just the sample mean of $y_i$ in the subsample with $D_i=0$.

My question is, how can we arrive at the above coefficient estimates by using the standard OLS formulas? That is:

$$\widehat{\alpha} = \overline{y} - \overline{D}\widehat{\beta} \ \ \text{and} \ \ \widehat{\beta} = \frac{\sum_{i=1}^{N}(D_i - \overline{D})(y_i - \overline{y})}{\sum_{i=1}^{N}(D_i - \overline{D})^2}$$ where the bars represent sample means.