Hi,
I'm not quit sure how does this work so the header might be misleading or then it's indeed what I'm seeking for.
However, I have this regression procedure which I need to repeat on my sample of 30 firms:
The preregress module formulates dependent and independent variables which are then used in regress module.
I use "read where()" command to input firms from pooled data. Also I have to form every time a vector "resid_firmname = resid". How could I just make a vector out of the firm names and such a loop which would do this procedure firm by firm and also how to formulate such a output vector for every firm?
proc iml;
edit kirjasto.Dax30_hourly09;
/*394 missing values of volume, 264 for ALTG*/
/*BAYG changed to BAYGn on 21.09.2009*/
/*create variables for excess volume regression*/
start preregres (vol, high, low, close) global (x, y);
lnvol=log(vol);
lagvol=lag(lnvol, (1:50));
vola=high/low;
lnvola=log(vola);
lagvola=lag(lnvola, (1:10));
close10=lag(close, -10);
lnclose10=log(close10);
timeorig=T(1:nrow(vol));
tempx=lagvol||lagvola||lnclose10;
xtemp2=tempx[51:(nrow(vol)-10),];
lintrend=T(1:nrow(xtemp2));
constant=j((nrow(xtemp2)),1);
x=constant||xtemp2||lintrend;
y=lnvol[51:(nrow(vol)-10)];
finish;
/*list of firms:
adsg, altg, alvg, basf, bayg, beig, bmwg, cbkg, cong, DAIGn, DB1Gn, dbkg, dpwg, dteg, eong,
fmeg, freg, heig, hnkg, ifxg, lhag, ling, lxsg, mrcg, muvg, rweg, sapg, sdfg, sieg, tkag, vowg
*/
print resid_adsg resid_altg resid_alvg resid_basf resid_bayg resid_beig resid_bmwg resid_cbkg resid_cong resid_daig resid_db1g;
read all var "volume" into volume where(RIC="DB1Gn.DE");
read all var "high" into high where(RIC="DB1Gn.DE");
read all var "close" into close where(RIC="DB1Gn.DE");
read all var "low" into low where(RIC="DB1Gn.DE");
run preregres (volume, high, low, close);
start Regress; /* begins module */
xpxi = inv(x`*x); /* inverse of X'X */
beta = xpxi * (x`*y); /* parameter estimate */
yhat = x*beta; /* predicted values */
resid = y-yhat; /* residuals */
sse = ssq(resid); /* SSE */
n = nrow(x); /* sample size */
dfe = nrow(x)-ncol(x); /* error DF */
mse = sse/dfe; /* MSE */
cssy = ssq(y-sum(y)/n); /* corrected total SS */
rsquare = (cssy-sse)/cssy; /* RSQUARE */
/* print ,"Regression Results", sse dfe mse rsquare; */
stdb = sqrt(vecdiag(xpxi)*mse); /* std of estimates */
t = beta/stdb; /* parameter t tests */
prob = 1-probf(t#t,1,dfe); /* p-values */
/*print ,"Parameter Estimates",, beta stdb t prob;
print ,y yhat resid;*/
finish Regress; /* ends module */
run Regress;
create kirjasto.residuals var {resid};
append;
resid_db1g=resid;
close kirjasto.residuals;