Announcement

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

  • How to keep effective dates, after merging panel datasets?

    Good day Statalists!

    I merged a quarterly dataset with a daily dataset, and did some calculations.

    Now there are two date variables, one is crspdate(Stock trading days, skip Saturdays and Sundays), the other is eadate(Earnings announcement date, mostly one date in every quarter, but could be any date during that quarter, and could be on Saturdays and Sundays).

    The companies are identified by permno, so basically (permno crspdate) is unique, whereas (permno eadate) is not.

    I need to make (permno eadate) unique, which means keep the observations when eadate=crspdate, but the thing is, some eadate is on Saturdays and Sundays that crspdate is not available. In this case, I would like to link the eadate with the next available crspdate, mostly next Monday.

    Anyone can help? Great thank!

    Here is the sample:


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double permno long(crspdate eadate)
    10001 15108 15110
    10001 15109 15110
    10001 15110 15110
    10001 15111 15110
    10001 15112 15110
    10001 15218 15220
    10001 15219 15220
    10001 15222 15220
    10001 15223 15220
    10001 15224 15220
    end
    format %d crspdate
    format %d eadate
    I need to keep

    10001 15110 15110

    and

    10001 15222 15220
    Last edited by Edward Wu; 10 May 2018, 14:52.

  • #2
    This will do it:

    Code:
    by permno eadate, sort: egen next_crspdate = min(cond(crspdate >= eadate, crspdate, .))
    keep if crspdate == next_crspdate

    Comment


    • #3
      It worked! Thanks a lot!

      Comment

      Working...
      X