Announcement

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

  • variable management

    Good evening,
    I have a battery of 15 variables which reply to the following question:

    "HOW LIKELY IS IT THAT YOU WILL .....?
    Express a rating from 1 to 5 where 1 = Extremely Unlikely and 5 = Extremely Likely"


    I was wondering if there is any (quick) command which for each variable builds a dummy that takes value one if that variable takes the highest value of the row (among all 15 variables).


    Many thanks in advance for your time.
    Wishing you all a great weekend ahead.

  • #2
    If your variables are called v1-v15,
    Code:
    egen highest_value = rowmax(v1-v15)
    forvalues i = 1/15 {
        gen byte takes_highest_value_`i' = (v`i' == highest_value)
    }
    Note: No example data, so not tested. Beware of typos or other errors. Also, because no example data, this code may break if your data does not look like I imagine it does.

    In the future, please show example data whenever requesting help with code, and do so using the -dataex- command. If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Comment


    • #3
      Good Morning,
      many thanks: completely got the logic of your tips, make some minor adjustments in my data label and it works!

      Many thanks also for the suggestions about posting here, extremely useful!

      Wishing you a good week ahead!

      Comment

      Working...
      X