Announcement

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

  • z-score between more variables

    good morning to everyone,
    is there a command to calculate z-scores between multiple variables?
    To clarify: I have a battery of variables and my objective is to be able to compare for each individual (observation) how each variable is positioned with respect to the others.
    If we think about the database structure my goal is to compute a horizontal z-score rather than the usual vertical one.
    Is it possible?

    (all variables have the same scale but of course, can get different scores depending on individual responses).
    Last edited by Chiara Tasselli; 02 May 2022, 09:28. Reason: z-scores

  • #2
    I'm not aware of any single command that can do this. But piecing it together from basic Stata commands is not hard. As you provided no example data, I illustrate the approach in the auto.dta.
    Code:
    sysuse auto, clear
    
    unab vbles: price mpg headroom trunk weight
    
    egen m = rowmean(`vbles')
    egen sd = rowsd(`vbles')
    
    foreach v of varlist `vbles' {
        gen z_`v' = (`v'-m)/sd
    }
    Now, this does not seem a reasonable or meaningful thing to do with the variables in auto.dta. If your variables are actually on similar scales, it becomes more suitable. But then it makes me think that perhaps you should really -reshape- your data into long layout, making all of those "variables" separate observations of a single variable, and do the standardization in the usual way. Without knowing more about the variables and what they are, it's hard to say.

    Comment

    Working...
    X