Need help solving the algebra of this econometrics question because the answer I got is different 
Have been working on this for probably 2-3 hours and can't figure it out. I got very close, but got stuck at a point where the numerator has ∑yi^2∑xi instead of ∑yi∑xi^2 and my denominator doesn't have anything after n∑xi^2. Would love some help seeing where I went wrong. My professor mentioned something today about doing something like adding and subtracting a term (that cancel to 0, which would make it easier to solve) but I don't know where to add anything.
 A: The terms $X_i - \bar X$ are the residuals.  You probably already know that they don't change when you add a constant to all the $X_i:$ the same constant will be added to their mean and that is subtracted off as part of the "$-\bar X$" term.
Avail yourself of this flexibility by adding $-\bar X$ to all the $X_i.$ This cannot change $\hat\beta_1,$ which depends only on the residuals. The new mean is $\bar X = 0.$  Notice, since $\bar X$ is a multiple of the sum of the $X_i,$ this implies $\sum X_i = 0,$ too.  We'll exploit this below.
Given any putative formula for $\hat \beta_0,$ the only thing you need to show is that $\hat\beta_1 \bar X + \hat\beta_0 = \bar Y$ (because that's true of equation [2], which determines $\hat\beta_0$).
Plugging $\bar X = 0$ into [2] shows that the only thing left to demonstrate is that
$$\bar Y = \hat\beta_1 \bar X + \hat \beta_0 = \hat\beta_0.$$
Plugging $\bar X = 0$ into the last formula in your question gives a fraction with common factors of $\sum X_i^2$ on top and bottom.  Because none of these formulas work when this sum is zero, you may assume it's nonzero, so the common factors cancel, giving
$$\frac{\sum Y_i \sum X_i^2 - \left(\sum X_i\right)(\text{other stuff})}{n\sum X_i^2 - \left(\sum X_i\right)^2} = \frac{ \sum Y_i \sum X_i^2 - 0}{n \sum X_i^2 - 0} = \frac{\sum Y_i}{n} = \bar Y,$$
QED.
We could even have avoided these calculations by applying the same considerations to observe that the responses $Y_i$ can similarly be adjusted so that $\sum Y_i = 0.$  That leaves you having to prove that $\hat\beta_0 = 0.$  But when you plug $\bar Y = \bar X = \sum Y_i = \sum X_i = 0$ into the last formula, the numerator obviously reduces to $0$ and you're done--without having done a single algebraic step.
