I have regressed y on x1 and x2 in python but I get very different results when I do it by hand. I am using the following formulae:
http://faculty.cas.usf.edu/mbrannick/regression/Reg2IV.html
I am having hard time finding the formulae for a, b1 and b2 in the 2-variate regression:
$$ y = a + b_1x + b_2x $$
It is a bit silly to ask for this but everyone seems to be doing this with a software package and I want to do it by hand. Any useful references would be very appreciated.
The OLS estimator of $b$ is given by $$ \hat{b} = \mathbf{(X ^ T X)^{-1}X ^ T y }, $$ where $\mathbf{X}$ is $ n\times 3$ matrix, where the first column is all ones for the intercept and the other two consist of your $x_{1}$ and $x_2$ values respectively. Same structure holds for any number of variables $p$ with $\mathbf{X}_{n \times p}$.