Announcement

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

  • reversing non-integer variables using revv

    Hi everyone,

    I want to reverse a mean scale score, which is a non-integer variable from 1 to 5. I tried using revv, as it says it handles non-integer variables. I tried so by specifying the valid() option, but I did not know how to specify the option to reverse the non-integer variable... For example, I typed revv varlist, valid(1/5) which only reverse coded the integer numbers 1, 2, 3, 4 and 5 but not the non-integer values in-between (e.g. 1.2, 1.3 etc).

    Can anyone help me out with this and knows how to specify the valid() option so that my non-integer variable gets reversed completely?

    Thank you so much!!

  • #2
    Code:
    6 - whatever
    is an ancient spell to flip 1 to 5 to 5 to 1.

    Comment


    • #3
      Hi,

      thank you for answering so quickly! I tried typing revv varlist, valid(6 - whatever) but I get an error message r(121) "valid () invalid -- invalid numlist". I might have not understood how to use your ancient spell correctly? Sorry for that, I am very new to stata

      Many thanks!

      Comment


      • #4
        Sorry, I wasn't meaning that you should use revv with that syntax A main selling point of revv (from SSC, as you are asked to explain: FAQ Advice #12) is to deal with value labels as well as values. and you won't have value labels for non-integers.

        Code:
        gen whatever2 = 6 - whatever
        is the essence and if you have several variables put that in a loop.

        Incidentally, the results of

        Code:
        sysuse auto, clear
        
        revv gear_ratio, gen(new)
        scatter new gear_ratio
        are a guide to what revv does do with non-integer variables and it may not be what you want in your case.

        Comment


        • #5
          Ohhh now I understand! Thank you so much for clarifying, that makes sense!

          Comment


          • #6
            revv (SSC) is outdated; rev (SSC) does the same thing, but neither program is usually useful for reversing non-integer values. In fact, they are dangerous and I would write them differently today than I have written them about 10 years ago. For the series 1.1, 2.2., 3.3, ..., 5.5, rev will interchange the distinct non-integer values. The result is the same as typing:

            Code:
            recode varname (1.1 = 5.5) (2.2. = 4.4) ... (5.5 = 1.1)
            which is rarely what you want.

            Comment


            • #7
              Hi Daniel Klein,

              thank you very much for flagging this!

              Comment


              • #8
                Hello everyone, thank you for your post and replies. I am also very new to STATA and I have a similar challenge. But in my case, my non-integer variable is an index. the minimum is 0.046 and the maximum is 0.805. I want to reverse code this variable, as higher values mean the opposite of the direction I want.

                I used the code: vreverse variable_name, gen(variable_name1) but it returns the error: "non-interger values in variable_name".

                I will appreciate any help.

                thank you in advance
                Last edited by Ijeoma Ugwuanyi; 20 Mar 2022, 07:05.

                Comment


                • #9
                  What is the maximum in principle? The minimum? If 1 and 0, then subtract from 1.

                  Comment


                  • #10
                    Thank you for the swift reply Nick.

                    In principle, the maximum is 1 and the minimum is 0. Higher values signify high inequality, which is not good in my study context.

                    Okay, I will subtract from 1. To be clear, I would use the example you specified as above right? For example using the code: gen variable_name1 = 1 - variable_name

                    Comment


                    • #11
                      Indeed. That is my suggestion.

                      Comment


                      • #12
                        Thank you very much, Nick! it worked. I saw that the higher values became lower values and vice versa. This is what I wanted.

                        Comment

                        Working...
                        X