Announcement

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

  • Scaling Data

    Hi all,
    I am working on some survey data, one question is based on proportions. I therefore have 5 variables which should add up to 100%. Some responses have a sum of just over 100 or just under 100. I would like to scale the 5 variables such that the totals always add up to 100. Is there a streamline way I can do this?
    Thanks!

  • #2
    Code:
    clear
    input v1 v2 v3 v4 v5
    1 2 3 4 5
    end
    
    egen total = rowtotal(v1 v2 v3 v4 v5)
    
    foreach x in v1 v2 v3 v4 v5{
        gen res_`x' = `x'/total*100
        format res_`x' %4.2f
    }
    
    list

    Comment


    • #3
      Thank you, this was very helpful.

      Comment


      • #4
        Why scale here? If the variables are all integers you should expect that they add to 100. Otherwise failure to add exactly to 100 is a common side-effect of reporting resolution. More at https://statweb.stanford.edu/~cgates...freedman79.pdf

        Comment

        Working...
        X