Hello Stata forum:

I want to make an event study for share repurchase announcements by using the calendar time approach. However, I could not figure out how to make monthly calendar portfolios in STATA. The methodology is as follow: for each calendar month over the entire sample period, I have to construct a portfolio with all firms experiencing the event within the previous 12 months. For example the monthly portfolio in 01/2006 considers all the events in the previous 12 months. Afterwards, I need to calculate the calendar time returns for the monthly portfolios.

You can find below an small sample of my dataset .
(J=0 for the event month, ret= monthly returns for each month)

Does anyone can help me with this?

Thanks in advance.


Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str17 cusip float(monthly_date announcmonth ret j year) byte(dummy2005    dummy2006    dummy2007    dummy2008    dummy2009)
"18145710" 528 540            . -12 2005 1 0 0 0 0
"18145710" 529 540     -.156268 -11 2005 1 0 0 0 0
"18145710" 530 540   .008862665 -10 2005 1 0 0 0 0
"18145710" 531 540    .07696108  -9 2005 1 0 0 0 0
"18145710" 532 540   -.04911707  -8 2005 1 0 0 0 0
"18145710" 533 540     .0594124  -7 2005 1 0 0 0 0
"18145710" 534 540   -.20180938  -6 2005 1 0 0 0 0
"18145710" 535 540   -.11968128  -5 2005 1 0 0 0 0
"18145710" 536 540   .006669173  -4 2005 1 0 0 0 0
"18145710" 537 540   -.04378057  -3 2005 1 0 0 0 0
"18145710" 538 540     .2505425  -2 2005 1 0 0 0 0
"18145710" 539 540   -.07028065  -1 2005 1 0 0 0 0
"18145710" 540 540   -.14166453   0 2005 1 0 0 0 0
"18145710" 541 540    .26002008   1 2005 1 0 0 0 0
"18145710" 542 540   -.12093624   2 2005 1 0 0 0 0
"18145710" 543 540   -.11126358   3 2005 1 0 0 0 0
"18145710" 544 540    .04586339   4 2005 1 0 0 0 0
"18145710" 545 540  -.011793413   5 2005 1 0 0 0 0
"18145710" 546 540   .013171804   6 2005 1 0 0 0 0
"18145710" 547 540    .11318108   7 2005 1 0 0 0 0
"18145710" 548 540   .034454886   8 2005 1 0 0 0 0
"18145710" 549 540   -.09531017   9 2005 1 0 0 0 0
"18145710" 550 540   -.07955264  10 2005 1 0 0 0 0
"18145710" 551 540   -.06430265  11 2005 1 0 0 0 0
"18145710" 552 540  -.003023431  12 2005 1 0 0 0 0
"18145710" 553 540    -.2239008  13 2005 1 0 0 0 0
"18145710" 554 540    .11187335  14 2005 1 0 0 0 0
"18145710" 555 540     .1036656  15 2005 1 0 0 0 0
"18145710" 556 540   .007604556  16 2005 1 0 0 0 0
"18145710" 557 540            0  17 2005 1 0 0 0 0
"18145710" 558 540    -.0894938  18 2005 1 0 0 0 0
"18145710" 559 540    .06727918  19 2005 1 0 0 0 0
"18145710" 560 540   -.13585782  20 2005 1 0 0 0 0
"18145710" 561 540    .10438398  21 2005 1 0 0 0 0
"18145710" 562 540    .27075297  22 2005 1 0 0 0 0
"18145710" 563 540    .01392693  23 2005 1 0 0 0 0
"18145710" 564 540  -.006636447  24 2005 1 0 0 0 0
"18145710" 565 540    .03917414  25 2005 1 0 0 0 0
"18145710" 566 540            .  26 2005 1 0 0 0 0
"20594410" 528 540            . -12 2005 1 0 0 0 0
"20594410" 529 540    .04019561 -11 2005 1 0 0 0 0
"20594410" 530 540   .010471255 -10 2005 1 0 0 0 0
"20594410" 531 540    .08442876  -9 2005 1 0 0 0 0
"20594410" 532 540   .064093895  -8 2005 1 0 0 0 0
"20594410" 533 540   .064089514  -7 2005 1 0 0 0 0
"20594410" 534 540  -.007244732  -6 2005 1 0 0 0 0
"20594410" 535 540  -.005833703  -5 2005 1 0 0 0 0
"20594410" 536 540 -.0007315883  -4 2005 1 0 0 0 0
"20594410" 537 540    .06584889  -3 2005 1 0 0 0 0
"20594410" 538 540    .06563719  -2 2005 1 0 0 0 0
"20594410" 539 540    .06920672  -1 2005 1 0 0 0 0
"20594410" 540 540   -.06579011   0 2005 1 0 0 0 0
"20594410" 541 540  -.022419583   1 2005 1 0 0 0 0
"20594410" 542 540    .01985824   2 2005 1 0 0 0 0
"20594410" 543 540   -.09030033   3 2005 1 0 0 0 0
"20594410" 544 540    .04124294   4 2005 1 0 0 0 0
"20594410" 545 540   .007825692   5 2005 1 0 0 0 0
"20594410" 546 540    .13889003   6 2005 1 0 0 0 0
"20594410" 547 540  -.021948734   7 2005 1 0 0 0 0
"20594410" 548 540    .03943405   8 2005 1 0 0 0 0
"20594410" 549 540    .06934837   9 2005 1 0 0 0 0
"20594410" 550 540   .012889726  10 2005 1 0 0 0 0
"20594410" 551 540  -.019665806  11 2005 1 0 0 0 0
"20594410" 552 540   -.08666985  12 2005 1 0 0 0 0
"20594410" 553 540   -.02109907  13 2005 1 0 0 0 0
"20594410" 554 540   -.00479429  14 2005 1 0 0 0 0
"20594410" 555 540    .10951691  15 2005 1 0 0 0 0
"20594410" 556 540    .05872254  16 2005 1 0 0 0 0
"20594410" 557 540  -.019826317  17 2005 1 0 0 0 0
"20594410" 558 540   -.15766685  18 2005 1 0 0 0 0
"20594410" 559 540  -.033497453  19 2005 1 0 0 0 0
"20594410" 560 540   -.06541663  20 2005 1 0 0 0 0
"20594410" 561 540     .0511036  21 2005 1 0 0 0 0
"20594410" 562 540  -.022511385  22 2005 1 0 0 0 0
"20594410" 563 540   -.04614834  23 2005 1 0 0 0 0
"20594410" 564 540    .12171114  24 2005 1 0 0 0 0
"20594410" 565 540  -.012136118  25 2005 1 0 0 0 0
"20594410" 566 540   .014144523  26 2005 1 0 0 0 0
"20594410" 567 540    .09176532  27 2005 1 0 0 0 0
"20594410" 568 540   .037191022  28 2005 1 0 0 0 0
"20594410" 569 540   -.12096267  29 2005 1 0 0 0 0
"20594410" 570 540  -.017063593  30 2005 1 0 0 0 0
"20594410" 571 540   -.01859663  31 2005 1 0 0 0 0
"20594410" 572 540   -.05250994  32 2005 1 0 0 0 0
"20594410" 573 540   -.07655241  33 2005 1 0 0 0 0
"20594410" 574 540   -.00777485  34 2005 1 0 0 0 0
"20594410" 575 540  -.017657291  35 2005 1 0 0 0 0
"20594410" 576 540    .15861143  36 2005 1 0 0 0 0
"20594410" 577 540  -.071740486  37 2005 1 0 0 0 0
"20594410" 578 540    .08804075  38 2005 1 0 0 0 0
"20594410" 579 540   -.06750707  39 2005 1 0 0 0 0
"20594410" 580 540    .05387377  40 2005 1 0 0 0 0
"20594410" 581 540     -.032271  41 2005 1 0 0 0 0
"20594410" 582 540    .06749654  42 2005 1 0 0 0 0
"20594410" 583 540  -.029301774  43 2005 1 0 0 0 0
"20594410" 584 540   -.10717247  44 2005 1 0 0 0 0
"20594410" 585 540    -.2591502  45 2005 1 0 0 0 0
"20594410" 586 540   -.19640385  46 2005 1 0 0 0 0
"20594410" 587 540   -.05022125  47 2005 1 0 0 0 0
"20594410" 588 540   -.18850604  48 2005 1 0 0 0 0
end
format %tm monthly_date
format %tm announcmonth
format %ty year