Announcement

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

  • Event study moving average outside event window

    The following panel data provides information about the firm event PERMCO_ED which is unique. DATE is the relative time period and Adjvol. I want to calculate the average 100 days of Adjvol but the moving average should be outside of the event window (-40 days to +20 days).

    For example:
    For the Date +20, the 100 average should be calculated from the day -140 to -40
    For the Date 0, the 100 average should be calculated from the day -160 to -60
    For the Date -20, the 100 average should be calculated from the day -180 to -80

    I am not sure how to apply the rangestat in this situation.

    Thank you

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float PERMCO_ED int DATE long Adjvol
    1 -200 268970737
    1 -199 254621017
    1 -198 284856495
    1 -197 238195664
    1 -196 139782594
    1 -195 106324701
    1 -194 132858383
    1 -193 158869284
    1 -192 115975783
    1 -191 101560004
    1 -190 139035414
    1 -189 119769111
    1 -188 129587584
    1 -187 124977699
    1 -186  86608032
    1 -185 103595982
    1 -184  92348088
    1 -183 124278567
    1 -182 146062476
    1 -181 187834983
    1 -180 190051918
    1 -179 165848802
    1 -178 181743877
    1 -177 152931821
    1 -176 129566486
    1 -175  85532237
    1 -174  99752072
    1 -173 137928294
    1 -172 128116352
    1 -171 135581950
    1 -170 145686415
    1 -169 101156153
    1 -168 104770806
    1 -167  99302035
    1 -166  90747034
    1 -165 154006398
    1 -164 113511286
    1 -163  76716304
    1 -162  90346424
    1 -161  87052763
    1 -160 114742670
    1 -159  94312393
    1 -158  93371145
    1 -157  84837879
    1 -156  73672032
    1 -155  79691752
    1 -154  72547307
    1 -153  53363555
    1 -152  73715229
    1 -151 110262369
    1 -150 104357120
    1 -149  63897407
    1 -148 126637518
    1 -147 109830441
    1 -146  98698628
    1 -145 134522381
    1 -144 122870111
    1 -143 111570277
    1 -142  81682076
    1 -141  78693671
    1 -140  77005922
    1 -139  65855461
    1 -138 113615243
    1 -137 103336667
    1 -136 129038049
    1 -135 153578320
    1 -134 229035331
    1 -133 106493205
    1 -132 105266714
    1 -131  98850577
    1 -130 120396101
    1 -129 101132766
    1 -128  87143602
    1 -127  90676250
    1 -126  79556939
    1 -125  76511890
    1 -124  63672812
    1 -123  57511265
    1 -122  51085202
    1 -121  73211411
    1 -120  89419785
    1 -119  66868956
    1 -118  67037481
    1 -117 115667860
    1 -116 160322134
    1 -115 214307079
    1 -114 148507415
    1 -113 110373935
    1 -112 114586353
    1 -111 112624589
    1 -110  70190813
    1 -109  54425413
    1 -108  79182467
    1 -107  89481931
    1 -106  96674424
    1 -105  87775030
    1 -104 102493412
    1 -103  86692907
    1 -102 128618490
    1 -101 131831749
    1 -100 186071333
    1  -99 156476292
    1  -98 157295894
    1  -97 104198941
    1  -96  97781495
    1  -95  85217993
    1  -94  87568866
    1  -93 147432418
    1  -92 168954856
    1  -91 136149356
    1  -90 150434312
    1  -89 155247134
    1  -88 140318675
    1  -87 142514785
    1  -86 164344439
    1  -85 110497807
    1  -84  96396678
    1  -83 155338225
    1  -82 168217532
    1  -81 220306149
    1  -80 133934171
    1  -79 143254783
    1  -78 120344875
    1  -77 113049986
    1  -76 141895502
    1  -75 100977604
    1  -74 124536293
    1  -73 195004446
    1  -72 143557666
    1  -71 185221575
    1  -70 145922714
    1  -69 172709726
    1  -68 265627642
    1  -67 134346408
    1  -66  91638505
    1  -65 151876788
    1  -64 133739529
    1  -63  94018211
    1  -62 200381342
    1  -61 265890177
    1  -60 233507722
    1  -59 130170775
    1  -58 133061642
    1  -57 120379231
    1  -56 196606746
    1  -55 317112705
    1  -54 204888614
    1  -53 159143229
    1  -52  92824662
    1  -51  66807601
    1  -50 157119123
    1  -49 133654129
    1  -48 130570706
    1  -47 128593787
    1  -46  98735329
    1  -45  91647234
    1  -44 159217800
    1  -43 259259406
    1  -42 292751060
    1  -41 195241515
    1  -40 157637774
    1  -39 148860061
    1  -38 126722820
    1  -37 162854160
    1  -36 262598931
    1  -35 198768892
    1  -34 163460388
    1  -33 117769484
    1  -32 129413130
    1  -31 155147811
    1  -30  45768856
    1  -29  79048368
    1  -28 119403410
    1  -27  92875783
    1  -26 172342107
    1  -25 147260365
    1  -24  93079714
    1  -23 154612668
    1  -22 126121317
    1  -21 118417425
    1  -20 106106182
    1  -19 155383235
    1  -18  90568618
    1  -17 191143393
    1  -16 228637486
    1  -15 179287934
    1  -14 118378036
    1  -13 122366874
    1  -12 120434104
    1  -11 225132299
    1  -10 372658713
    1   -9 312097086
    1   -8 203482839
    1   -7 148243494
    1   -6 108580234
    1   -5  82828123
    1   -4 140175245
    1   -3 124764325
    1   -2 148266349
    1   -1 154359758
    1    0 182723765
    1    1 165041828
    1    2 134330805
    1    3 158631340
    1    4 123511297
    1    5  92139404
    1    6 102209030
    1    7 112584521
    1    8 123600799
    1    9 116841053
    1   10  86196761
    1   11  97424292
    1   12 131801614
    1   13 153373829
    1   14  83967086
    1   15 144812829
    1   16 152943917
    1   17 166884431
    1   18 119693133
    1   19 121617398
    1   20 102627742
    1   21 123490010
    1   22 121616425
    1   23 105351057
    1   24  79428531
    1   25 166699778
    1   26 156891679
    1   27 138683853
    1   28  79814847
    1   29 100521904
    1   30 102594947
    2 -200 185221575
    2 -199 145922714
    2 -198 172709726
    2 -197 265627642
    2 -196 134346408
    2 -195  91638505
    2 -194 151876788
    2 -193 133739529
    2 -192  94018211
    2 -191 200381342
    2 -190 265890177
    2 -189 233507722
    2 -188 130170775
    2 -187 133061642
    2 -186 120379231
    2 -185 196606746
    2 -184 317112705
    2 -183 204888614
    2 -182 159143229
    2 -181  92824662
    2 -180  66807601
    2 -179 157119123
    2 -178 133654129
    2 -177 130570706
    2 -176 128593787
    2 -175  98735329
    2 -174  91647234
    2 -173 159217800
    2 -172 259259406
    2 -171 292751060
    2 -170 195241515
    2 -169 157637774
    2 -168 148860061
    2 -167 126722820
    2 -166 162854160
    2 -165 262598931
    2 -164 198768892
    2 -163 163460388
    2 -162 117769484
    2 -161 129413130
    2 -160 155147811
    2 -159  45768856
    2 -158  79048368
    2 -157 119403410
    2 -156  92875783
    2 -155 172342107
    2 -154 147260365
    2 -153  93079714
    2 -152 154612668
    2 -151 126121317
    2 -150 118417425
    2 -149 106106182
    2 -148 155383235
    2 -147  90568618
    2 -146 191143393
    2 -145 228637486
    2 -144 179287934
    2 -143 118378036
    2 -142 122366874
    2 -141 120434104
    2 -140 225132299
    2 -139 372658713
    2 -138 312097086
    2 -137 203482839
    2 -136 148243494
    2 -135 108580234
    2 -134  82828123
    2 -133 140175245
    2 -132 124764325
    2 -131 148266349
    2 -130 154359758
    2 -129 182723765
    2 -128 165041828
    2 -127 134330805
    2 -126 158631340
    2 -125 123511297
    2 -124  92139404
    2 -123 102209030
    2 -122 112584521
    2 -121 123600799
    2 -120 116841053
    2 -119  86196761
    2 -118  97424292
    2 -117 131801614
    2 -116 153373829
    2 -115  83967086
    2 -114 144812829
    2 -113 152943917
    2 -112 166884431
    2 -111 119693133
    2 -110 121617398
    2 -109 102627742
    2 -108 123490010
    2 -107 121616425
    2 -106 105351057
    2 -105  79428531
    2 -104 166699778
    2 -103 156891679
    2 -102 138683853
    2 -101  79814847
    2 -100 100521904
    2  -99 102594947
    2  -98 130594912
    2  -97  76568940
    2  -96  86567152
    2  -95 115373244
    2  -94 102612349
    2  -93 138609898
    2  -92  96040917
    2  -91  94438981
    2  -90 102040932
    2  -89  78757581
    2  -88  80511137
    2  -87  99401309
    2  -86  86315215
    2  -85  62608343
    2  -84  84204337
    2  -83  80524374
    2  -82 248391451
    2  -81 176196384
    2  -80 159378947
    2  -79 113676913
    2  -78 176988567
    2  -77 251463849
    2  -76 100118767
    2  -75 195723178
    2  -74 165057900
    2  -73 179147129
    2  -72 131677693
    2  -71 109591587
    2  -70  93441887
    2  -69 128549099
    2  -68 124950490
    2  -67 122652334
    2  -66 103098989
    2  -65  87319855
    2  -64  81317502
    2  -63 116005400
    2  -62 192352860
    2  -61 156743580
    2  -60 111046600
    2  -59 117482624
    2  -58 118334552
    2  -57 115745518
    2  -56  92189531
    2  -55  72554615
    2  -54 100596370
    2  -53  86563295
    2  -52  92151584
    end

  • #2
    rangestat is from SSC as you are asked to explain (FAQ Advice #12).

    I don't know what you tried, as you don't show us, but your problem sounds like

    Code:
    rangestat AdjVol, int(DATE -160 -60) by(PERMCO_ID)
    except that this is an average over 101 dates, not 100. The point is that -160 -60 are offsets, not numeric values to be taken literally.

    Comment


    • #3
      I looked at one of your previous replies to another post of mine and I have come up with a modified version of that specific command. The results seem to be accurate, I had verified the calculation in excel and they seem to be an exact match.

      I employed the following code:


      Code:
      gen low= DATE-160
      gen high= DATE-60
      rangestat (mean) Mean_Adjvol= Adjvol , by( PERMCO_ED ) interval( DATE low high)
      Thank you!




      Last edited by Bilal Hafeez; 07 Jun 2019, 20:18.

      Comment

      Working...
      X