Given the linear model:
yy=X1bb1+X2bb2+ee
We want to find the first order conditions of the problem:
bb1,bb2argminee′ee
bb1,bb2argmin(yy−y^y^)′(yy−y^y^)
The objective function of the problem is equivalent to:
ee′ee=(yy−y^y^)′(yy−y^y^)=yy′yy−2yy′y^y^+y^y^′y^y^=yy′yy−2yy′(X1bb1+X2bb2)+(X1bb1+X2bb2)′(X1bb1+X2bb2)=yy′yy−2yy′X1bb1−2yy′X2bb2+bb1′X1′X1bb1+2bb1′X1′X2bb2+bb2′X2′X2bb2
Now we take the gradient of the function with respect to bb1 and bb2:
∂bb1∂f=0⟹−2X1′yy+2X1′X1bb1+2X1′X2bb2=0⟹X1′X1bb1+X1′X2bb2=X1′yy
∂bb2∂f=0⟹−2X2′yy+2X2′X2bb2+2X2′X1bb1=0⟹X2′X2bb2+X2′X1bb1=X2′yy
Which we can package into a block of conditions like so:
[X1′X1X2′X1X1′X2X2′X2][bb1bb2]=[X1′yyX2′yy]