/* ** OLS Program */ @ Data loading @ load data[100,5] = exer.txt; @ Define # of observations, # of regressors, X and Y @ tt = rows(data); @ # of observations @ kk = 5; @ # of regressors @ y = data[.,1]; x2 = data[.,2]; x3 = data[.,3]; x4 = data[.,4]; x5 = data[.,5]; @ Dependent variable @ yy = y ; vny = {"y"}; @ Regressors @ xx = ones(tt,1)~x2~x3~x4~x5; vnx = {"cons", "x2", "x3", "x4", "x5" } ; @ Do not change below @ @ OLS using yy and xx @ b = invpd(xx'xx)*(xx'yy); e = yy - xx*b ; s2 = (e'e)/(tt-kk); v = s2*invpd(xx'xx); econ = b~sqrt(diag(v))~(b./sqrt(diag(v))); econ = vnx~econ; se = sqrt(diag(v)); sst = yy'yy - tt*meanc(yy)^2; sse = e'e; r2 = 1 - sse/sst; @ Printing out OLS results @ output file = ols.out reset; let mask[1,4] = 0 1 1 1; let fmt[4,3] = "-*.*s" 8 8 "*.*lf" 10 4 "*.*lf" 10 4 "*.*lf" 10 4; format /rd 10,4 ; "" ; "OLS Regression Result" ; "------------------------" ; " dependent variable: " $vny ; "" ; " R-Squares " r2 ; "" ; "variable coeff. std. err. t-st " ; yyprin = printfm(econ,mask,fmt); "" ; output off ;