program myreg
	version 9
	syntax varlist [if] [in]
	marksample touse
	tempvar one
	qui gen byte one=1

	mata: myreg("`varlist' one", "`touse'")
end

version 9
mata:
function myreg(string scalar varnames, string scalar touse)
{
	string rowvector        vars, rhsvars
	string scalar           lhsvar
	real matrix             X
	real colvector          y

	vars = tokens(varnames)
	lhsvar  = vars[1]
	rhsvars = vars[|2\.|]
	st_view(X, ., rhsvars, touse)
	st_view(y, ., lhsvar, touse)
	invsym(cross(X,X))*cross(X,y)
}
end