Announcement

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

  • Help pulling data from previous observations into new observation for same patient id

    I have a data set with organized by patient id and visit number (usually 5 visits per patient). Often, the person collecting the data only typed in the date of birth on visit 1, so now I'd like to ask the best way to give all the other visits the same date of birth as visit 1. I know that I could simply sort by patient id and visit number, and then replace the date of birth value with _n-1 if date of birth is missing. This works assuming everybody has a visit 1, which is not necessarily the case. In the case when there is not a visit 1, then this technique would create false data, by giving a patient the date of birth of the previous patient id. I know there must be a more elegant way of doing this with some kind of loop operation, and would love your help.
    Thanks!
    Clay Bavinger
    University of Michigan

  • #2
    You can use egen's max() function for this. It uses the highest non-missing value within the by-group:
    Code:
    bysort id: egen bdate2 = max(bdate)

    Comment

    Working...
    X