Announcement

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

  • Keeping highest values of a variable per individual

    Hello,

    I have been struggling all day with my database, and I don't seem to find a solution to my problem. I have data that looks like this:
    Person BSc MSc Phd Education_level
    A 0 0 1 2
    A 1 0 0 0
    A 0 1 0 1
    B 1 0 0 0
    B 0 0 1 2
    The variables BSc MSc and Phd are dummy variables. A value of 1 is assigned if the person has obtained a degree. Therefore, the database has information that person A has obtained all 3 types of degrees, whereas t he database only recognizes that person B has obtained a BSc and Phd. In some cases, people have more than 1 degree of each type, so it results in even more observations for an individual.

    The last variable, Education_level is a variable I created. It assignes a value of 0 to BSc degrees, a value of 1 for MSc degrees, and a value of 2 for Phds. My goal is to end up with a single observation per Person, so that I will keep the highest value of the variable Education_level per individual. It should look like this:
    Person Education_level
    A 2
    B 2
    How can I achieve this? Thank you so much for your help.


    Best regards,

    Carla
    Last edited by carla Oth; 05 Apr 2022, 14:58.

  • #2
    Code:
    collapse (max) Education_level, by(Person)

    Comment


    • #3
      Thank you, you made it so easy!

      Comment

      Working...
      X