Q:

Proof for Simple Linear Regression: What am I doing wrong?

I am trying to prove the well known formula for simple linear regression $$SS_{TOTAL}=SS_{MODEL}+SS_{ERROR}$$
i.e
$$\sum_{i=1}^n (y_i - \bar{y})^2 =\sum_{i=1}^n (\hat{y}_i-\bar{y})^2+ \sum_{i=1}^n(\hat{y}_i - y_i)^2 $$
and I'm having more trouble than I care to admit. I go down the following road 
\begin{align*}
\sum_{i=1}^n (\hat{y}_i-\bar{y})^2+ \sum_{i=1}^n(\hat{y}_i - y_i)^2 &= \sum_{i=1}^{n}(\hat{y}_i^2-2\hat{y}_i\bar{y}+\bar{y}^2) +\sum_{i=1}^{n}(\hat{y}_i^2-2y_i\hat{y}_i+y_i^2)\\
&=\sum_{i=1}^n (\hat{y}_i^2)-2\bar{y}^2n +  \bar{y}^2n + \sum_{i=1}^n(\hat{y}_i^2) - \sum_{i=1}^n(2y_i\hat{y}_i)+\sum_{i=1}^n(y_i^2)\\
&=\sum_{i=1}^n (y_i^2)-2\bar{y}^2n +  \bar{y}^2n + \sum_{i=1}^n(\hat{y}_i^2) - \sum_{i=1}^n(2y_i\hat{y}_i)+\sum_{i=1}^n(\hat{y}_i^2)\\
&=\sum_{i=1}^n (y_i^2-2y_i\bar{y} +  \bar{y}^2) + 2\sum_{i=1}^n(\hat{y}_i^2 - y_i\hat{y}_i)\\
&=SS_{TOTAL}+2\sum_{i=1}^n(\hat{y}_i^2 - y_i\hat{y}_i)
\end{align*}
but I can't see any reason why the right term must be zero. Any help redirecting this ship would be greatly appreciated.

A:

\begin{align*}
\sum_{i=1}^n(\hat{y}_i^2 - y_i\hat{y}_i)&=\sum_{i=1}^n[\hat{y}_i(\hat{y}_i - y_i)]\\
&=\sum_{i=1}^n[(\hat{\beta}_0+\hat{\beta}_1x_{i1}+\cdots +\hat{\beta}_{p}x_{ip})\hat{\varepsilon}_i]\\
&=0
\end{align*}
where the last line follows because under OLS each individual term in the sum is zero (the strict exogeneity assumption implies that the mean of the residuals is zero and the correlation between the residuals and the independent variables is zero).
By the way, you can find a different proof of the result on Wikipedia. (It starts from the LHS of your first equation rather than the RHS.)

