turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- Analytics
- /
- Stat Procs
- /
- rolling window beta

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

a month ago - last edited a month ago

Hello all,

I need your help plz because I am having troubles with my sas code. I want to estimate the monthly betas for multiple CUSIP codes (20000 stocks) at each date by using the preceding 48 month window. My regression is the following:

Rt = alpha + Betai Rti + BetamRtm + e

I have posted my initial data that contains the following variables : Report_date Cusip Rt Rti Rtm

and I want to obtain the folllowing table : Report_date Cusip betai betam

I have tried the following codes, the problem is that I want to obtain the results by CUSIP not every cusip have 48 month-observations and some have more.

ANY help would be much appreciated.

```
data nstockregfinal4 / view= nstockregfinal4;
do grp = 0 to nrecs-48;
do j = 1 + grp to 48 + grp;
set nstockregfinal3 nobs=nrecs point=j;
output;
end;
end;
stop;
run;
proc reg data=nstockregfinal4 outest=Coeff noprint;
by grp;
model Rt = Rtm Rti;
output out=Res p=predicted r=residus;
run;
quit;
or I have tried also :
data nstockregfinal5 / view= nstockregfinal5;
array _X1 {48} _temporary_ ;
array _X2 {48} _temporary_ ;
array _Y {48} _temporary_ ;
set nstockregfinal3;
by CUSIP;
retain N 0;
N = ifn(first.CUSIP,1,N+1);
I=mod(N-1,48)+1;
_X1{I}=Rtm;
_X2{I}=Rti;
_Y{I}=Rt;
if N>=48 then do I= 1 to 48;
Rtm=_X1{I};
Rti=_X2{I};
Rt=_Y{I};
output;
end;
run;
proc reg data=nstockregfinal5 noprint outest=myests;
by CUSIP REPORT_DATE;
model Rt = Rtm Rti;
run;
quit;
```