Announcement

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

  • Assign string variable to all in group

    I would like to assign a string variable to all in a group. I want to be able to assign "IA" if any member of the group has IA. I want to create the values in newvalue. My data looks like this

    id. val. newvalue
    1. IA. IA
    1. II. IA
    1. IA IA
    2. II . (missing since no IA for person 2)
    2. II .
    2 ID .
    3. II. IA
    3. II IA
    3 IA. IA
    4. . IA
    4. IA. IA
    4 ID. IA



  • #2
    Code:
    bys id: egen tag= max(inlist(val, "IA"))
    gen newval = "IA" if tag

    Comment


    • #3
      Another way to do it

      Code:
      gen isIA = val == "IA" 
      
      bysort id (isIA) : gen newval = cond(isIA[_N], "IA", "")

      Comment

      Working...
      X