Announcement

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

  • Keeping the first date/observation every 24 weeks

    Hello everyone,

    I have a dataset of thousands of companies and the dates of hundreds of announcements made by each company. Variable "id" identifies a company. Variable "date" represents the announcement date.

    Please see my data below:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long id int date
    1 7550
    1 7578
    1 7704
    1 7900
    1 7921
    1 8145
    1 8320
    1 8600
    1 8663
    1 8677
    1 8726
    1 8901
    1 8985
    1 9104
    1 9209
    2 7396
    2 7403
    2 7592
    2 7732
    2 7851
    2 7928
    2 8040
    2 8187
    2 8194
    2 8299
    2 8362
    2 8565
    2 8628
    2 8726
    2 8740
    end
    format %d date
    I want to keep/identify the first announcement every 24 weeks, for every company.
    For example, in my data above, for the first id, I am interested in keeping/identifying 02sep1980 (7550), 18aug1981(7900), 20apr1982(8145), 12oct1982(8320), 19jul1983(8600), 15may1984(8901), 04dec1984(9104).

    In other words, I want to keep subsequent announcements that are as close to each other as possible, but not any closer than 24 weeks apart.

    I would be very grateful for your help. Please let me know if I should clarify my problem any further.

    Pawel

    (I use Stata/SE 15.1)
    Last edited by Pawel Czarnowski; 26 Apr 2022, 08:58.

  • #2
    Code:
    local 24_weeks = 7*24
    
    by id (date), sort: gen ref_date = date + `24_weeks' if _n == 1
    by id (date): replace ref_date = cond(date > ref_date[_n-1], date + `24_weeks', ref_date[_n-1]) if _n > 1
    by id (date): keep if ref_date != ref_date[_n-1]
    Thank you for using -datatex- on your very first post!

    Comment


    • #3
      Thank you very much, that worked perfectly.

      Comment


      • #4
        panelthin from SSC is I think relevant here. It's also a search term for mentions of this problem on Statalist.

        Comment

        Working...
        X