title1 h=1 'EVENT STUDY : Impact of rating changes on stock market prices'; run; libname work 'C:\Users\utilisateur\Documents\My SAS Files\9.3\Data_base'; /* proc import datafile='C:\Users\utilisateur\Documents\My SAS Files\9.3\Data_base\S&P INDEX.xlsx' out=indix dbms=xlsx replace; getname=yes; run; proc import datafile='C:\Users\utilisateur\Documents\My SAS Files\9.3\Data_base\exp_stock.xlsx' out=stockprice dbms=xlsx replace; getname=yes; run; proc import datafile='C:\Users\utilisateur\Documents\My SAS Files\9.3\Data_base\expTABLE_EVENT.xlsx' out=eventdate dbms=xlsx replace; getname=yes; usedate=yes; run; */ data WORK.stockprices; merge work.stockprice(rename=(price=p)) work.indix(rename=(S_P_1500=m)); keep date p m; by date; run; /* ------------------------------------------------------ Compute daily returns 'ri' is the return on the stock 'rm' is the return on the market portfolio ------------------------------------------------------ */ data work.return; set work.stockprices; keep date ri rm; by date; pp = lag(p); pm = lag(m); ri = LOG(p/pp); rm = LOG(m/pm); run; data work.eventdate; set work.eventdate; event=cdate; format event ddmmyy10.; /*informat event date9.;; /*rename cdate=date;*/ run; /* ------------------------------------------------------ Set window flags; relative position to the event ------------------------------------------------------ */ data _Null_; set work.eventdate; CALL symput ('event',event); /*First and last date of the estimation window*/ call symputx ('FEST',Festimat); call symputx ('LEST',Lestimat); /*First and last date of the event window*/ call symputx ('FEVT',Fevent); call symputx ('LEVT',Levent); /*First and last date for the whole study*/ %let FDATE=&FEST; %let LDATE=&LEVT; run; data work.return; set work.return; by date; retain n 0; n = n + 1; est_win = (date >=&FEST) and (date <=&LEST); evt_win = (date >=&FEVT) and (date <=&LEVT); if (date =&event) then call symput('EVENT_N',n); where (ri ^= .) and (rm ^= .); run; /* D is the trading day index, relative to the event day */ data work.return; set work.return; by date; D = n - &EVENT_N; run; /* -------------------------------------------------------- Compute simple stats for rm over the estimation window. -------------------------------------------------------- */ proc means data = work.return(where=(est_win)) noprint n mean var; output out=work.outstat n = L1 mean = mrm var = vrm; var rm; run; data _null_; set work.outstat; call symput('L1',L1); /* # of obs. in the est. window. */ call symput('mrm',mrm); /* mean(rm) over the est. window. */ call symput('vrm',vrm); /* var(rm) over the est.window. */ run; /* -------------------------------------------------------- Compute alpha, beta, and rss over the estimation window. -------------------------------------------------------- */ proc reg data = work.return(where=(est_win)) noprint simple outest=work.reg sse; model ri = rm; quit; run; data _null_; set work.reg; call symput('alpha',Intercept); /* alpha */ call symput('beta',rm); /* beta */ call symput('rss',_SSE_); /* residual sum of squares */ call symput('se',_SSE_/(&L1-2)); /* variance of the residuals */ run; /* ------------------------------------------------------ Compute abnormal returns 'ar' over the event window ------------------------------------------------------ */ data work.ar; set work.return(where=(evt_win)); by date; keep D rm ar; ar = ri - &alpha - &beta*rm; /* abnormal return */ run; title2 'TEST Abnormal Returns over the Event Window'; proc gplot data = work.ar; plot ar*D; run; quit; /* ------------------------------------------------------ Compute Standardized Abnormal Returns (SAR), cumulative AR (CAR) ------------------------------------------------------ */ data work.ar; set work.ar; by D; drop n; retain car 0 n 0; car = car + ar; /* cumulative abnormal return */ n = n + 1; vcar = n*&se; /* var(car) */ scar = car/sqrt(vcar); /* standardized car */ ze = (1 + ((rm-&mrm)**2)/&vrm)/&L1; /* second component of var(ar) */ v = &se + ze; /* var(ar) */ sar = ar/sqrt(v); /* standardized ar */ run; /* ------------------------------------------------------ Check for abnormal returns over the event window. ------------------------------------------------------ */ title2 'TEST Standardized Abnormal Returns over the Event Window'; proc gplot data = work.ar; plot sar*D; run; proc print data=work.ar; var d ar; run;