Command Reference : Matrix Language Reference
  
 
@regress
Regression on columns of matrix.
Syntax: @regress(m[, v])
m: matrix
v: (optional) vector
Return: matrix
Returns the results of an OLS regression on the first column of matrix m versus the remaining columns of m.
The returned matrix contains four columns of information: (1) regression coefficient values, (2) standard errors, (3) t-test statistics, and (4) associated p-values.
If an optional vector v is supplied, the regression residuals are stored in v.
Examples
matrix results = @regress(yxmat)
estimates a regression on the data in the columns of the matrix YXMAT and saves the coefficient, standard error, t-statistic and p-value results in columns of RESULTS
Next for comparison purposes we run a regression on random data using the equation object, collect results in a matrix, and make a series containing the residuals.
First, create a workfile with random data, create a group with the dependent variable and regressors, and set the workfile sample.
workfile q 2000 2022
series y = nrnd
series x1 = nrnd
series x2 = nrnd
group yx y 1 x1 x2
smpl 2002 2022
equation eq1.ls y c x1 x2
matrix eq_results = @hcat(eq1.@coefs, eq1.@ses, eq1.@tstats, eq1.@pvals)
eq1.makeresids eq_resids
The function offers a quick way of obtaining equivalent results,
group yx y 1 x1 x2
vector fn_resids
matrix fn_results = @regress(@convert(yx), fn_resids)
Cross-references
See also @intercept, and @trendcoef.