Announcement

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

  • Creating an indicator variable if one event occured within plus/minus 15 days within another event.

    Dear Statalisters,

    I have perhaps a rather basic question I do not know the answer to. I have a list of events with a particular date (in my case European Council summits) captured in one variable and a list of events with another date (in my case occurrences of politicians' tweets). I would like to create a thirnd varibales( dichotomous), which would capture whether a tweet has occurred with plus/minus 15 days of an European Council summit.

    This is an example from my dataset:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(European_Council Tweet_date Tweet_Summit)
    17776 17794 .
    17820 17829 .
    17843 17939 .
    17877 17585 .
    17957 18067 .
    17975 18074 .
    17992 18085 .
    18066 17947 .
    18157 18137 .
    18199 18167 .
    18220 18174 .
    18241 18209 .
        . 18249 .
        . 18249 .
        . 18308 .
    end
    format %td European_Council
    format %td Tweet_date
    label values Tweet_Summit Yes_No
    Achieving it is basically easy using the following:

    Code:
    replace Tweet_Summit=1 if inrange(Tweet_date, dmy(17,8,2008), dmy(16,9,2008))
    (0 real changes made)
    However, with hundreds of occurrences of one event (European Council summits) this would be time-consuming as one would have to manually calculate plus/minus 15 days for each summit and input it into the command.

    Is there a more elegant solutions?

    Many thanks, and best wishes
    Jan


  • #2
    Code:
    gen `c(obs_t)' obs_no = _n
    gen low = European_Council - 15
    gen high = European_Council + 15
    rangestat (count) wanted = obs_no, interval(Tweet_date low high)
    replace wanted = 0 if missing(wanted)
    replace wanted = min(wanted, 1)
    replace wanted = . if missing(European_Council)
    -rangestat- is written by Robert Picard, Nick Cox, and Roberto Ferrer. It is available from SSC.

    Comment

    Working...
    X