Announcement

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

  • Combining some values of a single variable into one value in a different variable

    I have a variable, called X, w/ 9 values. I need to recode the values. I created a new variable, Y. I used replace Y = 1 if X == 4, etc. to generate the new values I want. Now I want to take the values 6, 7, 8, 9 in X and code them as 9 in Y. How do I do that? If i code replace Y = 9 if X == 6, and then say replace Y = 9 if X == 7, that doesn't add the number of observations coded as 7 to the number of observations coded as 6. It simply replaces the # of observations coded 6 w/ the # of observations coded 7. How can I sum 6, 7, 8, and 9 in X to the value 9 in Y?
    Last edited by Jerome Anderson; 07 Apr 2024, 10:10.

  • #2
    This is from

    Code:
    help recode

    For x2, collapse 1 and 2 into 1, change 3 to 2, change 4 through 7 to 3, and store the results in nx2
    . recode x2 (1 2 = 1) (3 = 2) (4/7 = 3), gen(nx2)

    Comment


    • #3
      Many thanks, Andrew. This worked.

      I appreciate your response.

      Comment

      Working...
      X