I was reading the Econometrics textbook by Damodar Gujarati, and in the book, he develops the sample regression function using the following equations.
$\sum Y_{i} = n \beta_{1} + \beta_{2}\sum X_{i}$
$\sum Y_{i} X_{i} = \beta_{1} \sum X_{i} + \beta_{2}\sum X_{i}^{2}$
I get this. But from these equations, we get something of the form of the following, and I am really confused as to how we get the following from the preceding equations as well as the inner workings of the following equations themselves.
$\beta_{2} = \frac{n\sum X_{i}Y_{i} - \sum X_{i}\sum Y_{i}}{n \sum X_{i}^{2} - (\sum X_{i})^{2}}$
= $\frac{\sum(X_{i}-\bar{X})(Y_{i}-\bar{Y})}{\sum(X_{i}-\bar{X})^{2}}$
Additionally, let me point out that $\bar{X}$ and $\bar{Y}$ are the means of X and Y respectively.
I am really confused as to how we get the second line of this equation from the first.
Finally we have that:
$\beta_{1} = \frac{ \sum X_{i}^2 \sum Y_{i} - \sum X_{i} \sum X_{i}Y_{i} }{n\sum X_{i}^2 - (\sum X_{i})^2}$
= $\bar{Y} - \beta_{2}\bar{X}$
Can someone please tell me how these equations follow from the first two?
Multiply the first equation by $\sum X_{i} $ and the latter by $n$ to get
$\sum Y_{i} \sum X_{i} = n \beta_{1} \sum X_{i} + \beta_{2}(\sum X_{i})^2$
$n\sum Y_{i} X_{i} = n\beta_{1} \sum X_{i} + n\beta_{2}\sum X_{i}^{2}$
Substract the 2nd equation from the first
$\sum Y_{i} \sum X_{i} - n\sum Y_{i} X_{i} = \beta_{2}(\sum X_{i})^2-n\beta_{2}\sum X_{i}^{2}$.
You can solve
$\beta_{2} = \frac{n\sum X_{i}Y_{i} - \sum X_{i}\sum Y_{i}}{n \sum X_{i}^{2} - (\sum X_{i})^{2}}$
Now plug in this solution to the first initial equation to solve for $\beta_1$.