Announcement

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

  • Likert SCale Conversion

    Hi all,

    I have a bunch of likert variables I want to convert.
    I want to be able to
    foreach var in varlist {
    convert "strongly agree" to 4, "agree" to 3, and so on
    }
    Can you help with this?
    Thanks!

  • #2
    see
    Code:
    h encode
    and pay particular attention to the "label()" option

    Comment


    • #3
      Here is some example code that illustrates Rich's solution.
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input str11(var1 var2)
      "Very Likely" "Likely"     
      "Likely"      "Very Likely"
      "Not Likely"  "Unlikely"   
      "Unlikely"    "Not Likely" 
      end
      
      label define like 4 "Very Likely" 3 "Likely" 2 "Not Likely" 1 "Unlikely" 
      foreach v of varlist var* {
          rename `v' s_`v'
          encode s_`v', generate(`v') label(like) noextend
      }
      list, clean nolabel
      list, clean
      Code:
      . list, clean nolabel
      
                  s_var1        s_var2   var1   var2  
        1.   Very Likely        Likely      4      3  
        2.        Likely   Very Likely      3      4  
        3.    Not Likely      Unlikely      2      1  
        4.      Unlikely    Not Likely      1      2  
      
      . list, clean
      
                  s_var1        s_var2          var1          var2  
        1.   Very Likely        Likely   Very Likely        Likely  
        2.        Likely   Very Likely        Likely   Very Likely  
        3.    Not Likely      Unlikely    Not Likely      Unlikely  
        4.      Unlikely    Not Likely      Unlikely    Not Likely

      Comment


      • #4
        Hmm, sorry I am still confused on doing this. When I encode, it will change the variables differently for some reason. For example, I encode and it changes var1 so that "very likely" is 5 and var2 so that very likey is 4. So this isn't quite working. Can you help?

        Comment


        • #5
          Lindsey, show your code and output so we can evaluate. It may be that your code is flawed or there is some additional complication we don't know about.
          -------------------------------------------
          Richard Williams, Notre Dame Dept of Sociology
          StataNow Version: 19.5 MP (2 processor)

          EMAIL: [email protected]
          WWW: https://www3.nd.edu/~rwilliam

          Comment


          • #6
            I will note that my example code was developed on one of the several earlier attempts - subsequently deleted - to post this question, when you asked
            I would like to do something like this:
            foreach var in varlist _all {
            code to convert "Very likely" to 4 "likely" to 3 "not likely" to 2 and "likely" to 1
            }
            which is why my values don't agree with the values you show in this post. So you must have had to adapt my code to your data, and - as Richard suggests - if you don't show us what you have done, we cannot tell you what is wrong with what you have done.

            Let me add that spelling and capitalization are crucial: if your data has "Very likely" and "very likely" then this needs to be taken care of - my code won't handle it.
            Last edited by William Lisowski; 27 May 2020, 15:29.

            Comment


            • #7
              The “recode” command may solve the problem. For example, if you have: 1: Very likely; 2: Unlikely; 3: Very unlikely; 4: Likely, with
              Code:
              recode (1=3)(4=2)(2=1)(3=0)
              you can build a numeric variable with an order reflecting a hierarchy.
              Thus, supposing you already have loop leading you to generate n numeric variables with the same name (apart from the numeric suffix) in a one-to-one correspondence with string variables through the command “forvalues i=1/n”, such loop may be just supplemented by something like:
              Code:
              recode var`i' (1=3)(4=2)(2=1)(3=0)
              I’ve had however a similar situation with many items, with different string wordings and with multiple recoding schemes necessary. Fortunately, it was always in contexts where I either had a dataset with the legend (for example, in the case of 5-item scales, this would be two variables – one numerical and one string - with 5 observations each) with the values in the desired order (let’s say “the true values”), or another dataset with both the string values and the true values. In both cases, I appended such dataset to the existing one, such that the problem reduced to having some missing values in numeric variables, and the full set of observations for the string variable. The procedure I follow is:
              1. Code:
                encode var1_string , generate(var1_encoded)
              to generate a numeric variable, not necessarily with the numbers I want;

              2.
              Code:
               labmask var1_encoded if var1_Lik!=. , values(var1_Lik)
              to make my numeric variable have, as labels, the “right” numbers;

              3.
              Code:
              decode var1_encoded, generate (var1_Likert)
              to generate the scale with the right number as a string;

              4.
              Code:
              destring var1_Likert, replace force
              to generate the variable with the desired numbers .
              Thus, supposing I have 12 items for a given scale, it could be something like:
              Code:
               forvalues i=1/12 {
              encode var`i’_string , generate(var`i’_encoded)
              labmask var`i’_encoded if var`i’_Lik!=. , values(var`i’_Lik)
              decode var`i’_encoded, generate (var`i’_Likert)
              destring var`i’_Likert, replace force
              }
              Last edited by Federico Tedeschi; 27 Dec 2022, 12:06.

              Comment


              • #8
                I wouldn't choose to loop over variables here at all. First off, it's always a good idea to check for consistent string values before you encode anything at all.

                One tool here is tabm from tab_chi on SSC. WIth @WIlliam Lisowski's toy example, we can go


                Code:
                * Example generated by -dataex-. To install: ssc install dataex
                clear
                input str11(var1 var2)
                "Very Likely" "Likely"     
                "Likely"      "Very Likely"
                "Not Likely"  "Unlikely"   
                "Unlikely"    "Not Likely" 
                end
                
                
                            |       variable
                     values |      var1       var2 |     Total
                ------------+----------------------+----------
                     Likely |         1          1 |         2 
                 Not Likely |         1          1 |         2 
                   Unlikely |         1          1 |         2 
                Very Likely |         1          1 |         2 
                ------------+----------------------+----------
                      Total |         4          4 |         8
                The default alphabetical order here manifestly misses the Likert flavour, but also makes spotting some inconsistencies easier, especially across many more than two such variables.

                Second, multencode from SSC exists as a way of encoding variables consistently without an explicit loop. In this case, the value labels should be defined first. https://www.stata.com/statalist/arch.../msg00729.html

                Comment

                Working...
                X