Announcement

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

  • rescaling a variable from -45 - 43 to 0 - 10

    Hello,

    I'm struggling to rescale a variable with the min -45.946 and max of 43.21 to 0 - 10 scale.
    I've seen few threads about this here on the forum but usually from 0-10 to 0-100 which sounds a bit easier.
    Does anybody have a simple solution for how I could deal with this problem?

    Best,
    Johanna

  • #2
    Code:
    // open some example data
    sysuse auto, clear
    
    // get the min and max of price
    sum price, meanonly
    
    // create the rescaled price
    gen price_rs = ( price - r(min) ) / ( r(max)-r(min) ) * 10
    
    // admire the result
    sum price price_rs
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Hi Johanna. This is probably obvious, but I'll say it anyway. If the lowest possible score < the observed minimum or the highest possible score > the observed maximum, use the lowest and highest possible scores in place of r(min) and r(max)--they give the observed min and max in your dataset. HTH.
      --
      Bruce Weaver
      Email: [email protected]
      Version: Stata/MP 18.5 (Windows)

      Comment


      • #4
        Thank you so much for the quick response! The code achieved the exact results I was hoping for!

        Comment


        • #5
          I am trying to rescale a variable scaled from1-10 to -4.5 to 4.5. How do I do it.

          Comment


          • #6
            gen newvar=oldvar - 5.5

            Comment


            • #7
              Thank you, but this only gave me tha minimum value of -4.5 and not a fixed value of 4.5. How should I do to obtain a fixed rescaling of -4.5 to 4.5

              Comment


              • #8
                Apperently, you have no one in your data that reached the theoretical maximum of 10. If someone in your data had a 10 on the original variable then (s)he would have gotten a 10-5.5=4.5 on the new variable. So the new variable is correct, it is just that your data does not cover the entire theoretical range.
                ---------------------------------
                Maarten L. Buis
                University of Konstanz
                Department of history and sociology
                box 40
                78457 Konstanz
                Germany
                http://www.maartenbuis.nl
                ---------------------------------

                Comment


                • #9
                  I'm wondering whether you have tried the code in #6. If so, it will give a range from min(-4.5) and max(4.5). I gather this is what you asked. To end, I fail to understand what is meant by "fixed".
                  Best regards,

                  Marcos

                  Comment


                  • #10
                    Yeah, at first I didn't understand but I ran my code and got what I asked for. Thanks you everyone for your help.

                    Comment

                    Working...
                    X