/*libname us '\\tsclient\e\badm742';*/ libname us 'f:\badm742'; /*data clean*/ data a; set us.crsp2017; year=year(date); month=month(date); if ret>-1; mktval=prc*shrout; if mktval>0; keep cusip year month prc ret vwretd mktval; run; /* get the data (1996-2000) to estimate beta for each stock*/ data b; set a; if year >1995 and year<2001; run; /* keep the stocks with at least 10 obs*/ proc sort run; data=b; by cusip; proc means data=b noprint; var ret; by cusip; output out=b1 n = num_obs; data run; b1; set b1; if num_obs>9; dum=1; proc sort run; data=b1; by cusip; data run; b2; merge b b1; by cusip; if dum=1; /* beta estimation*/ proc sort run; data=b2; by cusip; proc reg data=b2 noprint outest=beta; model ret = vwretd; by cusip; run; data data_beta; set beta; beta=vwretd; keep cusip beta; run; /* assign market value and book-to-market value ratio to each stock (based on the information of previous year) */ data mktval; set a; year=year+1; if month=12; keep cusip year prc mktval; run; data bkval; set us.compustat2017; year=fyear+1; keep cusip year bkvlps; run; proc sort run; data=mktval; by cusip year; proc sort run; data=bkval; by cusip year;
/*libname us '\\tsclient\e\badm742';*/ libname us 'f:\badm742'; /*data clean*/ data a; set us.crsp2017; year=year(date); month=month(date); if ret>-1; mktval=prc*shrout; if mktval>0; keep cusip year month prc ret vwretd mktval; run; /* get the data (1996-2000) to estimate beta for each stock*/ data b; set a; if year >1995 and year<2001; run; /* keep the stocks with at least 10 obs*/ proc sort data=b; by cusip; run; proc means data=b noprint; var ret; by cusip; output out=b1 n = num_obs; data b1; set b1; if num_obs>9; dum=1; run; proc sort data=b1; by cusip; run; data b2; merge b b1; by cusip; if dum=1; run; /* beta estimation*/ proc sort data=b2; by cusip; run; proc reg data=b2 noprint outest=beta; model ret = vwretd; by cusip; run; data data_beta; set beta; beta=vwretd; keep cusip beta; run; /* assign market value and book-to-market value ratio to each stock (based on the information of previous year) */ data mktval; set a; year=year+1; if month=12; keep cusip year prc mktval; run; data bkval; set us.compustat2017; year=fyear+1; keep cusip year bkvlps; run; proc sort data=mktval; by cusip year; run; proc sort data=bkval; by cusip year; run;
Assignment_3_sascodes_2017.docx