Announcement

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

  • Regressions for several events in a year

    Hi
    I have a daily dataset with no weekends and a few excluded dates. Every year there are about 8 events. I have a variable, labelled "loop", coded as 0 on the event day and it takes values such as -1,-2, etc. for days before the event and 1,2, etc. for days after the event. The loop variable should go from -6 to 33 around the event date however as the event dates change sometimes, it can takes values less than that. For example, loop can be from -1 to 10 around an event as the next event date is closer than usual.

    I want to estimate a regression of variable Y on X and get the coefficient and t statistics/or significance intervals for a window that starts two days before any day on the loop variable and ends two days after. Therefore, there should be only 40 regressions, one for each day pertaining to the loop variable using the 5-day window as described.

    Therefore, another way to think about it is that I have 40 events "assuming that each day of the loop is an event" and want to estimate regressions for each of those "events" using a 5 day window from 2 days before to 2 days after the event.

    I hope someone can help with that.

    Here is the data

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(date loop Y X)
    12421  9    .40833064556100585                    .
    12422 10    1.7504380481915494                    .
    12423 11    1.3442199171612046   1.1142340930694614
    12424 12     1.172214576405528    .8366815842332993
    12425 13    1.0709235971502196   -.5698582708671603
    12428 14     1.060860025764998   .44619780930879466
    12429 15    -.0717033848796067     .603466848487165
    12430 16     .1886515469692096   .20029839951941084
    12431 17    .06841567317243946   .26156506181061856
    12432 18    .44950582513105797    .7234289144089658
    12435 19    -.0706365931515518    .9296635336682627
    12436 20    -.2911380165270039    2.456222851925734
    12437 21    -.6499041454174792    5.694674390555773
    12438 22   -.16246315062454775    .9643535617024777
    12439 23    .40569156604426393   1.5043988731429845
    12442 24     .8780598716288113   1.3668928340199311
    12443 25     1.932645839372804  -.26166523791799196
    12444 26    1.9121746000000828   1.3423224530024678
    12445 -6    1.9324681898750695    .3301592082916583
    12446 -5     .9306850585091286     3.31895119973687
    12449 -4   -1.8244805771757688     .767298012854508
    12450 -3   -2.0588482667276753   -2.121362539935701
    12451 -2   -1.7345886658457155    2.127378792039226
    12452 -1   -1.7247998017700272   -4.534862103767482
    12453  0     -2.17802071078379  .059393679617856535
    12456  1    .17645332480213938  -.19192401922494884
    12457  2    -.0433065317360537   -6.300753755400369
    12458  3     .3764865559312769  -1.5337402402938907
    12459  4 -.0034396706450223746    3.067362100583561
    12460  5    .20806243874404995   2.1066805077527038
    12463  6   -.30306966582031025   -.7991202944618075
    12464  7   -.41261880445961907   1.6796374960179323
    12465  8    -.2539716791640778 -.007249956236526354
    12466  9   -.45341014827258164  -5.4905658996127205
    12467 10   -1.2437243680603505    .9070158491607397
    12470 11    -.4098913112849045                    .
    12471 12   -.03132676347357144   -.3136421468738003
    12472 13   -1.1742794106360144    .2844228420773084
    12473 14   -1.1643888153161752   1.9248449336488016
    12474 15   -.15304185513137503   1.9817014126865398
    12477 16  -.053511280049090004     .692597550533921
    12478 17     .1257932143570839   1.3725805193035667
    12479 18     .4178155063435218    .4920659310490232
    12480 19     .7095454460085415    2.944231776068673
    12481 20      .325746045762787    1.719804856260731
    12484 21     .3057632019275447   .39698489334907644
    12485 22   .036316824911430956    3.968928189570995
    12486 23     .2971358751473252    .4925379424625736
    12487 24     .6978752105955888  -.14209078275306575
    12488 25    1.6305182817657693    5.119749079875876
    12491 -6    1.2357097420706786    .7321162417174153
    12492 -5     .4378829665795614    .1867299344584854
    12493 -4     .4479285369523023    9.393819782584274
    12494 -3   -.08173389457420965   -1.229264138215256
    12495 -2   -1.3574756017802336    -1.93509210792755
    12498 -1    -2.018372860879014    .5931807835466785
    12499  0   -1.9888161304031704   1.5030996988125025
    12500  1   -3.7923882734641756    .6710868287031964
    12501  2    -5.293532732221129    5.283346988344717
    12502  3    -4.480144012470322   -.8536996551767804
    12505  4   -3.8834577775936796   -.3057341132681399
    12506  5    -4.955864221877693    .9954846980862985
    12507  6    -.9183101626907386    1.841555638313738
    12508  7     .6520254681110282    .6081061830106048
    12509  8     1.388063719674748                    .
    12512  9     .5665610347746153   -.5417515075925026
    12513 10    2.5192996692225744   1.1784468927139873
    12514 11   -.39653590939376926                    .
    12515 12   -1.0341656615456496    .2167469963580361
    12516 13   -1.5853819996759833   .23099803515373485
    12519 14    -.7514731274653075    .6531313020333248
    12520 15   -1.8897208455712633    .9140979853089712
    12521 16   -1.6133623327793112   .31024002158664055
    12522 17   -1.4251730488087144    1.675301430510085
    12523 18  -.015313038351183472    1.146840336801559
    12526 19   -.09532159991209044    .9510022512827321
    12527 20    1.7390025491301975    .9399939408462611
    12528 21     2.055388819049453    .4118700220858298
    12529 22    2.4857160622088204   .08062457545650156
    12530 23     .4446623561720875    .5634462619069002
    12533 24     .9674540661588571    .9292694385370084
    12534 25    .46740688576560885    .6030849705715844
    12535 26    .40713498167053164                    .
    12536 27      .256498324538601   1.1292072530338413
    12537 28     .7104222740167865  .009673898215755353
    12540 29     -.673701520292902    .7738292332602551
    12541 30    -2.394422800262941    .9373607037318985
    12542 31   -1.8083685306032438  -.38058296688195253
    12543 32   -2.7038038574019874   1.7051886646059087
    12544 33   -2.2360243985528605   1.9587793600933983
    12547 -6   -1.2981600052189846    .3334241972883007
    12548 -5   -.21813962757157856    2.033909753895595
    12549 -4 .00022444076535066415  -.18217615344710394
    12550 -3    2.2150168663573444    1.061018322106444
    12551 -2     2.449358327653983    .4690801513532031
    12554 -1    2.1624478684972637    .7107077496520608
    12555  0    1.9883917704687226    .4333344114082396
    12556  1    1.5733558221847854   1.1688861491174312
    12557  2     .7090757906687895   2.1718633790100044
    12558  3     .3284749621768279   2.2110628210759873
    end
    format %td date

  • #2
    Hi

    The best I have done now is below. However, I am not sure if will do exactly what I described?! Also, it does not give me a variable that contains the slope coefficients and t stats.

    I hope now that one can help

    Code:
    gen tt=_n
    tsset tt
    
    * Identify unique event days
    levelsof loop, local(event_days)
    
    * Initialize lists to store coefficients and t-statistics
    local coefficients ""
    *local t_statistics ""
    
    * Loop over each event day
    
    foreach tt in `event_days' {
    
     reg Y X   if loop >= `tt' - 1 & loop <= `tt' + 2,  r
        local coef = _b[X]
        *local t_stat = r(t_stat)[X]
    
        local coefficients "`coefficients' `coef'"
        *local t_statistics "`t_statistics' `t_stat'"
    }
    
    * Display coefficients and t-statistics
    di "Coefficients: `coefficients'"
    *di "T-Statistics: `t_statistics'"

    Comment

    Working...
    X