Announcement

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

  • creating household identifier in long file

    I have been struggling with figuring out a way to create a unique household identifier (NEW VAR in table below) for data which look like the table displayed under this message. Would appreciate any advice!

    Click image for larger version

Name:	creating household var.png
Views:	1
Size:	142.4 KB
ID:	1435460
    Attached Files
    Last edited by Katya Ivanova; 21 Mar 2018, 05:54.

  • #2
    Please don't post data as images. Post data as code using dataex. https://www.statalist.org/forums/help#stata explains.

    What are your rules? I can't work them out.

    Comment


    • #3
      Here is the dataex output:

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input double(famid alter_persid ytype) float biotog
      5602000025 5702034086 5 0
      5602000025 5702034084 4 0
      5602000025 5702034085 1 0
      5602000064 5702008156 4 1
      5602000064 5702008157 1 1
      5602000067 5702009962 1 1
      5602000067 5702009961 4 1
      5602000070 5702057144 1 0
      5602000079 5702042848 5 .
      5602000079 5702042846 4 .
      5602000105 5702024467 1 0
      5602000107 5702012578 4 0
      5602000107 5702012580 2 0
      5602000108 5702039876 5 .
      5602000108 5702039874 4 .
      5602000108 5702039875 1 .
      5602000125 5702006837 4 1
      5602000148 5702018197 3 0
      5602000157 5702017365 4 .
      5602000157 5702017366 1 .
      end
      label values ytype ytype
      label def ytype 1 "bio mother", modify
      label def ytype 2 "new partner father", modify
      label def ytype 3 "widowed new partner father", modify
      label def ytype 4 "bio father", modify
      label def ytype 5 "new partner mother", modify
      label values biotog tog
      label def tog 0 "bio parents not tog", modify
      label def tog 1 "bio parents tog", modify
      Each famid can have multiple alter_persid reporting (who can be bio mother, new partner father, etc as defined in ytype). The variable biotog determines whether the bio parents are still together or separated. I want to create a variable which groups the alters into their respective households (in order to account for clustering of individuals in households). For the intact it's easy because they are defined by their common famid (their kid). But once those bio parents are not together and potentially have new partners, I am not sure how to code it (i.e., there are multiple parent figures who all share the same famid). The logical combinations are multiple: fathers can be - with bio mother, with new partner, alone; bio mothers - with bio fathers, with new partners, alone; stepfathers can be with bio mothers or widowed (and same for stepmothers).

      So for example, for the first three lines - alter_persid 5702034086 (new partner mother) and 5702034085 (bio mother) are one household and 5702034084 (bio father) is another household.

      Hope that this is clearer and thank you!

      Comment

      Working...
      X