* A very simple program, "ols1" estimates linear regression coefficients using ordinary least squares. program ols1 version 8.0 * The syntax allows only for a variable list with one or more numeric variables. syntax varlist(min=1 numeric) * "tempname..." assigns names to temporary matrices to be usined in this program. When ols1 has finished, they drop. tempname crossYX crossX crossY b * "matrix accum..." forms a cross-product matrix. The K variables in varlist, and the N observations with nonmissing * values on all K variables, comprise an N row, K column data matrix we might call yX. The cross product matrix YX equals * the transpose of yX times yX. Written algebraically, crossYX=(yX)'yX quietly matrix accum `crossYX' = `varlist' * Matrix crossX extracts rows 2 through K, and column 2 through K from crossYX: * crossX = X'X matrix `crossX' = `crossYX'[2...,2...] * Column vector crossY extracts rows 2 through K, and column 1 from crossYX: * crossY = X'y matrix `crossY' = `crossYX'[2...,1] * The column vector b contains OLS regression coefficients, obtained by the classic estimating equation b = inverse(X'X)X'y matrix `b' = syminv(`crossX') * `crossY' * Finally, we list the coefficient estimates, which are the contents of b. matrix list `b' end