/* EXAMPLE TO DISPLAY LEAST SQUARES INFERENCE */ /* Load in Data */ load path = E:\econ5340\; load xydata[52,3] = crime.dat; data = xydata[2:52,.]; y = data[.,2]; x = data[.,1 3]; nobs = rows(x); /* Calculating b Vector */ constant = ones(51,1); xmat = constant~x; k = cols(xmat); b = inv(xmat' * xmat)*(xmat' * y); print " "; print "b vector = " b; /* Calculating Standard Errors */ resids = y - xmat*b; ssquare = (resids'*resids)/(nobs-k); print "ssquare = " ssquare; varb = inv(xmat'*xmat)*ssquare; print "estimated variance of b = " varb; /* Calculating Rsquared */ ybar = y - meanc(y); rsquare = 1 - (resids'*resids)/(ybar'*ybar); /* Individual t tests */ t2 = b[2,1]/sqrt(varb[2,2]); t3 = b[3,1]/sqrt(varb[3,3]); print " t stat for b2 = " t2; print " t stat for b3 = " t3; /* 95% Confidence Interval for b2 */ tcrit = 2.014; cilb = b[2,1] - (tcrit)*sqrt(varb[2,2]); ciub = b[2,1] + (tcrit)*sqrt(varb[2,2]); print "confidence interval lower bound = " cilb; print "confidence interval upper bound = " ciub; /* Overall Significance Test */ Fstat = (rsquare/(k - 1))/((1 - rsquare)/(nobs - k)); Print " F statistic = " Fstat;