Announcement

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

  • Identifying persons with affected parents

    Hi,

    A common problem when studying families is to identify offspring with affected parents. The problem I can't work my mind around is, how to create a new variable and tell Stata to do the lookup.
    In this example here, we have only one pedigree, fam_1, where a person with id 9074 is both a mother as well as affected. This is designated by variable is_affected_mom which gets value 1. The pedigree includes a member with id 9307, whose mother person 9074 is, as indicated with the variable mom_id.

    How do I tell Stata to check whether mom_id value can be found both in variable id, and at the same time, to get value 1 in variable is_affected_mom?

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str5 family_id    long id long    mom_id    byte is_affected_mom
    fam_1    9017    .       .
    fam_1    9064    9190    .
    fam_1    9074    .       1
    fam_1    9232    .       .
    fam_1    9233    .       .
    fam_1    9234    .       .
    fam_1    9235    .       .
    fam_1    9307    9074    .
    fam_1    9386    9190    .
    end
    Thank you in advance!

    BR Mikko

  • #2
    Thank you for the data example. This is a straightforward job for a -merge- once you know how records are linked.

    Code:
    clear
    frame create Working
    frame change Working
    input str5 family_id    long id long    mom_id    byte is_affected_mom
    fam_1    9017    .       .
    fam_1    9064    9190    .
    fam_1    9074    .       1
    fam_1    9232    .       .
    fam_1    9233    .       .
    fam_1    9234    .       .
    fam_1    9235    .       .
    fam_1    9307    9074    .
    fam_1    9386    9190    .
    end
    
    replace is_affected_mom = 0 if mi(is_affected_mom)
    frame put family_id id if is_affected_mom, into(MomAffected)
    
    frlink m:1 family_id mom_id, frame(MomAffected family_id id) gen(lmom)
    For convenience, I have replaced 0s for every missing value of -is_affected_mom- to make it's use as a logical flag compatible with Stata's definition (where 0 is treated false, and all non-zeros are treated as true).

    Result:

    Code:
    . list
    
         +--------------------------------------------+
         | family~d     id   mom_id   is_aff~m   lmom |
         |--------------------------------------------|
      1. |    fam_1   9017        .          0      . |
      2. |    fam_1   9064     9190          0      . |
      3. |    fam_1   9074        .          1      . |
      4. |    fam_1   9232        .          0      . |
      5. |    fam_1   9233        .          0      . |
         |--------------------------------------------|
      6. |    fam_1   9234        .          0      . |
      7. |    fam_1   9235        .          0      . |
      8. |    fam_1   9307     9074          0      1 |
      9. |    fam_1   9386     9190          0      . |
         +--------------------------------------------+

    Comment


    • #3
      Thank you, Leonardo!
      You also displayed here the frame(s) -function which indeed is something I need to learn.
      Very good!
      Thanks!
      BR Mikko

      Comment

      Working...
      X