Announcement

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

  • Finding the earliest date within two boundaries

    I have three date variables corresponding to the beginning of three surveys for different individuals in the %td format (01jan2020 for instance) (so the beginning of survey 1 can vary across observations, etc.).

    To generate the earliest date, I would just go for egen earliest = rowmin(date1 date2 date3), but what if I'm interested in finding the earliest date an individual has been surveyed between, say, February 2020 and November 2020?

    Thanks a lot for the help. I would love to show you some data example but I don't know how to shuffle my dataset because the first observations only have one date available. I'd be grateful if someone helped me figure that little problem out!

  • #2
    Perhaps this untested code will start you in a useful direction.
    Code:
    generate d1int = date1 if inrange(date1,td(1feb2020),td(30nov2020))
    generate d2int = date2 if inrange(date2,td(1feb2020),td(30nov2020))
    generate d3int = date3 if inrange(date3,td(1feb2020),td(30nov2020))
    egen earliest = rowmin(d1int d2int d3int)

    Comment


    • #3
      Dear William:

      The code was exactly what I was looking for. Many thanks!

      Comment

      Working...
      X