Announcement

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

  • Removing 2 variables from a ranking and recalculating rank

    Here is the shape of my data
    • 7 attributes (size, colour, price, etc.) were ranked by people.
    • The data is arranged whereby if attribute “size” was ranked first then size=1. If size was ranked second then size=2. If colour was ranked fifth than colour=5, and so on.
    • So each case has 7 variables for ranking, each taking a value from 1 to 7
    The problem
    • I want to remove two of the variables (say price and colour) from the ranking, and calculate mean rank per variable
    • Unless I recalculate ranks so that they are from 1 to 5, the mean rank will be biased.
    • But I can’t figure out a straightforward way to recalculate ranks so that they are from 1 to 5
    What I’ve tried so far
    I tried creating new variables called size5, shape5, and take the approach “replace size5 = 1 if size 5 > shape5” and so on with other 4 attributes with further ‘replace x if’. However, once I get to replace size5 = 2 then it quickly creates a “if” conditions of unmanageable number and complexity.

    Surely there must a simple way to do this I just don’t know about?
    Advice welcome!

  • #2
    Ian:
    welcome to this forum.
    As per FAQ, and example/excerpt of your dataset, that you can easily share via -dataex- would help interested listers to reply positively.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      your question is not very clear; however, I think that after deleting the two variables you want to drop, -egen- with one of the "rank" function is what you want; note that there are 3 ways to use this so you should read the help file carefully; see
      Code:
      help egen
      added in edit: note that I believe you want to drop two variables but that part of your question is particularly unclear to me

      Comment


      • #4
        thanks both - will read FAQ properly and post excerpt if I make another post to the forum.

        I worked it out for myself in the end, though reading help egen as a result of Rich's input helped me think about it (thanks Rich!)

        Putting solution here in case it helps someone else in the future.

        Perhaps it wasn't clear that each rank was already set up as a variable. The solution was to do create a new set of rank variables and use commands like
        replace a=a-1 if b<a
        and so on.
        So if a was ranked 5th, then it would be replaced as ranked 4th if b (the variable to be dropped) was ranked higher than a originally (where 1 is highest).
        If a was ranked 5th but b was ranked 6th, then nothing happens.

        I compared with different cases that I fixed manually to cross-check and this solution works.

        thanks again, and I will read the FAQ next time.
        ian


        Comment

        Working...
        X