proc (3) = regress (x,y);
local xxi,b,ymxb,sse,sd,t;
xxi=invpd(x'x);
b=xxi*(x'y);
ymxb=y-(x*b);
sse=ymxb'ymxb/(rows(x)-cols(x));
sd=sqrt(diag(sse*xxi));
t=b./sd;
retp(b,sd,t);
endp;
@ create a 100*4 matrix of standard-normal random numbers @
{x, state1} = rndKMn(100,4,-1)*100;
@ define a file for output. No path is defined so it will be in your
working directory @
output file = C:\gs\tempdata.asc reset; @ reset - the file is overwritten
each time a write occurs @
@ print x on the screen and to the file, in ascii form, space delimited @
print x;
@ turn off the output file @
output off;
@ Ascii load from the file, into a one-column vector @
load x[] = C:\gs\tempdata.asc;
@ turn the column vector into a 100*4 matrix @
x = reshape(x,100,4);
@ select the first column @
y = x[.,1];
@ select columns two, three, and four @
x = x[.,2:cols(x)];
@ call the "regress" function - it has three returns @
{ coeff, stderror, tstat } = regress(x,y);
@ print column labels @
print "Coefficients, Standard Errors, T-Statistics";
@ horizontally concatenate the returns from "regress" and print the result @
print coeff~stderror~tstat;
z = {coeff, stderrow, tstat};
fname = "test.xls";
names = {"Coefficients", "Standard Errors", "T-statistics"};
call export(z',faname,names);