Announcement

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

  • How to create a unique identifier for each combination?

    Dear all,

    I have a variable called partner, which is equal to zero if the partner is the wife and 1 if the partner is the husband. Within each household, denoted by a household identifier (hhid) there are various couples. I want to group each combination of 0 and 1 within the household as a couple.

    I have tried to do this using:

    egen partner_id = group(hhid partner) but I do not quite get the identifier for each combination of 0 and 1 within a household.

    Do you know how I could do this?

    Thank you in advance,

    Enrique

  • #2
    I don't understand. Suppose that household 1 contains two couples: male person 1 is married to female person 2, and male person 3 is married to female person 4. How do you know that the marriages are 1 with 2 and 3 with 4, not 1 with 4 and 2 with 3? There must be some variable(s) that enable you to figure that out. Without that information, it isn't possible to identify the couples, let alone assign them unique identifiers.

    Please post back with the full explanation and also include example data. Use the -dataex- command to do that. If you are running version 18, 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Comment


    • #3
      Dear Clyde,

      The variable that allows me to infer this is called relationtohead:

      Where it takes a value of 1 if the head 2 if the spouse of the head. I would like to group those with a value of 1 and 2 and the same household id as a couple.

      Here is the dataex with both the hhid and the relationtohead variable:

      20151 1
      21951 1
      22951 2
      30153 1
      30451 1
      30551 1
      30552 2
      30553 2
      30553 1
      30931 2
      30931 2
      30941 1
      31151 1
      31341 2
      31551 1
      31741 2
      31741 2
      31831 1
      31831 1
      31831 2
      31842 1
      31851 1
      31931 2
      31931 2
      32011 1
      32011 1
      32011 1
      32011 1
      32051 2
      32651 2
      32941 2
      32941 1
      32941 1
      40631 1
      40631 2
      40631 1
      40631 1
      40631 2
      40631 2
      41053 1
      41053 2
      41431 2
      41431 2
      41431 2
      41431 1
      41431 1
      41431 1
      42221 2
      42221 1
      42221 2
      42221 2
      42221 1
      42641 2
      42641 1
      43041 1
      43041 1
      50122 1
      50122 1
      50122 1
      51311 2
      51311 2
      51311 2
      51311 2
      51312 2
      51312 2
      51741 2
      60411 2
      60700 1
      60700 1
      60700 2
      60700 2
      60700 1
      60700 2
      60700 2
      60700 2
      60700 1
      60700 1
      60841 1
      60841 2
      60841 1
      61041 2
      61442 2
      61442 2
      61600 1
      61600 2
      61600 1
      61600 2
      61600 2
      61600 2
      61600 1
      61600 1
      61600 2
      61600 1
      61811 2
      61811 2
      61811 1
      61811 1
      61811 1
      61811 2
      61811 1


      Thank you in advance,

      Enrique

      Comment


      • #4
        You cropped your copy/paste of the -dataex- output in a way that leaves out a lot of information that, in this particular instance probably is unimportant, but often would be crucial. Please be more careful to use -dataex- correctly in the future. There is something very odd about this data. There are 5 households with 2 heads, 3 with 3 heads, and 2 each with 4 and 5 heads. I'm not aware of any household classification system that allows for more than one head in the household. So please explain this one.

        Moreover, 6 households, 40631, 41431, 42221, 60700, 61600, and 61811 have both more than one head and more than one spouse, hence presumably multiple couples. So in those we have the situation I raised in #2 where more information is needed to distinguish who is whose spouse. If you are going to identify couples, there must be some other variable or variables that provide this additional information.

        As things stand now, it is not possible to solve your problem. And I can't get past feeling that there is something wrong with the data set in the first place.

        Comment

        Working...
        X