Announcement

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

  • recode to exclude missings without specifying an upper limit?

    Dear Statalisters -

    I am looking to recode a numeric variable where the highest category does not specify an upper value but instead indicates that the category should include all values above X but exclude missings (or less than missing). Is there an easy way to do this within the recode statement?

    Thank you,
    Alison

  • #2
    Hmm. Suppose 42 means "42 and above". What would you recode it to?

    Comment


    • #3
      For example, my code is as follows for recoding age into age categories:
      recode age (0/17=1 "1:Age 0-17") (18/44=2 "2:Age 18-44" ) (45/100=3 "3:Age 45+"), gen(age_gr) label(age_gr)
      Where I would prefer not to specify an upper age limit for the final category 45+ as I have been surprised by a few exceptions (101, 102 . . . ).
      There is of course a component of biological plausibility within this example, but it has come up for me in the past with other variables.

      Comment


      • #4
        You can use min and max, max meaning the highest nonmissing value:
        Code:
        recode age (min/17=1 "1:Age 0-17") (18/44=2 "2:Age 18-44" ) (45/max=3 "3:Age 45+"), gen(age_gr) label(age_gr)

        Comment


        • #5
          Thank you, Svend! I was not aware of min/max usage.

          Comment

          Working...
          X