clear set mem 300m /* merge code*/ use event_study_full_sample.dta, clear sort permno save newfile1.dta, replace use event.dta, clear sort permno save newfile2.dta, replace use newfile1.dta, clear merge permno using newfile2.dta tab _merge drop _merge save even_full_adate.dta clear use "C:\even_full_adate" keep date permno ret vwretd adate gen e_date=date(adate,"MDY") gen event_count=permno*e_date by event_count, sort: gen nvals = _n == 1 count if nvals drop nvals sort event_count date by event_count: gen datenum=_n by event_count: gen target=datenum if date==e_date egen td=min(target), by (event_count) drop target gen dif=datenum - td bysort event_count: gen event_window=1 if dif>=-1 & dif<=1 egen count_event_obs=count(event_window), by(event_count) bysort permno: gen estimation_window=1 if dif<-1 & dif>=-252 egen count_est_obs=count(estimation_window), by(event_count) replace event_window=0 if event_window==. replace estimation_window=0 if estimation_window==. tab permno if count_event_obs<3 tab permno if count_est_obs<30 drop if count_event_obs < 3 drop if count_est_obs < 30 *count unique observation of permno * edate for unique event by event_count, sort: gen nvals = _n == 1 count if nvals drop nvals set more off gen predicted_return=. drop if event_count==18121 egen id=group(event_count) forvalues i=1(1)808 { list id event_count if id==`i' & dif==0 reg ret vwretd if id==`i' & estimation_window==1 predict p if id==`i' replace predicted_return = p if id==`i' & event_window==1 drop p } *Here, we created a variable "id" that numbers the companies from 1 to however many there are. The N is the number of company-event combinations that have complete data. This process iterates over the companies, runs a regression in the estimation window for each, and then uses that regression to predict a 'normal' return in the event window. *Abnormal and Cumulative Abnormal Returns *We can now calculate the abnormal and cumulative abnormal returns for our data. The daily abnormal return is computed by subtracting the predicted normal return from the actual return for each day in the event window. The sum of the abnormal returns over the event window is the cumulative abnormal return. sort id date gen abnormal_return=ret-predicted_return if event_window==1 by id: egen cumulative_abnormal_return = sum(abnormal_return) *Here we simply calculate the abnormal return for each observation in the event window. Then we set the cumulative abnormal return equal to the sum of the abnormal returns for each company. *Testing for Significance *We are going to compute a test statistic, test, to check whether the average abnormal return for each stock is statistically different from zero. * test = (1/n :AR)/(AR_SD) *where AR is the abnormal return and AR_SD is the abnormal return standard deviation. sort id date by id: egen ar_sd = sd(abnormal_return) by id: egen scar=cumulative_abnormal_return /ar_sd gen j1 =(1/sqrt(3)) * ( cumulative_abnormal_return /ar_sd) gen j2= sqrt(808*(251-4)/(3-2))* scar reg cumulative_abnormal_return if dif==0, robust