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.
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.
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;
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.
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.