各位大神求助!我是stata新手,做stata数据出现问题啦!
我们用的是普林斯顿的event study http://dss.princeton.edu/online_help/stats_packages/stata/eventstudy.html
我们是做收购的event, 很多公司在相同的一年有很多收购,这些事件发生的时间都不相同。但是代码只能取第一个,后面的几笔同公司收购全部都自动删除掉了。
可是这会影响我们的结果……
有没有什么办法能够保留所有的收购,而不是每个公司保留一笔?或者是不是代码中出现了什么限制呀?我上传下我们的一年的数据,希望有大神能够帮我们解答,谢谢啦!
use stockdata1981.dta, replace
sort company_id date
replace prc= abs(prc)
by company_id: gen ret= (prc - prc[_n-1])/prc[_n-1]
merge m:m company_id using eventdates1981.dta
keep if _merge==3
sort company_id date
by company_id: gen datenum=_n
by company_id: gen target=datenum if date==event_date
egen td=min(target), by(company_id)
drop target
gen dif=datenum-td
*set the window*
by company_id: gen event_window=1 if dif>=-1 & dif<=1
egen count_event_obs=count(event_window), by(company_id)
by company_id: gen estimation_window=1 if dif<=-6 & dif>=-205
egen count_est_obs=count(estimation_window), by(company_id)
replace event_window=0 if event_window==.
replace estimation_window=0 if estimation_window==.
*list of company_ids that do not have enough observations within the event and estimate window*
set more off
tab company_id if count_event_obs<3
tab company_id if count_est_obs<200
*drop if not enough*
drop if count_event_obs < 3
drop if count_est_obs < 200
drop count_event_obs count_est_obs
*Estimating Normal Performance*
set more off /* this command just keeps stata from pausing after each screen of output */
gen predicted_return=.
egen id=group(company_id)
/* for multiple event dates, use: egen id = group(group_id) */
forvalues i=1(1)98 { /*note: replace N with the highest value of id */
l id company_id if id==`i' & dif==0
reg ret market_return if id==`i' & estimation_window==1
predict p if id==`i'
replace predicted_return = p if id==`i' & event_window==1
drop p
}
*Abnormal and Cumulative Abnormal Returns*
sort id fyear
gen abnormal_return=ret-predicted_return if event_window==1
sort company_id
by company_id: egen cumulative_abnormal_return = sum(abnormal_return)
sort id
egen evacar = mean(abnormal_return)
*Testing for Significance*
sort id date
by id: egen ar_sd = sd(abnormal_return)
gen test =(1/sqrt(98)) * ( cumulative_abnormal_return /ar_sd)
list company_id cumulative_abnormal_return test if dif==0
*output*
outsheet company_id event_date cumulative_abnormal_return test using stats.csv if dif==0, comma names
*Testing Across All Events*
reg cumulative_abnormal_return if dif==0, robust
而且中间出现了一个问题,就是在做循环回归的时候,98个公司到51就不跑了,说是 no observation, 不明白这是怎么回事嗷呜……
楼主你这个问题非常具体啊,哈哈。
1)不应该用merge m:m。 Stata help file里面说,虽然m:m的选项存在,但是建议用户永不使用。。。你是不是用1:m的时候出现说master data有duplicates,所以改用m:m啊?如果是的话,我建议你先把stock data整理一下,删掉重复项,再用1:m,应该就能生成一家公司对多个事件的数据了。
2)关于你的第二个问题,我暂时没时间细看。你跑到这个loop之前先试一下指令count if id==51 & estimation_window==1 ,看看是不是0。