Announcement

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

  • data manipulation

    Hi everyone! I am trying to create a parental education variable for my dataset. The variables i have are Household identification number, Individual identification number, Father's id, The level of education of each individual, and relation to the head of househod(Relation to HoH). I want to create a co-resident sample such that for all individuals, whose Relation to HoH has value =1 , their education level should go as parental education for those who has Relation to HoH value =3. Moreover, I have another variable called 'head of households father's edu'. The value in this for corresponding household, should go straight to relation to head of household=1 as their parent's education. Thus, i have a parental edu variable. Can somebody please help me with the stata code for this. Thanks in advance!

  • #2
    Welcome to the Stata Forum. The first you should do before posting anything is to read the Forum's FAQ and follow the many good suggestions closely. I am sure that you will get faster and better answers then.

    Specifically in your case, have a closer look at #12 therein and what it says about an example of your data.

    Comment


    • #3
      Apologies! I am redefining my problem. I have problem with merging dataset and creating a parental education variable. I want to create a co-resident sample such that for all individuals. The corresponding HHEDUC of those who has Relation to HoH (RO4) value =1 ,are to appear as parental education for those who has Relation to HoH value =3. Moreover, I want to include a non-resident data to this. The variable ID18C comes handy here. What i want to do is to bring the values in ID18C as corresponding parental education for those who has RO4=1. Thus, I will have a new variable 'parental education', which has details of parents of head and children. Hope I am clear. Many thanks for any help received!

      My data looks like this:
      dataex IDHH IDPERSON RO4 RO9 HHEDUC ID18C
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input str10 IDHH str12 IDPERSON int(RO4 RO9 HHEDUC ID18C)
      "0102010101" "010201010101" 1 69  9  0
      "0102010201" "010201020101" 1 75 16  0
      "0102010301" "010201030101" 1 69 11 10
      "0102010401" "010201040101" 1 75  0  0
      "0102010501" "010201050101" 1 75  9  0
      "0102010601" "010201060101" 1 75  9  0
      "0102010701" "010201070101" 1 75  8  0
      "0102010801" "010201080101" 1  .  0  0
      "0102010901" "010201090101" 1  .  9  4
      "0102010902" "010201090201" 1 75  0  0
      "0102011001" "010201100101" 1 75 11  0
      "0102011101" "010201110101" 1 75  8  8
      "0102011201" "010201120101" 1 69 15  8
      "0102011301" "010201130101" 1 69 11  0
      "0102011401" "010201140101" 1 75  8  0
      "0102011601" "010201160101" 1 75 15  0
      "0102011701" "010201170101" 1 75 15 10
      "0102011801" "010201180101" 1 75 16 16
      "0102011901" "010201190101" 1 69  8  0
      "0102012001" "010201200101" 1 75  0  0
      "0102020101" "010202010101" 1 69 15  0
      "0102020201" "010202020101" 1 69 13  0
      "0102020301" "010202030101" 1 75  2  2
      "0102020401" "010202040101" 1 75 11  0
      "0102020501" "010202050101" 1  .  0  0
      "0102020601" "010202060101" 1 75 16 10
      "0102020701" "010202070101" 1 75  9  9
      "0102020801" "010202080101" 1 75 16  9
      "0102020901" "010202090101" 1 75 16  5
      "0102021001" "010202100101" 1 75  0  0
      "0102021101" "010202110101" 1 75  0  0
      "0102021201" "010202120101" 1 75 10  8
      "0102021202" "010202120201" 1 75  8  0
      "0102021203" "010202120301" 1 69  0  0
      "0102021301" "010202130101" 1 75 12  0
      "0102021401" "010202140101" 1 75 11  0
      "0102021501" "010202150101" 1 75 14  0
      "0102021601" "010202160101" 1 75  5  5
      "0102021701" "010202170101" 1 75  0  0
      "0102021801" "010202180101" 1 75  5  5
      "0102021901" "010202190101" 1 75 12  0
      "0102022001" "010202200101" 1 75 12  .
      "0102030101" "010203010101" 1 75  9  0
      "0102030201" "010203020101" 1 75  9  0
      "0102030401" "010203040101" 1 75 15  0
      "0102030501" "010203050101" 1 75 15  9
      "0102030601" "010203060101" 1 75 10 10
      "0102030701" "010203070101" 1 75 14  9
      "0102030801" "010203080101" 1 75 15  0
      "0102030802" "010203080201" 1 75 14 10
      "0102030901" "010203090101" 1 75  0  0
      "0102031001" "010203100101" 1 75  9  0
      "0102031002" "010203100201" 1 69  9  0
      "0102031101" "010203110101" 1 75 14  0
      "0102031201" "010203120101" 1 69 15  0
      "0102031301" "010203130101" 1  . 12  0
      "0102031401" "010203140101" 1 75 16  8
      "0102031501" "010203150101" 1 75 16  3
      "0102031601" "010203160101" 1 75 11  0
      "0102031701" "010203170101" 1  . 12  0
      "0102031801" "010203180101" 1 75 16  5
      "0102031901" "010203190101" 1 75 16  5
      "0102032001" "010203200101" 1 75 11  0
      "0102040101" "010204010101" 1 75 16 10
      "0102040201" "010204020101" 1 75 16 12
      "0102040301" "010204030101" 1 75  9  5
      "0102040401" "010204040101" 1 75 10 10
      "0102040501" "010204050101" 1 75  7  0
      "0102040601" "010204060101" 1 75  0  0
      "0102040701" "010204070101" 1 75  5  5
      "0102040801" "010204080101" 1 75  9  0
      "0102040802" "010204080201" 1 69  9  5
      "0102040901" "010204090101" 1 75 11  0
      "0102041001" "010204100101" 1 75  0  5
      "0102041101" "010204110101" 1 75  5  0
      "0102041201" "010204120101" 1  . 16  0
      "0102041301" "010204130101" 1 75 12  8
      "0102041302" "010204130201" 1 75  9  0
      "0102041303" "010204130301" 1  .  9  9
      "0102041401" "010204140101" 1 75  5  0
      "0102041501" "010204150101" 1 69  6  6
      "0102041601" "010204160101" 1 75  5  5
      "0102041701" "010204170101" 1 75 10  0
      "0102041702" "010204170201" 1 69  8  8
      "0102041801" "010204180101" 1 75 16 12
      "0102041901" "010204190101" 1 75 12  0
      "0102042001" "010204200101" 1 75 10 10
      "0102050101" "010205010101" 1 75 11  9
      "0102050201" "010205020101" 1 75  9  0
      "0102050301" "010205030101" 1 75 10  0
      "0102050401" "010205040101" 1 75 15  0
      "0102050501" "010205050101" 1  6  8  0
      "0102050502" "010205050201" 1 69  9  7
      "0102050601" "010205060101" 1 75  8  0
      "0102050701" "010205070101" 1 75 15  0
      "0102050801" "010205080101" 1  .  9  0
      "0102050901" "010205090101" 1 75 10 10
      "0102051001" "010205100101" 1 75  9  0
      "0102051101" "010205110101" 1 69 12  8
      "0102051201" "010205120101" 1 75 15  0
      end
      label values RO4 RO4
      label def RO4 1 "Head 1", modify
      label values RO9 RO9
      label def RO9 69 "IF Spouse/Parent outside for more than 6 months", modify
      label def RO9 75 "Dead", modify
      label values HHEDUC HHEDUC
      label def HHEDUC 0 "none 0", modify
      label def HHEDUC 2 "2nd class 2", modify
      label def HHEDUC 5 "5th class 5", modify
      label def HHEDUC 6 "6th class 6", modify
      label def HHEDUC 7 "7th class 7", modify
      label def HHEDUC 8 "8th class 8", modify
      label def HHEDUC 9 "9th class 9", modify
      label def HHEDUC 10 "Secondary 10", modify
      label def HHEDUC 11 "11th Class 11", modify
      label def HHEDUC 12 "High Secondary 12", modify
      label def HHEDUC 13 "1 year post-secondary", modify
      label def HHEDUC 14 "2 years post-secondary", modify
      label def HHEDUC 15 "Bachelors 15", modify
      label def HHEDUC 16 "Above Bachelors 16", modify
      label values ID18C ID18C
      label def ID18C 0 "none 0", modify
      label def ID18C 2 "2nd class 2", modify
      label def ID18C 3 "3rd class 3", modify
      label def ID18C 4 "4th class 4", modify
      label def ID18C 5 "5th class 5", modify
      label def ID18C 6 "6th class 6", modify
      label def ID18C 7 "7th class 7", modify
      label def ID18C 8 "8th class 8", modify
      label def ID18C 9 "9th class 9", modify
      label def ID18C 10 "Secondary 10", modify
      label def ID18C 12 "High Secondary 12", modify
      label def ID18C 16 "Above Bachelors 16", modify

      Comment


      • #4
        Thank you for your example, but it only contains people with RO4 == 1, so it is not possible to do what you ask with this example.

        Please post back with a different data example that contains several households, at least some of which contain not only an RO4 = 1 observation but also some RO4 = 3 observations. And it is best if there is also at least one household with no RO4 = 1 observation. This will permit construction and testing of code for your problem.

        Also, just to anticipate a potential problem, it is likely that the best solution to the problem will involve the use of frames. Frames first became available in version 16. If you are using a version earlier than that, please point that out when you post back so that a non-frame based solution will be shown.

        Comment


        • #5
          Thanks for your reply. I am using STATA 16.1.
          Please take a look at the below data:

          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input str10 IDHH str12 IDPERSON int(RO4 RO9 HHEDUC ID18C)
          "0102010101" "010201010101"  1 69  9  0
          "0102010101" "010201010102"  2  .  9  0
          "0102010101" "010201010103"  3  1  9  0
          "0102010101" "010201010104"  3  1  9  0
          "0102010101" "010201010105"  3  1  9  0
          "0102010101" "010201010106"  4  .  9  0
          "0102010101" "010201010107"  5  5  9  0
          "0102010101" "010201010108"  5  5  9  0
          "0102010101" "010201010109"  5  5  9  0
          "0102010201" "010201020101"  1 75 16  0
          "0102010201" "010201020102"  3  1 16  0
          "0102010201" "010201020103"  4  . 16  0
          "0102010201" "010201020104"  5  2 16  0
          "0102010201" "010201020105"  5  2 16  0
          "0102010201" "010201020106"  5  2 16  0
          "0102010201" "010201020107"  3  1 16  0
          "0102010201" "010201020108"  4  . 16  0
          "0102010201" "010201020109"  5  7 16  0
          "0102010201" "010201020110"  5  7 16  0
          "0102010201" "010201020111"  5  7 16  0
          "0102010201" "010201020112"  3  1 16  0
          "0102010201" "010201020113"  4  . 16  0
          "0102010201" "010201020114"  5 12 16  0
          "0102010201" "010201020115"  5 12 16  0
          "0102010201" "010201020116" 12  . 16  0
          "0102010301" "010201030101"  1 69 11 10
          "0102010301" "010201030102"  2  . 11 10
          "0102010301" "010201030103"  3  1 11 10
          "0102010301" "010201030104"  3  1 11 10
          "0102010301" "010201030105"  3  1 11 10
          "0102010301" "010201030106"  3  1 11 10
          "0102010301" "010201030107"  3  1 11 10
          "0102010401" "010201040101"  1 75  0  0
          "0102010401" "010201040102"  2  .  0  0
          "0102010401" "010201040103"  3  1  0  0
          "0102010401" "010201040104"  3  1  0  0
          "0102010401" "010201040105"  3  1  0  0
          "0102010501" "010201050101"  1 75  9  0
          "0102010501" "010201050102"  2  .  9  0
          "0102010501" "010201050103"  3  1  9  0
          "0102010501" "010201050104"  4  .  9  0
          "0102010501" "010201050105"  5  3  9  0
          "0102010501" "010201050106"  3  1  9  0
          "0102010501" "010201050107"  4  .  9  0
          "0102010501" "010201050108"  3  1  9  0
          "0102010501" "010201050109"  3  1  9  0
          "0102010501" "010201050110"  3  1  9  0
          "0102010601" "010201060101"  1 75  9  0
          "0102010601" "010201060102"  3  1  9  0
          "0102010601" "010201060103"  4  .  9  0
          "0102010601" "010201060104"  5  2  9  0
          "0102010601" "010201060105"  5  2  9  0
          "0102010601" "010201060106"  3  1  9  0
          "0102010601" "010201060107"  4  .  9  0
          "0102010601" "010201060108"  5  6  9  0
          "0102010601" "010201060109"  5  6  9  0
          "0102010601" "010201060110"  3  1  9  0
          "0102010601" "010201060111"  4  .  9  0
          "0102010701" "010201070101"  1 75  8  0
          "0102010701" "010201070102"  2  .  8  0
          "0102010701" "010201070103"  3  1  8  0
          "0102010701" "010201070104"  3  1  8  0
          "0102010701" "010201070105"  3  1  8  0
          "0102010701" "010201070106"  3  1  8  0
          "0102010701" "010201070107"  3  1  8  0
          "0102010701" "010201070108"  3  1  8  0
          "0102010801" "010201080101"  1  .  0  0
          "0102010801" "010201080102"  2  .  0  0
          "0102010801" "010201080103"  3  1  0  0
          "0102010801" "010201080104"  3  1  0  0
          "0102010801" "010201080105"  3  1  0  0
          "0102010801" "010201080106"  3  1  0  0
          "0102010801" "010201080107"  3  1  0  0
          "0102010801" "010201080108"  3  1  0  0
          "0102010901" "010201090101"  1  .  9  4
          "0102010901" "010201090102"  3 75  9  4
          "0102010901" "010201090103"  4  .  9  4
          "0102010901" "010201090104"  3 75  9  4
          "0102010901" "010201090105"  3 75  9  4
          "0102010901" "010201090106"  3 75  9  4
          "0102010901" "010201090107"  3 75  9  4
          "0102010901" "010201090108"  3 75  9  4
          "0102010902" "010201090201"  1 75  0  0
          "0102010902" "010201090202"  2 69  0  0
          "0102010902" "010201090203"  3  1  0  0
          "0102010902" "010201090204"  3  1  0  0
          "0102011001" "010201100101"  1 75 11  0
          "0102011001" "010201100102"  2  . 11  0
          "0102011001" "010201100103"  3  1 11  0
          "0102011001" "010201100104"  7 75 11  0
          "0102011001" "010201100105"  7 75 11  0
          "0102011001" "010201100106"  7 75 11  0
          "0102011001" "010201100107"  7 75 11  0
          "0102011001" "010201100108"  7 75 11  0
          "0102011001" "010201100109" 10  . 11  0
          "0102011001" "010201100110"  9 75 11  0
          "0102011001" "010201100111"  9 75 11  0
          "0102011001" "010201100112"  9 75 11  0
          "0102011001" "010201100113"  6  . 11  0
          "0102011101" "010201110101"  1 75  8  8
          end
          label values RO4 RO4
          label def RO4 1 "Head 1", modify
          label def RO4 2 "Wife/Husband 2", modify
          label def RO4 3 "Son/Daughter 3", modify
          label def RO4 4 "Child-in-Law 4", modify
          label def RO4 5 "Grandchild 5", modify
          label def RO4 6 "Father/Mother 6", modify
          label def RO4 7 "Brother/Sister 7", modify
          label def RO4 9 "Nephew/Niece 9", modify
          label def RO4 10 "Sib-in-Law 10", modify
          label def RO4 12 "Servant/Others 12", modify
          label values RO9 RO9
          label def RO9 69 "IF Spouse/Parent outside for more than 6 months", modify
          label def RO9 75 "Dead", modify
          label values HHEDUC HHEDUC
          label def HHEDUC 0 "none 0", modify
          label def HHEDUC 8 "8th class 8", modify
          label def HHEDUC 9 "9th class 9", modify
          label def HHEDUC 11 "11th Class 11", modify
          label def HHEDUC 16 "Above Bachelors 16", modify
          label values ID18C ID18C
          label def ID18C 0 "none 0", modify
          label def ID18C 4 "4th class 4", modify
          label def ID18C 8 "8th class 8", modify
          label def ID18C 10 "Secondary 10", modify

          Comment


          • #6
            Code:
            frame put IDHH HHEDUC if RO4 == 1, into(heads)
            frame heads {
                isid IDHH, sort
            }
            
            frlink m:1 IDHH, frame(heads)
            frget HHEDUC, from(heads) suffix(_PARENT)
            replace HHEDUC_PARENT = . if RO4 != 3
            replace HHEDUC_PARENT = ID18C if RO4 == 1

            Comment


            • #7
              The codes are working perfectly! Thankyou very much.

              Comment

              Working...
              X