全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
3174 1
2017-01-05
clear
cd c:\stata
use eventdates1, clear                     
sort company_id
by company_id: gen eventcount=_N           
by company_id: keep if _n==1
sort company_id
keep company_id eventcount
save eventcount
use stockdata1, clear                       
sort company_id
merge m:1 company_id using eventcount   
tab _merge                                 
keep if _merge==3
drop _merge
expand eventcount   
drop eventcount
sort company_id date
by company_id date: gen set=_n
sort company_id set
save stockdata2                           
use eventdates1, clear   
sort company_id
by company_id: gen set=_n
sort company_id set
save eventdates2                          
use stockdata2, clear
merge m:1 company_id set using eventdates2     
tab _merge                                 
list company_id if _merge==2
keep if _merge==3
drop _merge   
egen group_id = group(company_id set)
sort group_id date
by group_id: gen datenum=_n
by group_id: gen target=datenum if date==event_date  
egen td=min(target), by(group_id)
drop target
gen dif=datenum-td

by group_id: gen event_window=1 if dif>=-10 & dif<=10         
egen count_event_obs=count(event_window), by(group_id)
by group_id: gen estimation_window=1 if dif<-30 & dif>=-160   
egen count_est_obs=count(estimation_window), by(group_id)
replace event_window=0 if event_window==.
replace estimation_window=0 if estimation_window==.

tab group_id if count_event_obs<21
tab group_id if count_est_obs<130
drop if count_event_obs <21
drop if count_est_obs < 130                              

set more off
browse                     /*程序的主体部分我有点搞不清是怎样循环的,为什么没有求77个样本平均值的过程呢?
gen predicted_return=.
egen id=group(group_id)
forvalues i=1(1)77{                    /*样本中有77家公司   求大神解释一下经过筛选之后的样本数要怎么快速的看出来,我是自己数出来的
l id group_id if id==`i' & dif==0      
reg ret market_ret if id==`i' & estimation_window==1     
predict p if id==`i'
replace predicted_return = p if id==`i' & event_window==1
drop p
}  
outreg2 using test.rtf

sort id date
gen abnormal_return=ret-predicted_return if event_window==1
by id: egen cumulative_abnormal_return = sum(abnormal_return)
sort id date
by id: egen ar_sd = sd(abnormal_return)                                 
gen test =(1/sqrt(21)) * ( cumulative_abnormal_return /ar_sd)
list company_id abnormal_return cumulative_abnormal_return test if dif==0
outsheet  company_id event_date abnormal_return cumulative_abnormal_return test using stats.csv if dif==0, comma name      

sort dif
by dif: egen c_abnormal_return = sum(abnormal_return)
by dif: egen ar_sd1 = sd(abnormal_return)
gen test1 =(1/sqrt(77)) * ( c_abnormal_return /ar_sd1)
outsheet dif c_abnormal_return test1 using stats1.csv if event_window==1 , comma name




二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2020-1-14 18:55:03
事件研究法不一定要求平均值
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群