Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Event study graph

    Dear all,

    I have this dataset

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float modate long gvkey float trn byte tic_newind float ff48_after
    432 1043  .011599372 1 1
    433 1043  .006463119 0 1
    434 1043  .015808247 0 1
    381 1056   .03750573 0 0
    382 1056  .064970195 0 0
    383 1056   .04966758 0 0
    384 1056   .06059147 1 1
    385 1056   .04347776 0 1
    386 1056   .04417698 0 1
    405 1056   .10177388 0 0
    406 1056   .05430648 0 0
    407 1056   .08125668 0 0
    408 1056   .18746273 1 1
    409 1056    .1538455 0 1
    410 1056   .10503364 0 1
    417 1056  .018058633 0 0
    418 1056   .03559741 0 0
    419 1056   .03681609 0 0
    420 1056  .030866826 1 1
    421 1056   .04697718 0 1
    422 1056   .04775205 0 1
    441 1056   .04478774 0 0
    442 1056   .03789423 0 0
    443 1056   .04094375 0 0
    444 1056   .06175835 1 1
    445 1056   .04464729 0 1
    446 1056   .04800224 0 1
    513 1056   .17015287 0 0
    514 1056    .2357336 0 0
    515 1056   .14718385 0 0
    516 1056    .1545227 1 1
    517 1056    .1759009 0 1
    518 1056    .1343986 0 1
    528 1082 .0031883584 1 1
    529 1082  .000853499 0 1
    530 1082  .002583388 0 1
    405 1094  .016653419 0 0
    406 1094   .04310413 0 0
    407 1094   .11329491 0 0
    408 1094   .04042383 1 1
    409 1094   .05237905 0 1
    410 1094   .08144742 0 1
    393 1098   .04450803 0 0
    394 1098   .07997139 0 0
    395 1098   .03759339 0 0
    396 1098   .03249086 1 1
    397 1098   .04728978 0 1
    398 1098   .04178986 0 1
    405 1098    .0338261 0 0
    406 1098   .05636624 0 0
    407 1098    .0397711 0 0
    408 1098   .07092672 1 1
    409 1098   .03913527 0 1
    410 1098   .05148625 0 1
    393 1109   .04508612 0 0
    394 1109   .03779129 0 0
    395 1109   .09138805 0 0
    396 1109   .09223603 1 1
    397 1109   .13809524 0 1
    398 1109    .2015528 0 1
    429 1109       .2722 0 0
    430 1109   .08326667 0 0
    431 1109       .0976 0 0
    432 1109    .4278667 1 1
    433 1109        .208 0 1
    434 1109   .09806667 0 1
    417 1117   .04343989 0 0
    418 1117    .0807021 0 0
    419 1117   .04842126 0 0
    420 1117   .05420671 1 1
    421 1117   .04526378 0 1
    422 1117  .067621104 0 1
    369 1173  .016996872 0 0
    370 1173  .018456725 0 0
    371 1173   .07711157 0 0
    372 1173  .027554745 1 1
    373 1173   .08824296 0 1
    374 1173   .03563608 0 1
    381 1173   .09265567 0 0
    382 1173   .07543907 0 0
    383 1173   .03996807 0 0
    384 1173  .028318584 1 1
    385 1173   .03065165 0 1
    386 1173   .02392062 0 1
    477 1228   .08233494 0 0
    478 1228    .7436393 0 0
    479 1228   .16652174 0 0
    480 1228   .10687242 1 1
    481 1228    .2338371 0 1
    482 1228    .3952275 0 1
    561 1228   .05730356 0 0
    562 1228   .15050155 0 0
    563 1228   .07313765 0 0
    564 1228    .2091151 1 1
    565 1228   .13381559 0 1
    566 1228   .17893605 0 1
    453 1239   .04146822 0 0
    454 1239  .024712674 0 0
    455 1239  .027694177 0 0
    456 1239  .035309017 1 1
    end
    format %tm modate
    The variables are these:
    modate = tells me month and year
    gvkey = firm identifier
    trn = firm turnover
    tic_newind= indicator 1 in the month where the firms join a new group
    tic_after= indicator equals to 1 the 3 months where the firm joins a new group. 0 the three mon ths before the shift in a new group.

    Basically I want to create an event sutdy graph such as
    yaxis= average turnover
    x axis= -3 month -2 month -1 month +1 month(this is the event study) +2 month +3 month

    Since I have to work with average, I would like to have the average for each period (months before and after) and then plotting the graph. So I created these variables

    Code:
    egen trn_3before= mean(trn) if f3.tic_newind=1
    egen trn_2before= mean(trn) if f2.tic_newind=1
    egen trn_1before= mean(trn) if f1.tic_newind=1
    
    egen trn_1after= mean(trn) if tic_newind=1
    egen trn_2after= mean(trn) if l.tic_newind=1
    egen trn_3after= mean(trn) if l2.tic_newind=1
    Now I should plot for the event study with a line graph (this part is a bit puzzling).

    I hope to have not created confusion
    Last edited by Marco Errico; 07 Nov 2020, 03:53.

  • #2
    Hi Marco,

    I will attempt some helpful comments. However, I dont have access to Stata and so I cannot load your data. My comments will be somehow general/generic.

    I believe you do not need to construct the new variables since the plot will show the average trend. In addition, the time of the event should not be +1 it should be 0.

    I believe you have panel data?


    Code:
    by gvkey = generate month = _n
    gen treatment = month if tic_newind ==1
    gen event_time = month-treatment
    
    gr two    (connect trn event_time if treatment==1, lcolor(red) lpattern(solid) msymbol(o) mcolor(*choose color)) ///
            (connect trn event_time if treatment==2, lcolor(blue) lpattern(solid) msymbol(o) mcolor(*choose color)) ///
            (connect trn event_time if treatment==3, lcolor(green) lpattern(solid) msymbol(o) mcolor(*choose color)) ///
            (connect trn event_time if treatment==4, lcolor(orange) lpattern(solid) msymbol(o) mcolor(*choose color)) ///
            (connect trn event_time if treatment==5, lcolor(brown) lpattern(solid) msymbol(o) mcolor(*choose color)) ///
            (connect trn event_time if treatment==6, lcolor(cranberry ) lpattern(solid) msymbol(o) mcolor(*choose color )) ///
            (connect trn event_time if treatment==Nth, lcolor(black) lpattern(solid) msymbol(o) mcolor(*choose color)) ///
            , legend( cols(4) lab(1 "1") lab(2 "2") lab(3 "3")  lab(4 "4") lab(5 "5") lab(6 "6") lab(7 "nth") )    
      
    note = Nth is meant as the last month that a firm is "treated". (see that with fre treatment).

    Comment


    • #3
      Dear Mads Moring thanks for your helpful comment.

      I was trying to run your codes but Stata gives me a message "nth not found".
      You say that nth is last month that a firm is treated. Nevertheless, I'm confused on what I have to write.

      Regarding the new variables, thanks. Actually I didn't understand if Stata will take the overall average of the 3 months before/after or I had to calculate the average for t-3 t-2 t-1 and so forth.

      Would you be so kind to help with that nth? thanks again

      Comment


      • #4
        you have to write the actual number and not "nth". Se my note in the code. Make a table of treatment and see which is the highest value.

        Comment


        • #5
          Sorry Mads Moring but I'm confused, I copy and paste a dataex when tic_newind==1

          dataex gvkey trn month1 tic_newind treatment event_time if tic_newind
          > ==1

          ----------------------- copy starting from the next line -----------------------
          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input long gvkey float(trn month1) byte tic_newind float(treatment event_time)
          1043   .011599372  25 1  25 0
          1056    .06059147  13 1  13 0
          1056    .18746273  37 1  37 0
          1056   .030866826  49 1  49 0
          1056    .06175835  73 1  73 0
          1056     .1545227 145 1 145 0
          1082  .0031883584  73 1  73 0
          1094    .04042383  37 1  37 0
          1098    .03249086  37 1  37 0
          1098    .07092672  49 1  49 0
          1109    .09223603  37 1  37 0
          1109     .4278667  73 1  73 0
          1117    .05420671  49 1  49 0
          1173   .027554745  13 1  13 0
          1173   .028318584  25 1  25 0
          1228    .10687242  71 1  71 0
          1228     .2091151 155 1 155 0
          1239   .035309017  97 1  97 0
          1239    .22295634 205 1 205 0
          1281    .13798238  25 1  25 0
          1283  .0023057216 121 1 121 0
          1300   .020137487  49 1  49 0
          1300    .04466645  73 1  73 0
          1300     .1070908 253 1 253 0
          1308     .4705275  13 1  13 0
          1331     .1557803  13 1  13 0
          1360   .024246646  13 1  13 0
          1372    .04496939  85 1  85 0
          1408    .12295192 157 1 157 0
          1441   .018205034  37 1  37 0
          1444   .032999773  25 1  25 0
          1542   .007756563  13 1  13 0
          1542     .0504231 109 1 109 0
          1546    .27739838  25 1  25 0
          1546    .07466027  49 1  49 0
          1559    .03612177 109 1 109 0
          1559   .036446784 145 1 145 0
          1598   .031562924  25 1  25 0
          1598     .1156886 157 1 157 0
          1606   .023407644 133 1 133 0
          1613     .0162038  73 1  73 0
          1618    .02102221  25 1  25 0
          1633    .13154228 289 1 289 0
          1640 .00042514424  13 1  13 0
          1641  .0045501553  25 1  25 0
          1651    .07133832  13 1  13 0
          1690    .26013705 265 1 265 0
          1706    .04575924  97 1  97 0
          1706    .10890781 109 1 109 0
          1706    .16576947 121 1 121 0
          1706    .09649502 133 1 133 0
          1706    .22637206 205 1 205 0
          1706    .14280072 277 1 277 0
          1721    .03082408  37 1  37 0
          1754   .008577236  25 1  25 0
          1780    .04856109  49 1  49 0
          1780    .02212678  73 1  73 0
          1781   .028860955  13 1  13 0
          1794    .05464865  97 1  97 0
          1794    .27472204 253 1 253 0
          1820   .031621676  97 1  97 0
          1820    .03747324 205 1 205 0
          1823            .  73 1  73 0
          1823     .1611958  85 1  85 0
          1823   .025909614 109 1 109 0
          1864    .05884492 133 1 133 0
          1865    .04112516  25 1  25 0
          1884   .031088173 109 1 109 0
          1926    .01751307  13 1  13 0
          1940      .138422  49 1  49 0
          1953    .02393301  13 1  13 0
          1953            .  25 1  25 0
          1971     .0276391  37 1  37 0
          1976      .423163 181 1 181 0
          1979     .0219027 145 1 145 0
          2028   .002762766  49 1  49 0
          2033     .0273437  13 1  13 0
          2033   .033542395  97 1  97 0
          2033    .07537819 109 1 109 0
          2033    .03733222 169 1 169 0
          2033    .08068908 181 1 181 0
          2049   .009778775  37 1  37 0
          2049    .13035347 193 1 193 0
          2049    .13533954 217 1 217 0
          2054    .05837306  25 1  25 0
          2054    .07430983  61 1  61 0
          2054    .09072028  97 1  97 0
          2058    .12486508  37 1  37 0
          2058    .08583364  49 1  49 0
          2058    .05375814  61 1  61 0
          2060   .010954873  13 1  13 0
          2070  .0025608195  85 1  85 0
          2085            .  61 1  61 0
          2085            .  73 1  73 0
          2085            .  97 1  97 0
          2086    .09557037 205 1 205 0
          2100  .0020107238  37 1  37 0
          2127    .05865669  13 1  13 0
          2130    .02256015  25 1  25 0
          2138   .035010707  97 1  97 0
          end
          how can I replace in your codes the last month that a firm is treated since it is contingent with the firm? some firm can be trated the 1st month, other the 10th.
          Sorry if I don't fully get your explanation

          Comment

          Working...
          X