Announcement

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

  • define multiple event windows

    Hi,
    I have a problem to define the estimation- & event window based on some tweets (almost 19 tweets) as event. The goal is to calculate CAR for window horizon of [0,5] [0,10] [0,30] [0,60] [0,120] for each events separately. The snap shot of date looks like as follow:


    Click image for larger version

Name:	Unbenannt.png
Views:	1
Size:	115.0 KB
ID:	1725453

    I really appreciate, if someone could help me to write the correct code with Stata,
    thanks in advance!


    0
    how to define the estimation event [-360,-1] minutes and event window [0,120]
    0%
    0
    I followed A Step-by-step Guide from -Princeton University- but different date structure
    0%
    0

  • #2
    I assume that when you refer to interval [0, #] you are counting time in minutes (not days, or hours, or seconds). This is just a guess. If I have guessed wrong, the code shown will need modification.

    On the assumption that the variables eventdate and date are both Stata internal format clock variables, the following code should work:
    Code:
    isid date, sort
    gen last_event_date = cond(missing(eventdate), last_event_date[_n-1], eventdate)
    
    foreach n of numlist 5 10 30 60 120 {
        gen byte window_`n' = ///
            inrange(date, last_event_date, last_event_date + msofminutes(`n'))
    }
    Note: Because example data was provided in an unusable form (it is not possible to import a screenshot into Stata) the code is not tested. It may contain typos or other errors.

    In the future, when showing data examples, please use the -dataex- command to do so. If you are running version 18, 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Comment

    Working...
    X