***********************************; /* RESEARCH METHODS IN ACCOUNTING */ /* Exercise 21.1.2020 */ ***********************************; * Note that comments are shown in green; * Use permanent SAS Data Sets with LIBNAME Statements; libname rma "\\home.org.aalto.fi\jarvah1\data\Downloads"; run; * import data; data rdq; set rma.rdq; if RDQ="."D then delete; /* <- here we delete observations where earnings announcement date is missing */ run; * check the data; proc contents data=rdq; /* <- Listing the content of your SAS Data Set */ proc print data=rdq (obs=15); /* <- Print first 15 observations (not over one million!)*/ run; * import daily data from CRSP; data dret; set rma.dret; if VOL=-99 then VOL=.; /* CRSP manual: Volume is set to -99 if the value is missing. */ TRADVOL=VOL/(SHROUT*1000); /* main variable in Beaver (1968) */ if TRADVOL=. then delete; if ret<-1 then ret=.; if ret=. then delete; /* CRSP use -66, -77, -88, -99 codes to indicate the reason for missing return data*/ if SPRTRN=. then delete; /* SPRTRN is the return on the Standard & Poor's Composite Index */ year=year(date); /* YEAR(date) syntax returns year from a SAS date value */ run; * We need to sort the data before we can run OLS models by each firm and year combination; proc sort data=dret; by permco year; run; proc reg data=dret noprint outest=parms; /* <- outputs the parameter estimates */ model ret=SPRTRN; /* <- the market model */ output out=dret2 residual=res; /* <- outputs the residual values into separate data file */ by permco year; run; proc sort data=dret2; by date; /* These syntaxs computes variance of residuals in each trading day */ proc means data=dret2 noprint; output out=dret3 var(res)=varret; by date; run; /* */ * merge datasets by date; data dret; merge dret2 dret3; by date; price_res=(res*res)/varret; run; proc contents data=dret; run; * merge Compustat and CRSP datasets; proc sql; create table aaa as select * from rdq as a, dret as b where a.LPERMCO=b.PERMCO and (-16<= (b.DATE-a.RDQ) <=16); quit; data bbb; set aaa; WINDOW=DATE-RDQ; /* event window in Beaver (1968) */ decade=int(year(RDQ)/10); /* one approach to create a 'decade' variable */ run; proc sort data=bbb; /* in this syntax we compute mean (and median) trading volumes and abnormal price residuals by each decade and day relative to earnings announcement */ by decade WINDOW; proc means data=bbb noprint; output out=ccc (drop=_type_) mean(TRADVOL)=meanVOL median(TRADVOL)=medVOL mean(price_res)=meanRES; by decade WINDOW; run; /* */ /* Make the Figure 1, Panel A of Dechow et al. (2014) */ proc sgplot data=ccc; series x=WINDOW y=meanVOL / GROUP=decade; XAXIS TYPE=discrete; YAXIS label='trading volume'; run; /* Make the Figure 1, Panel B of Dechow et al. (2014) */ proc sgplot data=ccc; series x=WINDOW y=meanRES / GROUP=decade; XAXIS TYPE=discrete; YAXIS label='price residual'; run;