Announcement

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

  • Reverse Command

    I am trying to reverse the order of some categorical variables in my dataset. There was previously a command "revrs" that would do this automatically. However, this command appears to be unrecognized by the current version of STATA, STATABE. Does anyone know of a new command or a similar action to take? The data is coded 1-5, however, some of my variables are coded least to greatest while others are greatest to least, all with the same values coded just opposite orders. I know I could manually recode each variable, but I am looking for a quicker more efficient way to do so.

  • #2
    Code:
    help recode

    Comment


    • #3
      for multiple variables:

      Code:
      foreach var in x1 x2 x3 x4 {
          recode `var' (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1)
      }

      Comment


      • #4
        revrs is a community-contributed command from SSC; you need to install it before you can use it. Make sure to read the help file carefully; the command does not reverse the values but only their order and might mess up the value labels. There are alternatives, which also have pitfalls.

        Comment


        • #5
          Although it is often overlooked, recode allows a variable list; no loop is needed.

          Code:
          recode x1 x2 x3 x4 (1 = 5) ... (5 = 1)

          Comment


          • #6
            What Daniel said...

            Comment

            Working...
            X