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
全选运行至forvalues时显示invalid syntax, 如果单独选择forvalues时显示type mismatch,代码来自b站https://www.bilibili.com/video/a ... 7fd9c56fef5d91aee22


雷达卡


京公网安备 11010802022788号







