Announcement

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

  • Creating a new variable assigning dates from other vars

    I have a database of doctor visits. Each case is a visit and the variable "id" allows identification of repeat attendees. I have created a new variable "dup" which numbers the visits of each person in chronological order. (second visit of id=abc123 has value dup=2)

    I want to create a new variable (datenext) which shows the date of the person's next visit, based on the variable date of visit (datevisit). For those with dup=0 (unique attendees) datenext will be missing. I want the variable to show date of the visit of the person with the same id but with the value of dup = dup+1. For cases showing the last visit, datenext will be missing.

    Many thanks

  • #2
    Numbering 1, 2, 3, .... will be as or more convenient than 0, 2, 3, ... but either way

    Code:
    bysort id (dup) : gen datenext = datevisit[_n+1]

    Comment


    • #3
      Great thank you that works.

      I have 0= unique visit 1= first visit (if repeat) etc.

      Comment

      Working...
      X