Announcement

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

  • #16
    Hi Devra,

    That is true. However, in the context of the study I am conducting it is important to keep solely households with only one husband/wife over all the waves in which that HH ID appears. Do you know how I could modify the code to accomplish this with STATA?

    Thank you in advance and apologies for all the confusion.

    Enrique

    Comment


    • #17
      I think this code will count the number of wives & husbands per HH ID. I copied the data from one of the posts above. It seems to have one HH with both two husbands and two wives. If this is not artificial, you might need to do some more data cleaning. egenmore (ssc install egenmore) is maintained by Nick Cox. Nick is also the author of the FAQ which explains how to spread the number of wives and husbands across each HH.

      Code:
      clear
      input str10(pidlink hhid) float(wave husband wife)
      "272010001" "2720100" 1 1 0
      "272010001" "2720100" 2 1 0
      "272010001" "2720100" 3 1 0
      "272010001" "2720100" 4 1 0
      "272010001" "2720100" 5 1 0
      "272010002" "2720100" 1 0 1
      "272010002" "2720100" 2 0 1
      "272010002" "2720100" 3 0 1
      "272010002" "2720100" 4 0 1
      "272010002" "2720151" 5 0 0
      "272010003" "2720100" 1 0 0
      "272010003" "2720100" 2 0 0
      "272010003" "2720100" 3 0 0
      "272010003" "2720100" 4 0 0
      "272010003" "2720100" 5 0 0
      "272010004" "2720100" 2 0 0
      "272010004" "2720100" 3 0 0
      "272010004" "2720100" 4 0 0
      "272010004" "2720100" 5 0 0
      "272010005" "2720100" 5 0 0
      "272010006" "2720100" 5 0 1
      "272020001" "2720200" 1 1 0
      "272020001" "2720211" 2 1 0
      "272020001" "2720211" 3 1 0
      "272020001" "2720211" 4 1 0
      "272020001" "2720211" 5 1 0
      "272020002" "2720200" 1 0 1
      "272020002" "2720211" 2 0 1
      "272020002" "2720211" 3 0 1
      "272020002" "2720211" 4 0 1
      "272020002" "2720211" 5 0 1
      "272020003" "2720200" 1 0 0
      "272020003" "2720211" 2 0 0
      "272020003" "2720211" 3 0 0
      "272020003" "2720211" 4 0 0
      "272020003" "2720211" 5 0 0
      "272020004" "2720200" 2 1 0
      "272020004" "2720200" 3 1 0
      "272020004" "2720200" 4 1 0
      "272020004" "2720200" 5 1 0
      "272020005" "2720200" 2 0 1
      "272020005" "2720200" 3 0 1
      "272020005" "2720200" 4 0 1
      "272020005" "2720200" 5 0 0
      "272021104" "2720211" 2 0 0
      "272021104" "2720211" 3 0 0
      "272021104" "2720211" 4 0 0
      "272021104" "2720211" 5 0 0
      "272030001" "2720300" 1 1 0
      "272030001" "2720300" 2 1 0
      "272030001" "2720300" 3 1 0
      "272030001" "2720300" 4 1 0
      "272030001" "2720300" 5 1 0
      "272030002" "2720300" 1 0 1
      "272030002" "2720300" 2 0 1
      "272030002" "2720300" 3 0 1
      "272030002" "2720300" 4 0 1
      "272030002" "2720300" 5 0 1
      "272030003" "2720300" 1 0 0
      "272030003" "2720300" 2 0 0
      "272030003" "2720300" 3 0 0
      "272030003" "2720341" 4 0 1
      "272030004" "2720300" 2 0 0
      "272030004" "2720300" 3 0 0
      "272030004" "2720300" 4 0 0
      "272030004" "2720300" 5 0 0
      "272030005" "2720300" 3 0 0
      "272030005" "2720300" 4 0 0
      "272030005" "2720300" 5 0 0
      "272034101" "2720341" 4 1 0
      "272034101" "2720341" 5 0 0
      "272034103" "2720341" 4 0 0
      "272034104" "2720341" 5 1 0
      "272040001" "2720400" 1 1 0
      "272040001" "2720400" 2 1 0
      "272040001" "2720400" 3 1 0
      "272040001" "2720400" 4 1 0
      "272040001" "2720400" 5 1 0
      "272040002" "2720400" 1 0 1
      "272040002" "2720400" 2 0 1
      "272040002" "2720400" 3 0 1
      "272040002" "2720400" 4 0 1
      "272040002" "2720400" 5 0 1
      "272040003" "2720400" 1 0 0
      "272040003" "2720400" 2 0 0
      "272040003" "2720400" 3 0 0
      "272040003" "2720400" 4 0 0
      "272040003" "2720451" 5 1 0
      "272040004" "2720400" 1 0 0
      "272040004" "2720400" 2 0 0
      "272040004" "2720400" 3 0 0
      "272040004" "2720400" 4 0 0
      "272040004" "2720400" 5 0 0
      "272040005" "2720400" 4 0 0
      "272040005" "2720400" 5 0 0
      "272050001" "2720500" 1 1 0
      "272050001" "2720500" 2 1 0
      "272050001" "2720500" 3 1 0
      "272050001" "2720500" 4 1 0
      "272050001" "2720500" 5 1 0
      end
      
      *count the number of wives & husbands per HH
      egen nwife=nvals(pid) if wife==1, by(hhid)
      egen nhusb=nvals(pid) if husband==1, by(hhid)
      
      *spread the number of wives & husbands to all observations in the HH group
      bysort hhid (nwife), sort: replace nwife=nwife[_n-1] if missing(nwife)
      bysort hhid (nhus), sort: replace nhusb=nhusb[_n-1] if missing(nhusb)
      
      *list some observations
      list  if nwife==2 & nhusb==2
      
      *keep if 1 husband & wife each
      keep if nwife==1 & nhusb==1
      Devra Golbe
      Professor Emerita, Dept. of Economics
      Hunter College, CUNY

      Comment


      • #18
        In the larger data, all have 2. You can mark the switching homes by

        Code:
        g hhid_change = hhid != substr(pidlink,1,5)
        egen hhid_change_any = max(hhid_change), by(hhid)
        Not clear what you want to do with that info if you just want households with one husband/one wife.

        If you want the same pair, then you can use hhid_change_any to drop observations.

        Comment

        Working...
        X