Code:
clear input y x 1 0 0 1 1 1 0 0 end reg y x, vce(cl x) // SE of x is explicitly omitted drop if _n == 4 reg y x, vce(cl x) // SE of x is nonmissing drop if _n == 3 reg y x, vce(cl x) // SE of x is nonexistent
clear input y x 1 0 0 1 1 1 0 0 end reg y x, vce(cl x) // SE of x is explicitly omitted drop if _n == 4 reg y x, vce(cl x) // SE of x is nonmissing drop if _n == 3 reg y x, vce(cl x) // SE of x is nonexistent
. mat list V // SE Omitted
symmetric V[2,2]
x _cons
x 0
_cons 0 0
. mat list V //non-missing
x _cons
x 1.233e-32
_cons 0 0
. mat list V //Nonexistent
symmetric V[2,2]
x _cons
x -1.#IND
_cons -1.#IND -1.#IND
From the model Y= Xβ + e
1. The OLS estimate is βhat= (X'X)^{-1}(X'Y)
2. The variance estimate is σhat= ((Y-Xβ)' (Y-Xβ))/ (N-K)
input y x
1 0
0 1
1 1
0 0
end
reg y x
. reg y x
Source | SS df MS Number of obs = 4
-------------+------------------------------ F( 1, 2) = 0.00
Model | 0 1 0 Prob > F = 1.0000
Residual | 1 2 .5 R-squared = 0.0000
-------------+------------------------------ Adj R-squared = -0.5000
Total | 1 3 .333333333 Root MSE = .70711
------------------------------------------------------------------------------
y | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
x | 0 .7071068 0.00 1.000 -3.042435 3.042435
_cons | .5 .5 1.00 0.423 -1.651326 2.651326
------------------------------------------------------------------------------
. mat V= e(V)
. mat list V
symmetric V[2,2]
x _cons
x .5
_cons -.25 .25
. mat X= (1,0\ 1,1\ 1,1\ 1,0)
. mat list X
X[4,2]
c1 c2
r1 1 0
r2 1 1
r3 1 1
r4 1 0
. mat XP= X'
. mat XPX= XP*X
. mat XPXI = inv(XPX)
. mat list XPXI
symmetric XPXI[2,2]
c1 c2
c1 .5
c2 -.5 1
. mat Y= (1\0\1\0)
. mat list Y
Y[4,1]
c1
r1 1
r2 0
r3 1
r4 0
. mat XPY= XP*Y
. mat B= XPXI*XPY
. mat list B
B[2,1]
c1
c1 .5
c2 0
. mat YLXB= Y-XB
. mat YLXBP = YLXB'
. mat S= (YLXBP*YLXB)*(1/(4-2))
. mat VCE= S*XPXI
. mat list VCE
symmetric VCE[2,2]
c1 c2
c1 .25
c2 -.25 .5
mat X= (1,0\ 0,1\ 1,1) mat XP= X' mat XPX= XP*X mat XPXI = inv(XPX) mat Y= (0\1\1) mat XPY= XP*Y mat B= XPXI*XPY mat XB= X*B mat YLXB= Y-XB mat YLXBP = YLXB' mat S= (YLXBP*YLXB)*(1/(3-2)) mat VCE= S*XPXI mat list VCE
symmetric VCE[2,2] c1 c2 c1 0 c2 0 0
mata X= (1,0\ 0,1\ 1,1) Y= (0\ 1\ 1) XPXI = cholinv(cross(X,X)) B= XPXI*cross(X,Y) VCE= cross(Y-X*B,Y-X*B)*(1/(3-2))*XPXI XPXI B VCE end
Data | y x | |-------| 1. | 1 0 | 2. | 0 1 | 3. | 1 1 | The X matrix is | 1 0 | | 1 1 | | 1 1 |
. reg y x
Source | SS df MS Number of obs = 3
-------------+------------------------------ F( 1, 1) = 0.33
Model | .166666667 1 .166666667 Prob > F = 0.6667
Residual | .5 1 .5 R-squared = 0.2500
-------------+------------------------------ Adj R-squared = -0.5000
Total | .666666667 2 .333333333 Root MSE = .70711
------------------------------------------------------------------------------
y | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
x | -.5 .8660254 -0.58 0.667 -11.5039 10.5039
_cons | 1 .7071068 1.41 0.392 -7.984644 9.984644
------------------------------------------------------------------------------
. mat V= e(V)
. mat list V
symmetric V[2,2]
x _cons
x .75
_cons -.5 .5
mata : X= (1,0\ 1,1\ 1,1) : X 1 2 +---------+ 1 | 1 0 | 2 | 1 1 | 3 | 1 1 | +---------+ : Y= (1\0\ 1) : Y 1 +-----+ 1 | 1 | 2 | 0 | 3 | 1 | +-----+ : XX = cross(X, X) : XXI = cholinv(XX) : B= XXI*cross(X,Y) : B 1 +-------+ 1 | 1 | 2 | -.5 | +-------+ : VCE= cross(Y-X*B,Y-X*B)*(1/(3-2))*XXI : VCE [symmetric] 1 2 +-------------+ 1 | .5 | 2 | -.5 .75 | +-------------+ end
*DEFINE "a" AS THE SQUARE ROOT OF 2
. scalar a= sqrt(2)
. di a
1.4142136
*TAKE THE VALUE OF "a" AND SQUARE IT (THE ANSWER SHOULD BE 2)
. scalar b= 1.4142136*1.4142136
. di b
2.0000001
*TAKE AWAY 2 (THE ANSWER SHOULD BE 0)
. scalar c= b-2
*THE ANSWER
. di c
1.064e-07
Comment