Dear all,
I enclosed a program which simulate regressions
that you can try to run.
I succeeded in calculating the coefficient matrix of the regression (b).
but when I try to calculate the residuals I get just one column in the matrix that is correct but the other columns are with ones (1).
so the std of the residuals is also is not correct. (bolded with blue colour in the program)
I don't understand why that happens..
Who can help?
Many thanks...
proc iml;
n=10;
b=j(6,n);
do j=1 to n; *Number of simulations;
resid=j(239,n);
stdresid=j(n,1);
xtl = j(240, 1);
xsl=j(240, 1);
y=j(240, 1);
xtl[1,1]=0.926145577;
xsl[1,1] = 1.367164758;
y[1,1] = -27.99208409;
c=0.24269;
e=0.02106;
d=0.97564;
h=-0.24776;
m=-0.00362;
l=-0.00111;
q=0.00091339;
r=1.00339;
/** specify the mean and covariance of the population **/
Mean = {0, 0, 0};
Cov = {0.0343693345 0.0005718713 -.0000330633,
0.0005718713 0.0008609739 0.0000083048,
-.0000330633 0.0000083048 0.0000022582};
NumSamples = 240;
call randseed(0); /** set seed for the RandNormal module **/
U = RandNormal(NumSamples, Mean, Cov);
do i=2 to 240;
Y[i,1]=y[1,1]+u[i,1];
xsl[i,1]=c+e*y[(i-1),1]+d*xsl[(i-1),1]+h*xtl[(i-1),1]+u[i,2];
xtl[i,1]=m+l*y[(i-1),1]+q*xsl[(i-1),1]+r*xtl[(i-1),1]+u[i,3];
end;
ylag=lag(y);
xsl2=xsl##2;
xtl2=xtl##2;
/* Step 1: Compute X`X and X`y */
x = j(nrow(y), 1, 1) || ylag || xsl|| xtl || xsl2||xtl2; /* add intercept column */
v = {1}; /* specify rows to exclude */
idx = setdif(1:nrow(x), v); /* exclude values in v */
xnew = x[idx, ]; /* extract submatrix */
xpx = xnew`* xnew; /* cross-products */
v = {1}; /* specify rows to exclude */
idy = setdif(1:nrow(y), v); /*exclude values in v */
ynew = y[idx, ]; /* extract submatrix*/
xpy = xnew` * ynew;
b[,j]= solve(xpx, xpy);
resid[,j]=ynew-xnew*b[,j];
stdresid[j,]=std(resid[,j]);
end;
print b;
print resid;
print stdresid;
quit;