Hello Everyone,

I am new to this forum, so if I missed anything from the FAQ section regarding how to post problems here, please let me know.

I am currently working on an Event Study by examaing the effect of dividend payments on trading volumes. Since I'm not working with STATA on a regular basis, I ran into some problems during the data preparation.

My baseline datasheet contains the company id & name, date, a dummy which indicates the event date, prices, volumes and several dummies to indicate properties of the dividend (like taxes).
Here an example of my datasheet:

input float co_id str19 security float date str8 year double(unadjusted_price adjusted_price volume) int dividend_date byte tax float(days_co co_ret estimationwindow eventwindow twodayeventwindow onedayeventwindow)
1 "1&1 DRILLISCH" 17532 "01012008" 5.5 5.5 . 0 . 1 . 0 0 0 0
1 "1&1 DRILLISCH" 17533 "02012008" 5.2 5.2 86.4 0 . 2 -.05608947 0 0 0 0
1 "1&1 DRILLISCH" 17534 "03012008" 5.42 5.42 144.4 0 . 3 .04143719 0 0 0 0
1 "1&1 DRILLISCH" 17535 "04012008" 5.25 5.25 195 0 . 4 -.03186774 0 0 0 0
1 "1&1 DRILLISCH" 17538 "07012008" 4.96 4.96 221.5 0 . 5 -.05682234 0 0 0 0
1 "1&1 DRILLISCH" 17539 "08012008" 5.05 5.05 244.4 0 . 6 .017982503 0 0 0 0
1 "1&1 DRILLISCH" 17540 "09012008" 4.94 4.94 108.3 0 . 7 -.02202291 0 0 0 0
1 "1&1 DRILLISCH" 17541 "10012008" 4.96 4.96 259.6 0 . 8 .0040404093 0 0 0 0
1 "1&1 DRILLISCH" 17542 "11012008" 4.64 4.64 276.2 0 . 9 -.066691376 0 0 0 0
1 "1&1 DRILLISCH" 17545 "14012008" 4.61 4.61 177.7 0 . 10 -.00648651 0 0 0 0
1 "1&1 DRILLISCH" 17546 "15012008" 4.46 4.46 274.4 0 . 11 -.03307909 0 0 0 0
1 "1&1 DRILLISCH" 17547 "16012008" 4.39 4.39 207.1 0 . 12 -.015819538 0 0 0 0
1 "1&1 DRILLISCH" 17548 "17012008" 4.22 4.22 160.4 0 . 13 -.0394941 0 0 0 0
1 "1&1 DRILLISCH" 17549 "18012008" 4.12 4.12 148.3 0 . 14 -.023981964 0 0 0 0
1 "1&1 DRILLISCH" 17552 "21012008" 3.95 3.95 283.4 0 . 15 -.04213759 0 0 0 0
1 "1&1 DRILLISCH" 17553 "22012008" 4.25 4.25 699.9 0 . 16 .07320341 0 0 0 0
1 "1&1 DRILLISCH" 17554 "23012008" 4.05 4.05 466.4 0 . 17 -.0482021 0 0 0 0
1 "1&1 DRILLISCH" 17555 "24012008" 4.23 4.23 65.3 0 . 18 .04348511 0 0 0 0
1 "1&1 DRILLISCH" 17556 "25012008" 4.43 4.43 265.7 0 . 19 .04619759 0 0 0 0
1 "1&1 DRILLISCH" 17559 "28012008" 4.41 4.41 68.8 0 . 20 -.0045248945 0 0 0 0
1 "1&1 DRILLISCH" 17560 "29012008" 4.56 4.56 41.2 0 . 21 .033447932 0 0 0 0
1 "1&1 DRILLISCH" 17561 "30012008" 4.35 4.35 28.5 0 . 22 -.04714678 0 0 0 0
1 "1&1 DRILLISCH" 17562 "31012008" 4.31 4.31 69.4 0 . 23 -.009237941 0 0 0 0
1 "1&1 DRILLISCH" 17563 "01022008" 4.39 4.39 64.7 0 . 24 .018391322 0 0 0 0
1 "1&1 DRILLISCH" 17566 "04022008" 4.38 4.38 45.8 0 . 25 -.0022805028 0 0 0 0
1 "1&1 DRILLISCH" 17567 "05022008" 4.05 4.05 100.1 0 . 26 -.07833184 0 0 0 0
1 "1&1 DRILLISCH" 17568 "06022008" 4.17 4.17 54 0 . 27 .029199155 0 0 0 0
1 "1&1 DRILLISCH" 17569 "07022008" 4.03 4.03 105.1 0 . 28 -.03414966 0 0 0 0
1 "1&1 DRILLISCH" 17570 "08022008" 3.99 3.99 61.3 0 . 29 -.009975145 0 0 0 0
1 "1&1 DRILLISCH" 17573 "11022008" 4.03 4.03 32.1 0 . 30 .009975145 0 0 0 0
1 "1&1 DRILLISCH" 17574 "12022008" 4.07 4.07 106.2 0 . 31 .009876624 0 0 0 0
1 "1&1 DRILLISCH" 17575 "13022008" 4.14 4.14 52.2 0 . 32 .017052788 0 0 0 0
1 "1&1 DRILLISCH" 17576 "14022008" 4.34 4.34 148.5 0 . 33 .04717856 0 0 0 0
1 "1&1 DRILLISCH" 17577 "15022008" 4.25 4.25 62.2 0 . 34 -.020955365 0 0 0 0
1 "1&1 DRILLISCH" 17580 "18022008" 4.29 4.29 69.9 0 . 35 .00936775 0 0 0 0
1 "1&1 DRILLISCH" 17581 "19022008" 4.27 4.27 236.4 0 . 36 -.004672906 0 0 0 0
1 "1&1 DRILLISCH" 17582 "20022008" 4.42 4.42 151.4 0 . 37 .034525868 0 0 0 0
1 "1&1 DRILLISCH" 17583 "21022008" 4.35 4.35 88.9 0 . 38 -.01596385 0 0 0 0
1 "1&1 DRILLISCH" 17584 "22022008" 4.27 4.27 99.5 0 . 39 -.018562017 0 0 0 0
1 "1&1 DRILLISCH" 17587 "25022008" 4.4 4.4 41.7 0 . 40 .029990714 0 0 0 0
1 "1&1 DRILLISCH" 17588 "26022008" 4.6 4.6 166.3 0 . 41 .04445176 0 0 0 0
1 "1&1 DRILLISCH" 17589 "27022008" 4.5 4.5 113 0 . 42 -.02197891 0 0 0 0
1 "1&1 DRILLISCH" 17590 "28022008" 4.76 4.76 377.5 0 . 43 .05617027 0 0 0 0
1 "1&1 DRILLISCH" 17591 "29022008" 4.73 4.73 397.5 0 . 44 -.006322466 0 0 0 0
1 "1&1 DRILLISCH" 17594 "03032008" 4.67 4.67 264.5 0 . 45 -.01276613 1 0 0 0
1 "1&1 DRILLISCH" 17595 "04032008" 4.69 4.69 70.7 0 . 46 .004273511 1 0 0 0
1 "1&1 DRILLISCH" 17596 "05032008" 4.73 4.73 251.9 0 . 47 .00849262 1 0 0 0
1 "1&1 DRILLISCH" 17597 "06032008" 4.34 4.34 148 0 . 48 -.08605085 1 0 0 0
1 "1&1 DRILLISCH" 17598 "07032008" 4.2 4.2 96.7 0 . 49 -.032789823 1 0 0 0
1 "1&1 DRILLISCH" 17601 "10032008" 4.05 4.05 99.2 0 . 50 -.036367644 1 0 0 0
1 "1&1 DRILLISCH" 17602 "11032008" 4.24 4.24 134.6 0 . 51 .04584639 1 0 0 0
1 "1&1 DRILLISCH" 17603 "12032008" 4.24 4.24 97.2 0 . 52 0 1 0 0 0
1 "1&1 DRILLISCH" 17604 "13032008" 4.16 4.16 83 0 . 53 -.019048195 1 0 0 0
1 "1&1 DRILLISCH" 17605 "14032008" 4.31 4.31 43.1 0 . 54 .035422828 1 0 0 0
1 "1&1 DRILLISCH" 17608 "17032008" 4.15 4.15 57.6 0 . 55 -.03782957 1 0 0 0
1 "1&1 DRILLISCH" 17609 "18032008" 4.18 4.18 103.4 0 . 56 .007202912 1 0 0 0
1 "1&1 DRILLISCH" 17610 "19032008" 4.05 4.05 106.8 0 . 57 -.031594366 1 0 0 0
1 "1&1 DRILLISCH" 17611 "20032008" 4.09 4.09 53.7 0 . 58 .00982809 1 0 0 0
1 "1&1 DRILLISCH" 17612 "21032008" 4.09 4.09 . 0 . 59 0 1 0 0 0
1 "1&1 DRILLISCH" 17615 "24032008" 4.09 4.09 . 0 . 60 0 1 0 0 0
1 "1&1 DRILLISCH" 17616 "25032008" 4.46 4.46 104.4 0 . 61 .0866038 1 0 0 0
1 "1&1 DRILLISCH" 17617 "26032008" 4.4 4.4 154.7 0 . 62 -.013544225 1 0 0 0
1 "1&1 DRILLISCH" 17618 "27032008" 4.31 4.31 83.3 0 . 63 -.020666637 1 0 0 0
1 "1&1 DRILLISCH" 17619 "28032008" 4.34 4.34 72.1 0 . 64 .006936444 1 0 0 0
1 "1&1 DRILLISCH" 17622 "31032008" 4.43 4.43 86 0 . 65 .020525236 1 0 0 0
1 "1&1 DRILLISCH" 17623 "01042008" 4.56 4.56 140.4 0 . 66 .02892304 1 0 0 0
1 "1&1 DRILLISCH" 17624 "02042008" 4.29 4.29 136.2 0 . 67 -.06103589 1 0 0 0
1 "1&1 DRILLISCH" 17625 "03042008" 4.17 4.17 119.7 0 . 68 -.028370697 1 0 0 0
1 "1&1 DRILLISCH" 17626 "04042008" 4.37 4.37 182.6 0 . 69 .04684697 1 0 0 0
1 "1&1 DRILLISCH" 17629 "07042008" 4.75 4.75 153.8 0 . 70 .0833816 1 0 0 0
1 "1&1 DRILLISCH" 17630 "08042008" 4.6 4.6 86.8 0 . 71 -.032088313 1 0 0 0
1 "1&1 DRILLISCH" 17631 "09042008" 4.65 4.65 46.3 0 . 72 .010810916 1 0 0 0
1 "1&1 DRILLISCH" 17632 "10042008" 4.6 4.6 52.4 0 . 73 -.010810916 1 0 0 0
1 "1&1 DRILLISCH" 17633 "11042008" 4.54 4.54 51.3 0 . 74 -.01312929 1 0 0 0
1 "1&1 DRILLISCH" 17636 "14042008" 4.45 4.45 77 0 . 75 -.020022916 1 0 0 0
1 "1&1 DRILLISCH" 17637 "15042008" 4.39 4.39 58.9 0 . 76 -.01357487 1 0 0 0
1 "1&1 DRILLISCH" 17638 "16042008" 4.27 4.27 103.5 0 . 77 -.0277154 1 0 0 0
1 "1&1 DRILLISCH" 17639 "17042008" 4.34 4.34 30.2 0 . 78 .016260521 1 0 0 0
1 "1&1 DRILLISCH" 17640 "18042008" 4.35 4.35 74 0 . 79 .002301497 1 0 0 0
1 "1&1 DRILLISCH" 17643 "21042008" 4.3 4.3 46 0 . 80 -.011560823 1 0 0 0
1 "1&1 DRILLISCH" 17644 "22042008" 4.37 4.37 51.8 0 . 81 .016147986 1 0 0 0
1 "1&1 DRILLISCH" 17645 "23042008" 4.42 4.42 32.1 0 . 82 .011376687 1 0 0 0
1 "1&1 DRILLISCH" 17646 "24042008" 4.35 4.35 30.1 0 . 83 -.01596385 1 0 0 0
1 "1&1 DRILLISCH" 17647 "25042008" 4.35 4.35 34.9 0 . 84 0 1 0 0 0
1 "1&1 DRILLISCH" 17650 "28042008" 4.1 4.1 193.1 0 . 85 -.05918887 1 0 0 0
1 "1&1 DRILLISCH" 17651 "29042008" 3.75 3.75 524.1 0 . 86 -.08923113 1 0 0 0
1 "1&1 DRILLISCH" 17652 "30042008" 3.9 3.9 186.6 0 . 87 .03922071 1 0 0 0
1 "1&1 DRILLISCH" 17653 "01052008" 3.9 3.9 . 0 . 88 0 1 0 0 0
1 "1&1 DRILLISCH" 17654 "02052008" 3.9 3.9 75.3 0 . 89 0 1 0 0 0
1 "1&1 DRILLISCH" 17657 "05052008" 4.03 4.03 49.3 0 . 90 .032789823 1 0 0 0
1 "1&1 DRILLISCH" 17658 "06052008" 4 4 27.7 0 . 91 -.007472015 1 0 0 0
1 "1&1 DRILLISCH" 17659 "07052008" 4.2 4.2 71.1 0 . 92 .04879016 1 0 0 0
1 "1&1 DRILLISCH" 17660 "08052008" 4.22 4.22 8 0 . 93 .004750603 1 0 0 0
1 "1&1 DRILLISCH" 17661 "09052008" 4.26 4.26 49.6 0 . 94 .009434032 1 0 0 0
1 "1&1 DRILLISCH" 17664 "12052008" 4.43 4.43 32.1 0 . 95 .03913042 1 0 0 0
1 "1&1 DRILLISCH" 17665 "13052008" 4.48 4.48 32.5 0 . 96 .011223462 1 0 0 0
1 "1&1 DRILLISCH" 17666 "14052008" 4.4 4.4 169.8 0 . 97 -.018018505 1 0 0 0
1 "1&1 DRILLISCH" 17667 "15052008" 4.54 4.54 245.5 0 . 98 .03132247 1 0 0 0
1 "1&1 DRILLISCH" 17668 "16052008" 4.69 4.69 65.1 0 . 99 .03250557 1 0 0 0
1 "1&1 DRILLISCH" 17671 "19052008" 4.64 4.64 84.2 0 . 100 -.010718216 1 1 0 0


First Problem:
I tried to create event-windows around the event date (ex-dividend date) and started with a code like this, where the dividend_date dummy equals 1 at the ex-dividend date:

First approach:

gen eventwindow=0
replace eventwindow=1 if dividend_date[_n-10]==1
replace eventwindow=1 if dividend_date[_n-9]==1
replace eventwindow=1 if dividend_date[_n-8]==1
replace eventwindow=1 if dividend_date[_n-7]==1
replace eventwindow=1 if dividend_date[_n-6]==1
replace eventwindow=1 if dividend_date[_n-5]==1
replace eventwindow=1 if dividend_date[_n-4]==1
replace eventwindow=1 if dividend_date[_n-3]==1
replace eventwindow=1 if dividend_date[_n-2]==1
replace eventwindow=1 if dividend_date[_n-1]==1
replace eventwindow=1 if dividend_date==1
replace eventwindow=1 if dividend_date[_n+1]==1
replace eventwindow=1 if dividend_date[_n+2]==1
replace eventwindow=1 if dividend_date[_n+3]==1
replace eventwindow=1 if dividend_date[_n+4]==1
replace eventwindow=1 if dividend_date[_n+5]==1
replace eventwindow=1 if dividend_date[_n+6]==1
replace eventwindow=1 if dividend_date[_n+7]==1
replace eventwindow=1 if dividend_date[_n+8]==1
replace eventwindow=1 if dividend_date[_n+9]==1
replace eventwindow=1 if dividend_date[_n+10]==1

This approach seemed to work at first but is rather inefficient when it comes to larger windows. So I tried the following approach, which led to my first problem:

Second approach:

sort co_id date
by co_id: gen datenum=_n
by co_id: gen target=datenum if dividend_date==1
egen td=min(target), by(co_id)
drop target
gen dif=datenum-td

The dif variable counts the number of days from the observation to the event date (and further), with which I could create the dummies more efficiently. However this formular only works for one event per company. Since I'm analyzing dividend payments over seven years, I have obviously more than one event per company and STATA takes the first target date, calculates the difference from the other observations and ignores all following targets. My idea would be to create a "time-frame" around the calculation of dif, so that it can calculate the new difference for the next target (e.g. only calculate the difference 100 days around the event date). However, I am not sure how to do this.

To be more precise, one problem appears by the creation of the tax dummy (which indicates if a dividend is taxable or not). If the dividend is taxable the dummy equals one, if the dividend is tax free, it equals zero and for observations with no dividend payments it has missing values. Since I generate interactions between the tax dummy and the window dummies, the tax dummy has to take on the value 1 or 0 for a specific number of days around the event day, according to the lenght of the window (otherwise the interaction would be always 0 except for the event date --> all interactions would be the same). Following my first approach, I don't know how to lag this tax dummy around the event date, so I tried to use the second approach.


Second Problem:
Since my eventwindow dummy from above is binary, I (think I) can only include it as a normal variable in my regression. However, I want my regression to take the baseline effects of every lagged value of this window into account (Like the i.year variable would do it for every year). I am not sure how to generate my dummy (or write my regression function) in a way that every lagged value (negative and positve lag --> from -10 days to +10 days) appears in my regression output.

I hope I provided enough information for you to understand my problem.
Thank you very much for your help!