I would like to find the largest % of institutional ownership for each deal, for example, finding the largest % of institutional ownership for deal_no 2041148040. I add some time conditions for finding the largest % of institutional ownership. In the first step, I want to get all observations that ann_date are larger than rdate. Then, I want to get all observations that only have the maximum rdate for each mgrno for each deal_no (i.e. one maxrdate for one mgrno for one deal_no). Finally, I want to get all observations that have the largest % of institutional ownership for each deal_no. I used -bysort- to realize it but it seems that I did not do it the right way. Codes and an example are as follows. Is there something that I did wrong? Could anyone help me to handle this problem?
Code:
keep if ann_date > rdate
bysort mgrno acusip6 ann_date (rdate) : gen seq=_n
bysort mgrno acusip6 ann_date(rdate) : gen seqmax = _N
gen maxrdate = rdate if seq == seqmax & rdate!= .
format maxrdate %d
drop if maxrdate==.
drop seq seqmax
gen pershrheld = (shrheld/(shrout*1000))*100 /*calculate % of institutional ownership*/
bysort deal_no (pershrheld) : gen seq=_n
bysort deal_no (pershrheld) : gen seqmax = _N
gen max_pershrheld = pershrheld if seq == seqmax & pershrheld!= .
drop if max_pershrheld==.
drop seq seqmax
Example:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double mgrno str6 acusip6 int ann_date str10 deal_no double deal_value long rdate double(shrheld shrout) 110 "110122" 18100 "2093103020" 2247.397 17987 84544 1979863 110 "110122" 18100 "2093103020" 2247.397 18078 84544 1980883 110 "110122" 18100 "2093103020" 2247.397 18170 84544 1980925 110 "110122" 18100 "2093103020" 2247.397 18262 84544 1980980 110 "149123" 18231 "2133213040" 36.162 17987 22300 601527 110 "149123" 18231 "2133213040" 36.162 18078 22300 601752 110 "149123" 18231 "2133213040" 36.162 18170 22300 621294 110 "149123" 18231 "2133213040" 36.162 18262 19300 622728 110 "17275R" 17975 "2055874020" 590 17987 21200 5837017 110 "17275R" 17975 "2055874020" 590 18078 21200 5767881 110 "17275R" 17975 "2055874020" 590 18170 21200 5792675 110 "17275R" 17975 "2055874020" 590 18262 20200 5752585 110 "17275R" 18171 "2114183040" 3426.393 17987 21200 5837017 110 "17275R" 18171 "2114183040" 3426.393 18078 21200 5767881 110 "17275R" 18171 "2114183040" 3426.393 18170 21200 5792675 110 "17275R" 18171 "2114183040" 3426.393 18262 20200 5752585 110 "17275R" 18183 "2117364020" 2776.679 17987 21200 5837017 110 "17275R" 18183 "2117364020" 2776.679 18078 21200 5767881 110 "17275R" 18183 "2117364020" 2776.679 18170 21200 5792675 110 "17275R" 18183 "2117364020" 2776.679 18262 20200 5752585 110 "291011" 18176 "2115437020" 1108.804 17987 7130 755037 110 "291011" 18176 "2115437020" 1108.804 18078 7130 751441 110 "291011" 18176 "2115437020" 1108.804 18170 7130 751590 110 "291011" 18176 "2115437020" 1108.804 18262 7130 752278 110 "293792" 18016 "2069393020" 3283.249 17987 33240 449945 110 "293792" 18016 "2069393020" 3283.249 18078 33240 460249 110 "293792" 18016 "2069393020" 3283.249 18170 33240 476867 110 "293792" 18016 "2069393020" 3283.249 18262 33240 604716 110 "30231G" 18245 "2137370020" 40298.142 17987 152531 4941630 110 "30231G" 18245 "2137370020" 40298.142 18078 152531 4879710 110 "30231G" 18245 "2137370020" 40298.142 18170 152531 4805790 110 "30231G" 18245 "2137370020" 40298.142 18262 150881 4731898 110 "369604" 18234 "2133890020" 3800 17987 254830 10569000 110 "369604" 18234 "2133890020" 3800 18078 254830 10589575 110 "369604" 18234 "2133890020" 3800 18170 254830 10626842 110 "369604" 18234 "2133890020" 3800 18262 251830 10647495 110 "458140" 18052 "2079367020" 890.287 17987 33000 5562000 110 "458140" 18052 "2079367020" 890.287 18078 33000 5585000 110 "458140" 18052 "2079367020" 890.287 18170 33000 5598000 110 "458140" 18052 "2079367020" 890.287 18262 33000 5522000 110 "459200" 18106 "2094434020" 950.571 17987 65896 1814836 110 "459200" 18106 "2094434020" 950.571 18078 65896 1814836 110 "459200" 18106 "2094434020" 950.571 18170 64396 1814836 110 "459200" 18106 "2094434020" 950.571 18262 58892 1814836 110 "478160" 18038 "2075617020" 988.216 17987 21910 2767644 110 "478160" 18038 "2075617020" 988.216 18078 35860 2755566 110 "478160" 18038 "2075617020" 988.216 18170 35810 2755814 110 "478160" 18038 "2075617020" 988.216 18262 35810 2759100 110 "494368" 18179 "2116673020" 315.072 17987 19040 413997 110 "494368" 18179 "2116673020" 315.072 18078 19040 414206 110 "494368" 18179 "2116673020" 315.072 18170 19040 414493 110 "494368" 18179 "2116673020" 315.072 18262 16040 415379 110 "713448" 18007 "2066470020" 2060.375 17987 26700 1556731 110 "713448" 18007 "2066477020" 5421.629 17987 26700 1556731 110 "713448" 18007 "2066477020" 5421.629 18078 26700 1556791 110 "713448" 18007 "2066470020" 2060.375 18078 26700 1556791 110 "713448" 18007 "2066477020" 5421.629 18170 26700 1557999 110 "713448" 18007 "2066470020" 2060.375 18170 26700 1557999 110 "713448" 18007 "2066477020" 5421.629 18262 26700 1560445 110 "713448" 18007 "2066470020" 2060.375 18262 26700 1560445 110 "717081" 17923 "2044727020" 67285.695 17987 189475 6744640 110 "717081" 17923 "2044727020" 67285.695 18078 189475 6747979 110 "717081" 17923 "2044727020" 67285.695 18170 189475 6749143 110 "717081" 17923 "2044727020" 67285.695 18262 188415 8069536 115 "111320" 18231 "2132632020" 178 17897 20000 435900 115 "111320" 18231 "2132632020" 178 17897 20000 429800 115 "111320" 18231 "2132632020" 178 17897 20000 429650 127 "49446R" 18205 "2125038020" 444 17987 2199100 271084 127 "49446R" 18205 "2125038020" 444 18078 2880804 376352 127 "49446R" 18205 "2125038020" 444 18170 2794604 376366 127 "49446R" 18205 "2125038020" 444 18262 2975004 376751 135 "369604" 18234 "2133890020" 3800 17987 23700 10626842 135 "369604" 18234 "2133890020" 3800 17987 23700 10647495 135 "369604" 18234 "2133890020" 3800 17987 23700 10569000 135 "369604" 18234 "2133890020" 3800 17987 23700 10589575 155 "00724F" 18155 "2108492020" 1738.286 17987 34378 524207 155 "156708" 17910 "2042315020" 350 17987 12133 68809 155 "184496" 18016 "2069332040" 380.249 17987 86643 23749 155 "184496" 18016 "2069332040" 380.249 18078 89524 23328 155 "384802" 18052 "2079821040" 1.2 17987 13150 74480 155 "45666Q" 17940 "2050876020" 40 18078 259117 87137 155 "45666Q" 17940 "2050876020" 40 18170 297631 88365 155 "45666Q" 17940 "2050876020" 40 18262 318613 89450 155 "46612K" 18206 "2124946020" 414.883 18170 245673 31970 155 "46612K" 18206 "2124946020" 414.883 18262 268380 34515 155 "682189" 18205 "2128041020" 17 18078 762722 420353 155 "682189" 18205 "2128041020" 17 18170 876221 422099 155 "682189" 18245 "2137467020" 110.695 18078 762722 420353 155 "682189" 18245 "2137467020" 110.695 18170 876221 422099 155 "74762E" 18143 "2105124020" 337.217 17987 53119 196933 155 "74762E" 18143 "2105124020" 337.217 18078 17218 197631 155 "74762E" 18143 "2105124020" 337.217 18170 16716 197664 155 "74762E" 18143 "2105124020" 337.217 18262 16116 209171 155 "768573" 17917 "2044048020" 47 17987 279053 69147 155 "768573" 17917 "2044048020" 47 18078 194249 68501 155 "859241" 18234 "2135837020" 64.7 17987 251182 13190 155 "87929J" 18217 "2128380020" 1.935 18262 414559 42274 155 "87929J" 18232 "2133335020" 170 18262 414559 42274 155 "883556" 18143 "2076260040" 470.622 17987 25319 418165 155 "928563" 18119 "2098246020" 362 17987 38506 90654 end format %d ann_date format %td rdate
Best regards,
Wenyu
0 Response to How to get conditional maximum dates and values?
Post a Comment