Announcement

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

  • How to identify all the cases in a list of binary variables

    Hello folks, I have a list of binary variables and I want to generate a new variable describing the combination. Below is part of what my data looks like

    Code:
    id    sch_grade_ps    sch_grade_kg    sch_grade_g01    sch_grade_g02    sch_grade_g03    sch_grade_g04    sch_grade_g05    sch_grade_g06    sch_grade_g07
    1    0    0    0    0    0    0    0    1    1
    2    0    0    0    0    0    0    0    1    1
    3    0    0    0    0    0    0    0    1    1
    4    0    0    0    0    0    0    1    1    1
    5    0    0    0    0    0    0    0    0    1
    6    0    0    0    0    0    0    0    0    0
    7    0    0    0    0    0    0    1    1    0
    8    0    0    0    0    1    1    0    0    0
    9    1    1    0    0    0    0    0    0    0
    10    1    0    1    1    0    0    0    0    0
    11    0    0    0    0    0    0    1    1    1
    12    0    0    0    0    0    0    0    1    1
    13    1    1    1    1    1    1    0    0    0
    14    1    0    0    0    1    1    1    0    0
    15    0    0    0    0    0    0    0    0    0
    16    1    0    0    0    1    1    1    0    0
    17    0    0    0    0    0    0    0    0    0
    18    1    1    1    1    0    0    0    0    0
    19    1    1    1    1    0    0    0    0    0
    20    0    0    0    0    0    0    0    1    1
    21    0    0    0    0    0    0    0    0    0
    22    1    1    1    1    1    1    0    0    0
    23    0    0    0    0    0    0    0    1    1
    24    1    1    1    1    1    1    1    0    0
    I want to create a new variable, say grade_level and it describes the grades covered by each ID. For instance, for ID=1, the new variable will has value such as "6-7" or "6&7", etc. Anyway, my goal is to get a shorter version of the grade levels for each ID. The next step is to group IDs that have the same grade levels together. I did some search and found a command called Tuples but I feel this is not exactly what I want. Any ideas? Thanks!

  • #2
    One way to do this is:

    Code:
    egen grade_level = concat(sch_grade_ps sch_grade_kg sch_grade_g01 ///
    sch_grade_g02 sch_grade_g03 sch_grade_g04 sch_grade_g05 ///
    sch_grade_g06 sch_grade_g07), punct("&")

    Comment

    Working...
    X