BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MAC1430
Pyrite | Level 9

Hi everyone,

 

Can you please help me to estimate beta for this sample. The actual data is over 100 million observations; therefore, please kindly use the code that fits that huge data. We estimate following equation for each stock using daily returns within a month. For example for stock 1, we run the regression based on daily returns of January 2010 and for other months too. The equation is given below:

 

Return of each stock= C + beta1 (mkt1)+beta2 (mkt2) + beta3 (mkt3) +residual.

 

Then finally we estimate the beta based on sum of all three betas i.e.; beta = beta1+beta2+beta3

The data is given below:

data have;
infile cards expandtabs truncover;
input stock date : yymmdd10. ret mkt1 mkt2 mkt3 ;
format date yymmdd10.;
cards;
1	2010-01-07	0.04135	0.01	0.012	0.008
1	2010-01-26	-0.02544	0.02	0.024	0.016
1	2010-01-29	0.03384	0.03	0.036	0.024
2	2010-01-07	0.06069	0.01	0.012	0.008
2	2010-01-26	-0.06219	0.02	0.024	0.016
2	2010-01-29	0.01989	0.03	0.036	0.024
run;

Thanks a lot for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data have;
infile cards expandtabs truncover;
input stock date : yymmdd10. ret mkt1 mkt2 mkt3 ;
format date yymmdd10.;
cards;
1 2010-01-07 0.04135 0.01 0.012 0.008
1 2010-01-26 -0.02544 0.02 0.024 0.016
1 2010-01-29 0.03384 0.03 0.036 0.024
2 2010-01-07 0.06069 0.01 0.012 0.008
2 2010-01-26 -0.06219 0.02 0.024 0.016
2 2010-01-29 0.01989 0.03 0.036 0.024
;
run;
proc reg data = have outest=want noprint;
by stock date;
format date monyy5.;
model ret = mkt1 mkt2 mkt3;
run;

After get WANT table, it is easy to get beta you want.

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

data have;
infile cards expandtabs truncover;
input stock date : yymmdd10. ret mkt1 mkt2 mkt3 ;
format date yymmdd10.;
cards;
1 2010-01-07 0.04135 0.01 0.012 0.008
1 2010-01-26 -0.02544 0.02 0.024 0.016
1 2010-01-29 0.03384 0.03 0.036 0.024
2 2010-01-07 0.06069 0.01 0.012 0.008
2 2010-01-26 -0.06219 0.02 0.024 0.016
2 2010-01-29 0.01989 0.03 0.036 0.024
run;

proc reg data = have;
model ret = mkt1 mkt2 mkt3;
run;

MAC1430
Pyrite | Level 9
I am looking for three beta (beta1, beta2, beta3) values for each stock each month. Anyway Thanks for your time and efforts.
Ksharp
Super User
data have;
infile cards expandtabs truncover;
input stock date : yymmdd10. ret mkt1 mkt2 mkt3 ;
format date yymmdd10.;
cards;
1 2010-01-07 0.04135 0.01 0.012 0.008
1 2010-01-26 -0.02544 0.02 0.024 0.016
1 2010-01-29 0.03384 0.03 0.036 0.024
2 2010-01-07 0.06069 0.01 0.012 0.008
2 2010-01-26 -0.06219 0.02 0.024 0.016
2 2010-01-29 0.01989 0.03 0.036 0.024
;
run;
proc reg data = have outest=want noprint;
by stock date;
format date monyy5.;
model ret = mkt1 mkt2 mkt3;
run;

After get WANT table, it is easy to get beta you want.

MAC1430
Pyrite | Level 9
Thanks a lot ksharp, it works well.
AgReseach7
Obsidian | Level 7

how do you get beta (PROC GLIMMIX Beta distribution) back on original scale?

 

 

PROC glimMIX;

CLASS Phase TRT DAY ID;

MODEL DMIBWnew = TRT|phase /dist=beta DDFM=KR SOLUTION;

Random DAY/residual SUBJECT=ID;

LSmeans trt /DIFF ADJUST=SIMULATE (REPORT SEED=121211) cl adjdfe=row;

RUN; Quit;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 3253 views
  • 2 likes
  • 4 in conversation