cd D:\Data
import excel CAR, first clear
sor id date
by id: g estimation_window=1 ///
if (di>=-200 & di<=-30)
by id: g event_window=1 ///
if (di>=-10 & di<=10)
replace event_window=0 ///
if event_window==.
replace estimation_window=0 ///
if estimation_window==.
gen predicted_return=.
qui tabulate id
local N=r(r)
forvalues i=1(1)`N'{
qui reg r rm if(id==`i'& estimation_window==1)
predict temp if id==`i'
replace predicted_return=temp if(id==`i' & event_window==1)
drop temp
}
keep if event_window==1
gen ar=r-predicted_return
sor id date