data run; mb; merge mktval bkval; by cusip year; bm=bkvlps/prc; if bm>0; /* generate dataset including monthly returns,bm,beta and mktval for the period between 2001 and 2003*/ data run; a1; set a; drop mktval; proc sort data=a1; by cusip year;run; proc sort data=mb; by cusip year;run; data a_mb; merge a1 mb; by cusip year; if year>2000 and year<2004; run; proc sort run; data=data_beta; by cusip; proc sort run; data=a_mb; by cusip; data data_all; data_beta a_mb; lnme=log(mktval); lnbm=log(bm); by cusip;run; /*run regressions for each month and get coefficients over 36 months*/ proc sort run; data=data_all; by year month; proc reg data=data_all noprint outest=final; model ret = beta lnme lnbm; by year month; run; /*get mean, std and t_stat for the coefficients over 36 months*/ proc means data=final noprint; var beta lnme lnbm; output out=final1 mean = gama1 gama2 gama3 std = std_gama1 std_gama2 std_gama3 n= nob; data final1; set final1; keep gama1 gama2 gama3 std_gama1 std_gama2 std_gama3 t1 t2 t3; t1=(gama1/std_gama1)*sqrt(nob); t2=(gama2/std_gama2)*sqrt(nob); run; t3=(gama3/std_gama3)*sqrt(nob); /* you will find results in the table final2*/
data mb; merge mktval bkval; by cusip year; bm=bkvlps/prc; if bm>0; run; /* generate dataset including monthly returns,bm,beta and mktval for the period between 2001 and 2003*/ data a1; set a; drop mktval; run; proc sort data=a1; by cusip year;run; proc sort data=mb; by cusip year;run; data a_mb; merge a1 mb; by cusip year; if year>2000 and year<2004; run; proc sort data=data_beta; by cusip; run; proc sort data=a_mb; by cusip; run; data data_all; data_beta a_mb; lnme=log(mktval); lnbm=log(bm); by cusip;run; /*run regressions for each month and get coefficients over 36 months*/ proc sort data=data_all; by year month; run; proc reg data=data_all noprint outest=final; model ret = beta lnme lnbm; by year month; run; /*get mean, std and t_stat for the coefficients over 36 months*/ proc means data=final noprint; var beta lnme lnbm; output out=final1 mean = gama1 gama2 gama3 std = std_gama1 std_gama2 std_gama3 n= nob; data final1; set final1; keep gama1 gama2 gama3 std_gama1 std_gama2 std_gama3 t1 t2 t3; t1=(gama1/std_gama1)*sqrt(nob); t2=(gama2/std_gama2)*sqrt(nob); t3=(gama3/std_gama3)*sqrt(nob); run; /* you will find results in the table final2*/