已知 DATA2.dta文件包含的数据是 并购宣告日期date 证券代码stkcd 每个数据的编号caseID
sumTRD_Dalyr1m.dta文件包含的数据是 证券代码stkcd 并购交易日期trddt 日个股收益率dretwd 市场类型markettype 日市场回报率dretwdeq
思路是将DATA2.dta文件中的每一条数据提取出来与sumTRD_Dalyr1m.dta的数据进行合并,然后计算单条数据的CAR值,然后保存。我想编写一个循环命令进行计算,将DATA2.dta文件中的所有数据都计算一遍,然后我不知道为什么我写的这个循环命令在循环3次之后第四次就出错了((计算方法是正确的,单个的一次循环是正确的,就是循环不下去),出错的警示语句是insufficient observations。我写的命令与数据全部在下面,已经用dataex进行编写了,小萌新第一次提问,求大佬们帮忙解答一下,感激不尽!!!
* Example generated by -dataex-. To install: ssc install dataex
clear
input str10 date long stkcd float caseID
"2016-09-07" 2 1
"2017-09-19" 2 2
"2017-07-07" 18 3
"2017-10-13" 27 4
"2013-11-09" 39 5
"2017-02-28" 48 6
"2017-08-08" 50 7
"2014-11-07" 50 8
"2013-09-03" 60 9
"2013-09-04" 60 10
"2016-01-29" 63 11
"2016-12-06" 63 12
"2015-10-21" 63 13
"2017-11-29" 65 14
"2014-03-26" 66 15
"2014-12-11" 151 16
"2010-07-14" 151 17
"2015-06-02" 157 18
"2014-08-10" 157 19
"2016-01-26" 157 20
"2010-04-29" 333 21
"2011-08-12" 333 22
"2016-06-21" 333 23
"2016-12-02" 333 24
"2010-06-23" 333 25
"2017-02-11" 333 26
"2012-01-03" 338 27
"2012-08-31" 338 28
"2015-03-30" 338 29
"2016-12-12" 338 30
"2013-06-03" 338 31
"2012-08-23" 338 32
"2012-07-17" 404 33
"2012-04-16" 404 34
"2015-06-30" 415 35
"2014-07-14" 415 36
"2015-07-14" 415 37
"2015-05-12" 506 38
"2015-05-08" 513 39
"2010-01-20" 528 40
"2015-07-21" 534 41
"2015-12-28" 546 42
"2015-08-16" 553 43
"2017-01-26" 558 44
"2014-03-05" 566 45
"2013-09-18" 571 46
"2016-07-18" 571 47
"2017-06-13" 571 48
"2014-02-17" 587 49
"2013-03-15" 598 50
"2010-03-29" 607 51
"2011-04-07" 623 52
"2012-08-21" 636 53
"2016-02-02" 657 54
"2014-01-15" 661 55
"2017-09-05" 661 56
"2015-09-23" 676 57
"2014-09-15" 709 58
"2012-04-13" 709 59
"2016-04-18" 709 60
"2010-06-28" 709 61
"2016-07-16" 718 62
"2015-11-25" 718 63
"2015-06-16" 718 64
"2017-06-21" 757 65
"2010-12-23" 758 66
"2011-08-01" 758 67
"2013-07-25" 776 68
"2012-12-05" 778 69
"2011-04-26" 807 70
"2016-11-24" 807 71
"2015-01-09" 807 72
"2015-07-21" 810 73
"2015-01-07" 811 74
"2017-04-21" 825 75
"2010-11-22" 836 76
"2011-09-19" 852 77
"2010-06-01" 861 78
"2015-08-31" 869 79
"2015-08-28" 869 80
"2015-11-25" 869 81
"2017-12-12" 869 82
"2015-11-26" 869 83
"2015-10-10" 887 84
"2016-06-07" 887 85
"2015-02-04" 887 86
"2011-07-23" 887 87
"2016-01-19" 901 88
"2016-05-13" 923 89
"2011-10-11" 930 90
"2015-10-01" 938 91
"2015-09-17" 979 92
"2014-10-23" 979 93
"2015-11-27" 979 94
"2016-09-30" 981 95
"2017-05-22" 982 96
"2014-08-22" 982 97
"2010-02-02" 1696 98
"2015-09-17" 2004 99
"2011-12-07" 2004 100
end
save DATA2.dta,replace
* Example generated by -dataex-. To install: ssc install dataex
clear
input long stkcd str10 trddt float dretwd byte markettype float dretwdeq
600285 "2013-12-31" .017989 1 .005722
600783 "2013-12-31" -.010613 1 .005722
601566 "2013-12-31" .000786 1 .005722
600026 "2013-12-31" .020964 1 .005722
600006 "2013-12-31" .00692 1 .005722
600282 "2013-12-31" .021164 1 .005722
600461 "2013-12-31" -.001186 1 .005722
600766 "2013-12-31" .016701 1 .005722
600984 "2013-12-31" -.005405 1 .005722
600558 "2013-12-31" -.00142 1 .005722
600108 "2013-12-31" .011335 1 .005722
600371 "2013-12-31" -.053775 1 .005722
600330 "2013-12-31" -.014739 1 .005722
600337 "2013-12-31" -.009901 1 .005722
600531 "2013-12-31" .055745 1 .005722
600117 "2013-12-31" .013889 1 .005722
601558 "2013-12-31" .007353 1 .005722
603333 "2013-12-31" .01217 1 .005722
600252 "2013-12-31" .024793 1 .005722
600739 "2013-12-31" .00057 1 .005722
600458 "2013-12-31" -.001 1 .005722
600355 "2013-12-31" .007561 1 .005722
600993 "2013-12-31" .023641 1 .005722
600121 "2013-12-31" .012048 1 .005722
603003 "2013-12-31" .006944 1 .005722
600614 "2013-12-31" .001921 1 .005722
600685 "2013-12-31" .005351 1 .005722
600145 "2013-12-31" .005236 1 .005722
600775 "2013-12-31" .030023 1 .005722
600604 "2013-12-31" .061384 1 .005722
600297 "2013-12-31" .00692 1 .005722
600201 "2013-12-31" .006248 1 .005722
600149 "2013-12-31" -.012324 1 .005722
600126 "2013-12-31" .023747 1 .005722
600892 "2013-12-31" .002227 1 .005722
600629 "2013-12-31" .069794 1 .005722
600880 "2013-12-31" -.007018 1 .005722
600070 "2013-12-31" 0 1 .005722
600589 "2013-12-31" .001992 1 .005722
600815 "2013-12-31" 0 1 .005722
600084 "2013-12-31" .002545 1 .005722
600706 "2013-12-31" -.00674 1 .005722
600487 "2013-12-31" -.015836 1 .005722
600597 "2013-12-31" .023041 1 .005722
600598 "2013-12-31" .011628 1 .005722
600019 "2013-12-31" .007389 1 .005722
600405 "2013-12-31" .004251 1 .005722
600459 "2013-12-31" -.014656 1 .005722
600249 "2013-12-31" .014679 1 .005722
600256 "2013-12-31" -.004556 1 .005722
600138 "2013-12-31" .009164 1 .005722
600432 "2013-12-31" .010458 1 .005722
600418 "2013-12-31" .022248 1 .005722
600804 "2013-12-31" -.009859 1 .005722
600862 "2013-12-31" 0 1 .005722
600628 "2013-12-31" .002367 1 .005722
600997 "2013-12-31" .012727 1 .005722
600335 "2013-12-31" -.000769 1 .005722
600613 "2013-12-31" .020225 1 .005722
600816 "2013-12-31" .014235 1 .005722
600590 "2013-12-31" .015175 1 .005722
600526 "2013-12-31" .000981 1 .005722
600400 "2013-12-31" .019231 1 .005722
600210 "2013-12-31" .022013 1 .005722
600654 "2013-12-31" -.001368 1 .005722
600182 "2013-12-31" -.006823 1 .005722
600362 "2013-12-31" .011412 1 .005722
600661 "2013-12-31" .028181 1 .005722
600826 "2013-12-31" .019244 1 .005722
600608 "2013-12-31" .011667 1 .005722
600406 "2013-12-31" .007453 1 .005722
600665 "2013-12-31" 0 1 .005722
600568 "2013-12-31" .004728 1 .005722
600241 "2013-12-31" .011182 1 .005722
600770 "2013-12-31" .021871 1 .005722
600536 "2013-12-31" -.011027 1 .005722
600825 "2013-12-31" .004515 1 .005722
600075 "2013-12-31" .007849 1 .005722
600360 "2013-12-31" -.002506 1 .005722
600846 "2013-12-31" .001761 1 .005722
600202 "2013-12-31" .005848 1 .005722
600519 "2013-12-31" .031496 1 .005722
600897 "2013-12-31" -.03553 1 .005722
600060 "2013-12-31" .013169 1 .005722
600008 "2013-12-31" -.00295 1 .005722
600017 "2013-12-31" 0 1 .005722
600378 "2013-12-31" .005825 1 .005722
600455 "2013-12-31" .004944 1 .005722
600265 "2013-12-31" -.012788 1 .005722
600340 "2013-12-31" .016583 1 .005722
601688 "2013-12-31" .015873 1 .005722
600653 "2013-12-31" 0 1 .005722
600748 "2013-12-31" .01071 1 .005722
600120 "2013-12-31" .002396 1 .005722
600495 "2013-12-31" .006121 1 .005722
600869 "2013-12-31" .004213 1 .005722
600836 "2013-12-31" .007026 1 .005722
600638 "2013-12-31" .02 1 .005722
600500 "2013-12-31" .009296 1 .005722
600083 "2013-12-31" -.022284 1 .005722
end
save sumTRD_Dalyr1m.dta,replace
program count6
version 12.0
local i = 1
while `i' <= 745 {
use DATA2.dta,clear
keep if _n == `i'
save datax1.dta,replace
use datax1.dta,clear
merge 1:m stkcd using sumTRD_Dalyr1m.dta
keep if _merge == 3
drop _merge
sort trddt
gen caseID1 = _n
gen V = 0
replace V= _n if trddt == date
egen V2 = max(V)
gen td = caseID1 - V2
keep if td >= -150 & td <= 1
regress dretwd dretwdeq
predict t
keep if td >= -1 & td <=1
gen AR = dretwd - t
egen CAR = total(AR)
duplicates drop CAR , force
save CARx1.dta, replace
display CAR
display `i'
local i = `i' + 1
}
end
count6