Announcement

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

  • Backfilling empty observations based on same id

    Hello everyone,

    I have recently encountered a couple of data set in which the first contains main player attributes and the second contains secondary attributes. The first one also contains signing info for the player that I would like to expand to all the observations for a player post merge. Is there a way to backfill the missing observations based on the first one? Here is what my data looks like (sorted by name, _merge):
    player_name signing_year signing_source attributes _merge
    Alfredo 2021 High School Center Attack (1) master
    Alfredo . Right Winger (2) using
    Alfredo . Right Inverted Forward (2) using
    Michael 2019 College Center Back (1) master
    Michael . Deep Center Back (2) using
    Xavier 2023 College Midfield Left (1) master
    Xavier . Advanced Playmaker (2) using
    Xavier . Deep Lying Playmaker (2) using
    Thank you!

  • #2
    Code:
    sort player_name _merge
    foreach v of varlist signing_year signing_source {
        by player_name (_merge): replace `v' = `v'[1] if missing(`v')
    }

    Comment


    • #3
      This works, thank you

      Comment

      Working...
      X