Announcement

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

  • Dropping observations

    Hi I am working on a data of transplant patients and some of the patients have multiple transplants and in that case I only want to include those observations whose date is latest.
    Please help I am really stuck!!

  • #2
    In several of your previous posts, you were repeatedly suggested by the forum members to read through the FAQ section and follow the rules for posting specially the use of -dataex- to provide data example. A data example helps people here to quickly reproduce your problem and provide a probable solution. This is for your benefit and you increase the chance of getting a good response.
    Roman

    Comment


    • #3
      If I imagine that your patient records have a patient identifier that is a variable named ID and a transplant date that is a variable named TrDate, and TrDate is a Stata Internal Format date, as you have created using the date() function in your previous posts, then I imagine the following code would retain the observation, for each ID, with the largest value of TrDate.
      Code:
      by ID (TrDate), sort: keep if _n==_N
      With the "by" prefix, the data for each ID will be considered separately, and _n is the observation number within the ID (rather than within the entire dataset) and _N is the number of observations within the ID. So _n==_N for the last observation within each ID.

      Roman's advice is important. Very often a simple description really isn't clear without more detail, or at a minimum it is too difficult to guess at a good answer from what has been shared. When that happens other members will decide not to answer the question, or as Roman did, ask for an improved presentation that could have been provided to begin with.

      Please help us help you. Show example data. If you have run a command that didn't work, show your code and show us what Stata told you. Tell us what precisely is wrong. The Statalist FAQ provides advice on effectively posing your questions, posting data, and sharing Stata output.

      You will find that the time spend preparing and presenting a well-formed question will often pay off in a quicker answer that requires less followup.

      Comment

      Working...
      X