Announcement

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

  • Recode if date is not missing

    I have a problem that help recode doesnt solve.

    I have a IHD variable that is coded 0 or 1. In another column I have date of myocardial infarction. If a date is there, an event happened. If it's just a dot, no event happened. I want to recode from 0=1 if there is a date/or not a dot. Is there a simple solution?

  • #2
    your question is not completely clear - do you want to change just to "1" (if there is a date) or do you also want to change to 0 if date is missing; here is the first:
    Code:
    replace IHD=1 if missing(date)
    change "date" to whatever the actual name of your date variable is

    in the future, please show example data using -dataex- and showing the result in CODE blocks (see the FAQ)

    Comment


    • #3
      Thanks for swift reply. It would have been easier with a picture. I try to make it easier:


      MIDATE IHD
      . 0
      . 0
      06feb2000 1
      . 0
      . 0
      . 0
      04jun1999 0

      I want to record every row that has a date =1. Information about previous MI has several origin and not all make the current coding IHD=1, so I have to manually change those.

      replace IHD=1 if nonmissing (MIDATE) is in theory what I need.

      I recoded everyone to 1 if 0 now. Then used your code mentioned above. Seems to work.

      The problem is that I have 3 columns. MI-date, STEMI-date, NSTEMI-date. The two latter doesnt have a 1 if MI-date is 0 fortunately so maybe this solved my problem. I need to double check in the larger dataset (using a smaller training set on 9K individuals now).

      Comment


      • #4
        sorry, but this increases my level of confusion; maybe someone else can help but my suggestion about following the advice in the FAQ remains

        Comment


        • #5
          Originally posted by Rich Goldstein View Post
          sorry, but this increases my level of confusion; maybe someone else can help but my suggestion about following the advice in the FAQ remains
          Ah i see now why. It didnt look like that when I wrote...

          MI-Date IHD
          .
          .
          04jun1999 1
          .
          .
          .
          .
          06feb2000 0
          .

          I want IHD==1 if there is a date and not a "." in column "MI-Date".

          Comment

          Working...
          X