Announcement

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

  • Recode fraction numbers

    Hi, Stata users!
    I'm recoding a variable on Stata because I want to normalize it and my code is:
    recode A005 (-5 -4 -3 -2 -1=.) (4=0 "Not at all important") (3= 1/3 "Not very important") (2= 2/3 "Rather important") (1=1 "Very important"), gen(Work)
    but when I do this Stata tells me:
    ) expected, "/" found
    r(198);
    Can anyone explain me how I should write the fraction numbers?

  • #2
    It seems possible to recode to fractions using `=...' -- e.g.,
    Code:
    recode x (-5/-1 = .) (4=0) (3=`=1/3') (2=`=2/3') (1=1) , gen(y)
    However, value labels are not allowed for non-integer values.

    Comment


    • #3
      There are two sides to this.

      The syntax of programs like recode does not include any calculations on the fly, which is what you are asking for.

      There is at least one way round this, but it's not a good idea any way.

      Values like 1/3 and 2/3 cannot be held using exact binary representations and so you can easily get into a mess trying to count occurrences, and so forth. For much, much more, see the references under

      Code:
      search precision
      I would map 4 3 2 1 to 0 1 2 3 by subtracting from 4.

      Code:
      gen Work = 4 - A005 if A005 >= 0
      The term "normalise" is one of the most treacherous words in statistical science. Here you mean scaling to [0, 1]; elsewhere others use it to mean make closer to normal (Gaussian). Which method requires the first?

      Comment


      • #4
        Thank you

        Comment

        Working...
        X