Announcement

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

  • #16
    Code:
    bys householdnumber: egen n_head = total(head_of_house)
    bys householdnumber: egen n_spouse = total(spouse)
    bys householdnumber: egen n_child = total(child)
    bys householdnumber: gen hh_size = _N
    
    * Nuclear House Hold: 1 head, 1 spouse,and children, no one else
    gen NuclearHH = (n_head==1)&(n_spouse==1)&(n_child >0)&(n_head + n_spouse + n_child == hh_size)

    Comment


    • #17
      Anna:
      when I -tab- -test- it gives me back:
      Code:
      . tab test
      
             . tab test
      
             test |      Freq.     Percent        Cum.
      ------------+-----------------------------------
                3 |         63      100.00      100.00
      ------------+-----------------------------------
            Total |         63      100.00
      Please note that 100% percent refers to 63 out of 100 households.
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment


      • #18
        Wow. Thank you for the replies kind Stata-experts. I'll get back to you as soon as i have tested the different codes.

        Daniel Bela,
        Its amazing that you have translated the danish!! Kudos to your danish skills.
        About your code:
        I can tell you that although that one seems easy, it would not help me since if i limit the household size to ==3 then i would not get the families that has more than one child, and i need all the children. Cause a nuclear familiy is one father one mother and x amount of children.

        Originally posted by Daniel Bela View Post
        Another solution (not that efficient, but maybe easier to understand):
        Code:
        clear
        input long(postid householdnumber) str150 position_in_household_std float(spouse spouse_in_household child child_in_household head_of_house head_in_household)
        1 1 "Husstandsoverhoved" 0 1 0 0 1 1
        2 1 "Husstandsoverhoveds ægtefælle" 1 1 0 0 0 1
        3 1 "Husstandsoverhoveds tjenestefolk" 0 1 0 0 0 1
        4 2 "Husstandsoverhoved" 0 1 0 1 1 1
        5 2 "Husstandsoverhoveds ægtefælle" 1 1 0 1 0 1
        6 2 "Husstandsoverhoveds fællesbarn" 0 1 1 1 0 1
        7 2 "Husstandsoverhoveds logerende" 0 1 0 1 0 1
        8 3 "Husstandsoverhoved" 0 1 0 1 1 1
        9 3 "Husstandsoverhoveds ægtefælle" 1 1 0 1 0 1
        10 3 "Husstandsoverhoveds fællesbarn" 0 1 1 1 0 1
        11 3 "Husstandsoverhoveds fællesbarn" 0 1 1 1 0 1
        12 3 "Husstandsoverhoveds fællesbarn" 0 1 1 1 0 1
        13 3 "Husstandsoverhoveds fællesbarn" 0 1 1 1 0 1
        14 3 "Husstandsoverhoveds ægtefælles forældre" 0 1 0 1 0 1
        15 3 "Husstandsoverhoveds tjenestefolk" 0 1 0 1 0 1
        16 4 "Husstandsoverhoved" 0 1 0 0 1 1
        17 4 "Husstandsoverhoveds ægtefælle" 1 1 0 0 0 1
        18 4 "Husstandsoverhoveds tjenestefolk" 0 1 0 0 0 1
        19 4 "Husstandsoverhoveds tjenestefolk" 0 1 0 0 0 1
        20 5 "Husstandsoverhoved" 0 0 0 0 1 1
        21 5 "Husstandsoverhoveds særbarn" 0 0 0 0 0 1
        22 5 "Husstandsoverhoveds særbarn" 0 0 0 0 0 1
        23 5 "Husstandsoverhoveds logerende" 0 0 0 0 0 1
        24 5 "Husstandsoverhoveds logerende" 0 0 0 0 0 1
        25 5 "Husstandsoverhoveds logerende" 0 0 0 0 0 1
        26 6 "Husstandsoverhoved" 0 1 0 0 1 1
        27 6 "Husstandsoverhoveds ægtefælle" 1 1 0 0 0 1
        28 6 "Husstandsoverhoveds tjenestefolk" 0 1 0 0 0 1
        29 7 "Husstandsoverhoved" 0 0 0 1 1 1
        30 7 "Husstandsoverhoveds søskende" 0 0 0 1 0 1
        31 7 "Husstandsoverhoveds fællesbarn" 0 0 1 1 0 1
        32 7 "Husstandsoverhoveds fællesbarn" 0 0 1 1 0 1
        33 7 "Husstandsoverhoveds logerende" 0 0 0 1 0 1
        34 8 "Husstandsoverhoved" 0 1 0 0 1 1
        35 8 "Husstandsoverhoveds ægtefælle" 1 1 0 0 0 1
        36 8 "Husstandsoverhoveds tjenestefolk" 0 1 0 0 0 1
        37 9 "Husstandsoverhoved" 0 1 0 1 1 1
        38 9 "Husstandsoverhoveds ægtefælle" 1 1 0 1 0 1
        39 9 "Husstandsoverhoveds fællesbarn" 0 1 1 1 0 1
        40 9 "Husstandsoverhoveds fællesbarn" 0 1 1 1 0 1
        41 9 "Husstandsoverhoveds fællesbarn" 0 1 1 1 0 1
        42 9 "Husstandsoverhoveds fællesbarn" 0 1 1 1 0 1
        43 9 "Husstandsoverhoveds forældre" 0 1 0 1 0 1
        44 9 "Husstandsoverhoveds søskende" 0 1 0 1 0 1
        45 9 "Husstandsoverhoveds tjenestefolk" 0 1 0 1 0 1
        46 10 "Husstandsoverhoved" 0 1 0 1 1 1
        47 10 "Husstandsoverhoveds ægtefælle" 1 1 0 1 0 1
        48 10 "Husstandsoverhoveds fællesbarn" 0 1 1 1 0 1
        49 10 "Husstandsoverhoveds fællesbarn" 0 1 1 1 0 1
        50 10 "Husstandsoverhoveds fællesbarn" 0 1 1 1 0 1
        51 10 "Husstandsoverhoveds fællesbarn" 0 1 1 1 0 1
        52 10 "Husstandsoverhoveds tjenestefolk" 0 1 0 1 0 1
        53 11 "Husstandsoverhoved" 0 1 0 1 1 1
        54 11 "Husstandsoverhoveds ægtefælle" 1 1 0 1 0 1
        55 11 "Husstandsoverhoveds fællesbarn" 0 1 1 1 0 1
        56 11 "Husstandsoverhoveds tjenestefolk" 0 1 0 1 0 1
        57 11 "Husstandsoverhoveds tjenestefolk" 0 1 0 1 0 1
        58 11 "Husstandsoverhoveds familie" 0 1 0 1 0 1
        59 12 "Husstandsoverhoved" 0 0 0 1 1 1
        60 12 "Husstandsoverhoveds fællesbarn" 0 0 1 1 0 1
        61 12 "Husstandsoverhoveds fællesbarn" 0 0 1 1 0 1
        62 12 "Husstandsoverhoveds fællesbarns barn" 0 0 0 1 0 1
        63 12 "Husstandsoverhoveds fællesbarns barn" 0 0 0 1 0 1
        64 12 "Husstandsoverhoveds fællesbarns barn" 0 0 0 1 0 1
        65 12 "Husstandsoverhoveds fællesbarns barn" 0 0 0 1 0 1
        66 13 "Husstandsoverhoved" 0 1 0 1 1 1
        67 13 "Husstandsoverhoveds ægtefælle" 1 1 0 1 0 1
        68 13 "Husstandsoverhoveds fællesbarn" 0 1 1 1 0 1
        69 13 "Husstandsoverhoveds fællesbarn" 0 1 1 1 0 1
        70 13 "Husstandsoverhoveds fællesbarn" 0 1 1 1 0 1
        71 14 "Husstandsoverhoved" 0 1 0 1 1 1
        72 14 "Husstandsoverhoveds ægtefælle" 1 1 0 1 0 1
        73 14 "Husstandsoverhoveds fællesbarn" 0 1 1 1 0 1
        74 15 "Husstandsoverhoved" 0 1 0 0 1 1
        75 15 "Husstandsoverhoveds ægtefælle" 1 1 0 0 0 1
        76 15 "Husstandsoverhoveds tjenestefolk" 0 1 0 0 0 1
        77 16 "Husstandsoverhoved" 0 1 0 1 1 1
        78 16 "Husstandsoverhoveds ægtefælle" 1 1 0 1 0 1
        79 16 "Husstandsoverhoveds fællesbarn" 0 1 1 1 0 1
        80 16 "Husstandsoverhoveds logerende" 0 1 0 1 0 1
        81 16 "Husstandsoverhoveds logerende" 0 1 0 1 0 1
        82 16 "Husstandsoverhoveds familie" 0 1 0 1 0 1
        83 16 "Husstandsoverhoveds logerende" 0 1 0 1 0 1
        84 17 "Husstandsoverhoved" 0 1 0 1 1 1
        85 17 "Husstandsoverhoveds ægtefælle" 1 1 0 1 0 1
        86 17 "Husstandsoverhoveds fællesbarn" 0 1 1 1 0 1
        87 17 "Husstandsoverhoveds tjenestefolk" 0 1 0 1 0 1
        88 18 "Husstandsoverhoved" 0 0 0 0 1 1
        89 18 "Husstandsoverhoveds plejebarn" 0 0 0 0 0 1
        90 18 "Husstandsoverhoveds søskende" 0 0 0 0 0 1
        91 19 "Husstandsoverhoved" 0 1 0 1 1 1
        92 19 "Husstandsoverhoveds ægtefælle" 1 1 0 1 0 1
        93 19 "Husstandsoverhoveds fællesbarn" 0 1 1 1 0 1
        94 19 "Husstandsoverhoveds logerende" 0 1 0 1 0 1
        95 20 "Husstandsoverhoved" 0 1 0 1 1 1
        96 20 "Husstandsoverhoveds ægtefælle" 1 1 0 1 0 1
        97 20 "Husstandsoverhoveds fællesbarn" 0 1 1 1 0 1
        98 21 "Husstandsoverhoved" 0 1 0 1 1 1
        99 21 "Husstandsoverhoveds ægtefælle" 1 1 0 1 0 1
        100 21 "Husstandsoverhoveds fællesbarn" 0 1 1 1 0 1
        end
        // translate to english -- this may be inadequate for some translations, sorry
        replace position_in_household_std="head" if (position_in_household_std=="Husstandsoverhoved")
        replace position_in_household_std="other family member" if (position_in_household_std=="Husstandsoverhoveds familie")
        replace position_in_household_std="head's parent" if (position_in_household_std=="Husstandsoverhoveds forældre")
        replace position_in_household_std="head's child" if (position_in_household_std=="Husstandsoverhoveds fællesbarn")
        replace position_in_household_std="head's grandchild" if (position_in_household_std=="Husstandsoverhoveds fællesbarns barn")
        replace position_in_household_std="lodger" if (position_in_household_std=="Husstandsoverhoveds logerende")
        replace position_in_household_std="head's foster child" if (position_in_household_std=="Husstandsoverhoveds plejebarn")
        replace position_in_household_std="head's child from previous marriage" if (position_in_household_std=="Husstandsoverhoveds særbarn")
        replace position_in_household_std="head's sibling" if (position_in_household_std=="Husstandsoverhoveds søskende")
        replace position_in_household_std="servant" if (position_in_household_std=="Husstandsoverhoveds tjenestefolk")
        replace position_in_household_std="head's spouse" if (position_in_household_std=="Husstandsoverhoveds ægtefælle")
        replace position_in_household_std="head's parent-in-law" if (position_in_household_std=="Husstandsoverhoveds ægtefælles forældre")
        compress
        
        // generate total of already created spouse-/child-/head-indicators variables
        egen hh_focuspersons=rowtotal(spouse_in_household child_in_household head_in_household)
        
        // generate number of persons in household
        bysort householdnumber (postid) : generate hh_size=_N
        
        // mark focus households (where both of the above equal)
        generate nuclear_family_marker=(hh_size==hh_focuspersons & hh_size==3)
        Regards
        Bela

        Comment


        • #19
          Good that you solved your problem. I don't know much about Reddit, but closing the thread there with a reference to this one might be a good idea. The tough love persona of Statalist is that we may need to push you to be much more precise before we can solve your problem. That's not always understood elsewhere, or even here.

          Comment


          • #20
            :UPDATE:

            None of the above solutions worked for my dataset. (or, possibly, I was not skilled enough in Stata to implement it properly)
            So I ended up solving it myself like this:

            I made every single unique value into a dummy variable, and then I could specify exactly which positions were allowed in the household. I know its quite extensive, and there is probably an easier way, but it worked, and the positive thing about this code is that now I can just play around with the zeros and ones and get every household combination imaginable.

            Code:
            gen nucfamily=1 if head_in_household==1 & fællesbarn_in_household==1 & ægtefælle_in_household==1 & servant_in_household==0 & ///
            admincoworker_in_household==0 & aftægtsfolk_in_household==0 & Barn_af_enke_in_household==0 & Barn_af_opholdende_in_household==0 & ///
            Barnebarn_af_enke_in_household==0 & Barnebarnlogerende_in_household==0 & bogholder_in_household==0 & Elever_ell_lign_in_households==0 & ///
            Enke_in_household==0 & Fagmedarbejder_in_household==0 & Forpagter_bestyrer_in_household==0 & Forældrelogerende_in_household==0 & ///
            Fuldmægtig_in_household==0 & Familie_in_household==0 & Forældre_in_household==0 & Forældresforældre_in_household==0 & ///
            Forældresplejebarn_in_household==0 & Forældressøskende_in_household==0 & ForældresSøskBarn_in_household==0 & ///
            Forældresægtefælle_in_household==0 & Fællesbarnsbarn_in_household==0 & husholderske_in_household==0 & hustholderskesbarn_in_household==0 & ///
            Kæreste_in_household==0 & logerende_in_household==0 & Logerendesbarn_in_household==0 & Logerendesslægtning_in_household==0 & ///
            Fællesbarnsforlov_in_household==0 & Logerendessøskende_in_household==0 & logerendesTyende_in_household==0 & ///
            Logerendesægtefælle_in_household==0 & Lærling_in_household==0 & plejebarn_in_household==0 & Plejeforældre_in_household==0 & ///
            Svend_in_household==0 & Særbarn_in_household==0 &  Særbarnsbarn_in_household==0 & Særbarnsægtefælle_in_household==0 & ///
            søskende_in_household==0 & søskendesbarn_in_household==0 & søskendesægtefælle_in_household==0 & tyendesbarn_in_household==0 & ///
            Tægtefællessærbarn_in_household==0 & tyendessøskende_in_household==0 & tyendesægtefælle_in_household==0 & ægtefællesforældre_in_household==0 /// & ægtefællessærbarn_in_household==0 & ægtefællessærBsBs_in_household==0 & Ægtefællessøskende_in_household==0 & ///
            ægtefællesSøsbarn_in_household==0 & Inkvarteret_in_household==0 & Kollegianere_in_household==0 &  Lemellerindsat_in_household==0 & ///
            medejer_in_household==0 & medejersbarn_in_household==0 & opholdendehos_in_household==0 & Tilhusehos_in_household==0 & ///
            Tyendehosopholdende_in_household==0 & Underholdes_in_household==0 & Uoplyst_in_household==0 & ÆgtefælleOpholdHos_in_household==0 ///
            So now it works.

            NICK COX: I will link it to Reddit, and thank you for your help, I will hopefully get better at being more precise in the future.
            Last edited by Anna Frost; 23 Oct 2018, 09:45. Reason: Formating of the code

            Comment

            Working...
            X