Announcement

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

  • Creating a dummy variable for groups of categorical values

    Dear all,

    I have a dataset with the results of a survey where answers are labelled as "Very good", "good", "fair", "bad", "very bad". Then, I have % of responses for each answer. I would like to create a dummy variable named "Top" assuming value 0 when answers are very good, good and fair; value 1 when they are either bad or very bad.

    Is there any STATA command to do so, or do I have to rename all the labels on a numerical basis (i.e. 1 for very bad, 2 for bad, etc.?)

    Thank you in advance,
    Best regards,
    RD

  • #2
    Rossella:
    welcome to this forum.
    I would take a look at -help recode-.
    Kind regards,
    Carlo
    (Stata 18.0 SE)

    Comment


    • #3
      Let's suppose that 4 and 5 label bad and very bad.


      Then

      Code:
      gen top = whatever >= 4 if whatever < .
      will map

      values 3 or lower to 0

      4 or higher to 1

      except that any missings go to missing.

      Please note for future questions:

      https://www.statalist.org/forums/help#stata (how to give a data example: show, don't tell)

      https://www.statalist.org/forums/help#spelling (Stata not STATA)

      (If 1 and 2 are your existing values, then change the code accordingly. Not clear why you think you might need to change anything. In Stata rename means to change variable names, not to change value labels.)

      Comment


      • #4
        Originally posted by Carlo Lazzaro View Post
        Rossella:
        welcome to this forum.
        I would take a look at -help recode-.
        Thank you

        Comment


        • #5
          Originally posted by Nick Cox View Post
          Let's suppose that 4 and 5 label bad and very bad.


          Then

          Code:
          gen top = whatever >= 4 if whatever < .
          will map

          values 3 or lower to 0

          4 or higher to 1

          except that any missings go to missing.

          Please note for future questions:

          https://www.statalist.org/forums/help#stata (how to give a data example: show, don't tell)

          https://www.statalist.org/forums/help#spelling (Stata not STATA)

          (If 1 and 2 are your existing values, then change the code accordingly. Not clear why you think you might need to change anything. In Stata rename means to change variable names, not to change value labels.)
          Thank you, and I will look at how to give data example and spelling,

          Best regards
          R.

          Comment

          Working...
          X