* Using the MATRIX command for OLS estimation. sample 1 5 read y / byvar list 3 1 8 3 5 read x / rows=5 cols=3 list 1 3 5 1 1 4 1 5 6 1 2 4 1 4 6 * Get the regressors in columns 2 and 3 of the matrix x. matrix x1=x(0,2) matrix x2=x(0,3) print x1 x2 * OLS Estimation ols y x1 x2 * Test the null hypothesis that the sum of the coefficients is 0. test x1+x2=0 * Now use the MATRIX command to get the OLS estimates matrix b=inv(x'x)*x'y * Sum of squared residuals - SSE matrix ee=y'y-(b'(x'y)) * Error variance - SIGMA**2 gen1 df=2 gen1 sig2=ee/df print ee sig2 * Get the standard errors matrix varcov=sig2*inv(x'x) matrix stderr=sqrt(diag(varcov)) print b stderr * F-test statistic for testing the null hypothesis that the * sum of the coefficients is 0. read r / rows=1 cols=3 list 0 1 1 read lr / rows=1 cols=1 list 0 matrix f=((r*b-lr)'(inv(r*(inv(x'x)*r')))*(r*b-lr))/sig2 print f * Alternative calculation of the F-test statistic matrix f=(r*b-lr)'(inv(r*varcov*r'))*(r*b-lr) print f sample 1 1 * Get the t-statistic and a p-value for a 2-sided test. gen1 t=sqrt(f) distrib t / type=t df=df gen1 pvalue=2*(1-\$cdf) print t pvalue stop