Announcement

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

  • Replacing the information with condition

    I am using STATA SE version 16. I used sort famhh and egen chair_m=mode(chair), by(famhh) to regenerate more reliable asset component. But some value are missing (possibly due to contradiction of the mode when the equal number of either side). It's okey as it serves main purpose. Now I want to replace the value of chair to chair_m of each of the household head (relhh==self) to all the family members (rid) of the same family (famhh).


    slno rid famhh relhh chair chair_m

    110. 1D01013001 1D010130 Self 1 .
    111. 1D01013002 1D010130 Son 0 .
    256. 1D01028410 1D010284 Son 0 .
    257. 1D01028404 1D010284 Self 1 .
    478. 1D01046002 1D010460 Son 0 .

    479. 1D01046001 1D010460 Self 1 .
    575. 1K06015502 1K060155 Daughter 0 .
    576. 1K06015501 1K060155 Self 1 .
    651. 1K06037102 1K060371 Wife 0 .
    652. 1K06037101 1K060371 Self 1 .

    694. 1K06048702 1K060487 Wife 0 .
    695. 1K06048701 1K060487 Self 1 .
    703. 1K06051702 1K060517 Daughter 0 .
    704. 1K06051701 1K060517 Self 1 .
    816. 1K06078401 1K060784 Self 1 .

    817. 1K06078402 1K060784 Son 0 .
    822. 1K06080702 1K060807 Wife 0 .
    823. 1K06080707 1K060807 Father 1 .
    824. 1K06080704 1K060807 Son 0 .
    825. 1K06080701 1K060807 Self 0 .

    826. 1K06080703 1K060807 Son 1 .
    827. 1K06080706 1K060807 Father in la 1 .
    1095. 1K12301802 1K123018 Daughter 0 .
    1096. 1K12301801 1K123018 Self 1 .
    1136. 1K12316204 1K123162 Son 1 .

    1137. 1K12316203 1K123162 Daughter 0 .
    1138. 1K12316202 1K123162 Wife 0 .
    1139. 1K12316201 1K123162 Self 1 .
    1147. 1K12319202 1K123192 Wife 0 .
    1148. 1K12319201 1K123192 Self 1 .

    1154. 1K12321302 1K123213 Wife 1 .
    1155. 1K12321303 1K123213 Daughter 0 .
    1156. 1K12321301 1K123213 Self 1 .
    1157. 1K12321304 1K123213 Son 0 .
    1291. 1K12332401 1K123324 Self 1 .

    1292. 1K12332402 1K123324 Wife 0 .
    1389. 1M02012602 1M020126 Mother 1 .
    1390. 1M02012603 1M020126 Son 1 .
    1391. 1M02012601 1M020126 Father 1 .
    1392. 1M02012606 1M020126 Son 0 .

    1393. 1M02012605 1M020126 Wife 0 .
    1394. 1M02012604 1M020126 Self 0 .
    1411. 1M02022001 1M020220 Self 1 .
    1412. 1M02022002 1M020220 Wife 0 .
    1427. 1M02024105 1M020241 Self 1 .

    1428. 1M02024106 1M020241 Wife 0 .
    1489. 1M02043304 1M020433 Daughter 0 .
    1490. 1M02043305 1M020433 Son in law 0 .
    1491. 1M02043301 1M020433 Self 1 .
    1492. 1M02043303 1M020433 Daughter 1 .

    1545. 1M02059501 1M020595 Wife 1 .
    1546. 1M02059502 1M020595 Self 0 .
    1654. 1M02087607 1M020876 Son 0 .
    1655. 1M02087602 1M020876 Self 1 .
    1876. 1M04056905 1M040569 Son 1 .

    1877. 1M04056908 1M040569 Grandson 0 .
    1878. 1M04056902 1M040569 Wife 1 .
    1879. 1M04056901 1M040569 Self 0 .



    Please note, I need to do the same thing for 23 more variables. Please help me.


  • #2
    Please read FAQ and use -dataex- to show your data example.

    Comment


    • #3
      Thank you Fei Wang. Here is the data using the dataex

      Code:
      input str10 rid str8 famhh double relhh byte(chair chair_m)
      "1D01045501" "1D010455"  1 1 0
      "1D01045503" "1D010455"  3 0 0
      "1D01045502" "1D010455"  9 0 0
      "1D01045504" "1D010455" 14 0 0
      "1D01045505" "1D010455"  3 0 0
      "1D01045602" "1D010456"  9 1 1
      "1D01045601" "1D010456"  1 1 1
      "1D01045603" "1D010456"  3 1 1
      "1D01045604" "1D010456" 10 1 1
      "1D01046002" "1D010460"  3 0 .
      "1D01046001" "1D010460"  1 1 .
      "1D01046104" "1D010461"  3 0 0
      
      
      label values relhh relhh
      label def relhh 1 "Self", modify
      label def relhh 3 "Son", modify
      label def relhh 9 "Wife", modify
      label def relhh 10 "Daughter", modify
      label def relhh 14 "Mother in law", modify

      Comment


      • #4
        Thanks for the data example. If I understand correctly, you'd like to replace the values of chair of family members with the value of chair of the household head in the family. The code below assumes there is a head in every family.

        Code:
        bys famhh (relhh): replace chair = chair[1]

        Comment


        • #5
          Thank you Fei Wang. Though this may need some change as following

          Code:
          bys famhh (relhh): replace chair_m = chair[1]

          Comment

          Working...
          X