Hi all,
Thanks for taking the time to review my post. The reason why I am posting is for two reasons:
- To hear other opinions on how I could improve my code
- To find out how to see the AAR per day (including T-stat) and show this in a graph.
Goal of the analysis:
Event study on log. relative bid-ask spread to uncover the effect of stock splits on the liquidity of a stock, as measured by the relative bid-ask spread.
My data is organised as follows:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long PERMNO float(date LogRSpread) int eventdate float tau 10443 18546 -4.139922 18644 -98 10443 18547 -3.937159 18644 -97 10443 18548 -5.106545 18644 -96 10443 18549 -4.833041 18644 -95 10443 18550 -3.3638716 18644 -94 10443 18553 -4.3248663 18644 -91 10443 18554 -3.876368 18644 -90 10443 18555 -4.095077 18644 -89 10443 18556 -5.602118 18644 -88 10443 18557 -4.437783 18644 -87 10443 18560 -3.973706 18644 -84 10443 18561 -3.941876 18644 -83 10443 18562 -3.9787896 18644 -82 10443 18563 -5.635691 18644 -81 10443 18564 -8.824466 18644 -80 10443 18567 -4.647195 18644 -77 10443 18568 -3.784191 18644 -76 10443 18569 -4.648323 18644 -75 10443 18570 -3.005592 18644 -74 10443 18571 -3.880131 18644 -73 10443 18574 -4.236179 18644 -70 10443 18575 -4.472607 18644 -69 10443 18576 -3.666538 18644 -68 10443 18577 -4.55462 18644 -67 10443 18578 . 18644 -66 10443 18581 -5.78016 18644 -63 10443 18582 -4.905274 18644 -62 10443 18583 -4.905274 18644 -61 10443 18584 -5.826015 18644 -60 10443 18585 -8.814454 18644 -59 10443 18588 -4.3228674 18644 -56 10443 18589 -4.164725 18644 -55 10443 18590 . 18644 -54 10443 18592 -2.643828 18644 -52 10443 18595 -4.3546066 18644 -49 10443 18596 -2.2618823 18644 -48 10443 18597 -2.6097634 18644 -47 10443 18598 -2.397116 18644 -46 10443 18599 -2.476103 18644 -45 10443 18602 -2.489985 18644 -42 10443 18603 -2.77158 18644 -41 10443 18604 -3.832982 18644 -40 10443 18605 -3.033568 18644 -39 10443 18606 -3.403029 18644 -38 10443 18609 -3.1247175 18644 -35 10443 18610 -3.317936 18644 -34 10443 18611 -4.3353453 18644 -33 10443 18612 -3.108409 18644 -32 10443 18613 -2.902453 18644 -31 10443 18616 -2.972753 18644 -28 10443 18617 -3.0790806 18644 -27 10443 18618 -3.1436265 18644 -26 10443 18619 -3.0012724 18644 -25 10443 18623 -3.0027125 18644 -21 10443 18624 -3.574251 18644 -20 10443 18625 -3.207905 18644 -19 10443 18626 -3.8843596 18644 -18 10443 18627 -3.381081 18644 -17 10443 18630 -3.580943 18644 -14 10443 18631 -4.295885 18644 -13 10443 18632 -3.785299 18644 -12 10443 18633 -3.8042226 18644 -11 10443 18634 -3.7517455 18644 -10 10443 18637 -4.0900326 18644 -7 10443 18638 . 18644 -6 10443 18639 -5.146551 18644 -5 10443 18640 -3.951028 18644 -4 10443 18641 -4.850204 18644 -3 10443 18645 -3.8299186 18644 1 10443 18646 -2.924186 18644 2 10443 18647 -3.884683 18644 3 10443 18648 -4.2708616 18644 4 10443 18651 -3.234684 18644 7 10443 18652 -3.364364 18644 8 10443 18653 -3.3640034 18644 9 10443 18654 -4.1229324 18644 10 10892 20128 -3.407737 20226 -98 10892 20129 -3.805487 20226 -97 10892 20130 -3.948497 20226 -96 10892 20131 -3.1768684 20226 -95 10892 20132 -4.453464 20226 -94 10892 20136 -3.8792624 20226 -90 10892 20137 -4.2115464 20226 -89 10892 20138 -4.1630406 20226 -88 10892 20139 -3.912282 20226 -87 10892 20142 -4.5297427 20226 -84 10892 20143 -4.534513 20226 -83 10892 20144 -4.4456244 20226 -82 10892 20145 -4.2594748 20226 -81 10892 20146 -4.3434205 20226 -80 10892 20149 -4.1756773 20226 -77 10892 20150 -3.515802 20226 -76 10892 20151 -3.584601 20226 -75 10892 20152 -4.6016974 20226 -74 10892 20153 -3.595833 20226 -73 10892 20156 -4.4499717 20226 -70 10892 20157 -3.7702174 20226 -69 10892 20158 -4.390059 20226 -68 10892 20159 -4.153621 20226 -67 10892 20160 -4.1874175 20226 -66 end format %td date format %tdnn/dd/CCYY eventdate
In order to get to the desired results, I have used the following code:
Code:
local Initialdate_str="2000-01-01" local Finaldate_str="2020-12-31" local PathDataOutput = "\\studfiles.campus.uvt.nl\files\home\home01\u897141\Master\Thesis\LiqES" local EstWindStart = -100 local EstWindEnd = -10 local EventWindStart = 0 local EventWindEnd = 10 local Distance = `EventWindEnd' - `EstWindStart' + 1 import excel "T:\HR\Urenstaten\Roman\ThesisBackUpFiles\LiqEventStudy\PERMNOSplitDate.xlsx", sheet("Sheet1") rename A PERMNO rename B eventdate egen eventid = group(eventdate PERMNO) expand `Distance' bys eventid: gen tau = _n + `EstWindStart' -1 assert(tau<=`EventWindEnd') gen date = eventdate+tau format date %td tempfile DateFile save `DateFile', replace import excel "T:\HR\Urenstaten\Roman\ThesisBackUpFiles\LiqEventStudy\CleanedExtractFromWRDS.xlsx", sheet("Sheet1") firstrow clear format date %td merge m:1 PERMNO date using `DateFile' drop if missing(eventid) drop if missing(Combined) gen LogRSpread = ln(RelativeSpread) egen group_id = group(PERMNO) gen mean=. qui levelsof PERMNO,local(fid) foreach fid in `fid' { sum LogRSpread if tau<=`EstWindEnd' & tau>=`EstWindStart' & PERMNO==`fid' replace mean = r(mean) if PERMNO==`fid' } drop _merge sort PERMNO date gen Abn = LogRSpread - mean sum Abn if tau <=`EstWindEnd' drop if tau<=`EstWindEnd' collapse (sum) Abn, by(group_id PERMNO) qui levelsof PERMNO, local(listfirms) foreach ff in `listfirms'{ qui sum Abn if PERMNO==`ff' } reg Abn
Furthermore, I would like to see the AAR and accompanying T-stat per day, and produce a nice list so I can make a graph in Excel. Unfortunately, I have not been able to do so..
Really hope someone has an idea on how to achieve this.
Thanks a lot for reading,
0 Response to Request for second-opinion on Stata code and suggestion on how to see AAR per day (with t-stat)
Post a Comment