Dear community,

I want to perform an event study on dividend announcement effects. My problem is that when using the following code, only one announcement is taken per company, while the others are looked over, and thus I cannot create an estimation window for all the different announcements. This is the code I used:
Code:
 
 sort comname date by comname: gen datenum=_n by comname: gen target=datenum if date==anncdate egen td=min(target), by(company_id) drop target gen dif=datenum-td
And it works well for the first announcement date:
Code:
clear
input long GlobalCompanyKeyDividends int date str28 CompanyName double(PriceCloseDaily div) float(anncdate dif)
207161 18322 "DIALIGHT"   2.55    .     . -2
207161 18323 "DIALIGHT"    2.7    .     . -1
207161 18324 "DIALIGHT"    2.7 .043 18324  0
207161 18325 "DIALIGHT"   2.65    .     .  1
207161 18326 "DIALIGHT"  2.575    .     .  2
207161 18329 "DIALIGHT"   2.55    .     .  3
207161 18330 "DIALIGHT" 2.5725    .     .  4
207161 18331 "DIALIGHT" 2.5175    .     .  5
207161 18332 "DIALIGHT"   2.48    .     .  6
207161 18333 "DIALIGHT"  2.435    .     .  7
207161 18336 "DIALIGHT"    2.5    .     .  8
207161 18337 "DIALIGHT"    2.5    .     .  9
207161 18338 "DIALIGHT"    2.5    .     . 10
207161 18339 "DIALIGHT"  2.525    .     . 11
207161 18340 "DIALIGHT" 2.4725    .     . 12
end
format %td date
format %td anncdate
But is continues counting upwards for difference in date when presented another announcement.
Code:
clear
input long GlobalCompanyKeyDividends int date str28 CompanyName double(PriceCloseDaily div) float(anncdate dif)
207161 18463 "DIALIGHT"  3.175    .     .  99
207161 18464 "DIALIGHT" 3.2425    .     . 100
207161 18465 "DIALIGHT"  3.205    .     . 101
207161 18466 "DIALIGHT"  3.355    .     . 102
207161 18469 "DIALIGHT"   3.42 .028 18469 103
207161 18470 "DIALIGHT"   3.35    .     . 104
207161 18471 "DIALIGHT"  3.405    .     . 105
207161 18472 "DIALIGHT"  3.385    .     . 106
207161 18473 "DIALIGHT"    3.5    .     . 107
207161 18476 "DIALIGHT" 3.5175    .     . 108
207161 18477 "DIALIGHT"  3.725    .     . 109
207161 18478 "DIALIGHT"  3.735    .     . 110
207161 18479 "DIALIGHT"    3.8    .     . 111
end
format %td date
format %td anncdate
Is there a way to make Stata recognise that it should count from -130 to +5 in days for my entire window around an annoncement?

Kind regards,

Victor Schaper