Announcement

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

  • Ordering dates

    Hello all,

    My sample data is shown below:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(group date1 date2) byte ID
    1 16071 16454 1
    1 16305 16620 2
    1 16455 16620 2
    1 16455 16620 2
    1 16455 16620 2
    1 16742 16818 1
    1 16742 16860 2
    1 16742 16860 3
    1 16742 17044 2
    1 16819 17166 2
    1 16819 17166 2
    1 16819 17166 2
    1 16966 17166 2
    1 16966 17166 2
    1 17167 17911 2
    end
    format %td date1
    format %td date2
    I have variables for group, date1, date2, and ID. We can think of date1 as a start date and date2 as an end date. I want to order the dates based on the previous end date. For example, the first observation has 01jan2004 as date1 and 18jan2005 as date2. The next observation should be 19jan2005 (date1) and 03jul2005 (date2). There is a catch, however. I only want to continue this sequence if ID==1. If ID==2 or ID==3, the sequence ends and restarts based on a new ordering of dates.

    I would appreciate any assistance!

    Thanks,
    Anoush K.

  • #2
    sorry, but what you say makes no sense to me; you say, "the first observation has 01jan2004 as date1 and 18jan2005 as date2. The next observation should be 19jan2005 (date1) and 03jul2005 (date2)." - but those have different id's and you also say you "want to continue this sequence" [by id) - please clarify

    Comment


    • #3
      Rich, thank you for your response.

      It is OK for dates within the sequence to have different ID’s. When the sequence hits ID=2 or ID=3, that particular sequence stops and a new sequence begins. Does that clarify it a bit more? The more important aspect here is that the dates follow a sequence based on the previous date2 value.

      Comment

      Working...
      X