Announcement

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

  • generating parents background from the child point of view

    Hi everyone,
    I am using Italian time use data. If I know exactly who is who within a family (e.g. I know if that individual is a child or a parent) and for each individual I have the level of education, is there a way to have the level of education of parents from the view point of the children? (I have one individual for each row and variables are in column).
    Thank you in advance
    Andrea

  • #2
    Hi Andrea,

    Without a snippet of your dataset, you're only gonna get general responses or guesswork. Please look at the points 12.2 (using dataex) and 12.3 (using code delimiters) of the FAQ. They will help posting your question in a way that people can help you without spending too much of your (or their, for that matter) time.

    That said, please look here for what I believe it's a similar problem with good solutions.

    Good luck!

    Comment


    • #3
      Thank you Igor for your answer,
      since my data are confidential I will post an example of it
      Code:
      clear
      input str3 family str2(individual nucleus) float(childmother father master_mom high school_mom medie_mom element_mom notit_mom)
      "010" "01" "01" 0 0 1 0 0 0 0 0
      "010" "02" "01" 0 1 0 0 0 0 0 1
      "010" "03" "01" 1 0 0 0 0 0 0 0
      "010" "04" "01" 1 0 0 0 0 0 0 0
      "011" "01" "01" 0 0 0 0 0 0 0 0
      "011" "02" "01" 0 0 0 0 0 0 0 0
      "012" "01" "01" 0 0 1 0 0 0 0 0
      "012" "02" "01" 0 1 0 1 0 0 0 0
      "012" "03" "00" 0 0 0 0 0 0 0 0
      "012" "04" "01" 1 0 0 0 0 0 0 0
      "012" "05" "01" 1 0 0 0 0 0 0 0
      "013" "01" "01" 0 0 1 0 0 0 0 0
      "013" "02" "01" 0 1 0 0 1 0 0 0
      "013" "03" "01" 0 0 0 0 0 0 0 0
      "014" "01" "01" 0 0 1 0 0 0 0 0
      "014" "02" "01" 0 1 0 0 0 0 1 0
      "014" "03" "01" 0 0 0 0 0 0 0 0
      where family is the code of the family, individual is the id of the individual within a given family, nucleus is the number of the nucleus within the family, child is a dummy thanking 1 if you are the child of that nucleus, same for mother and father and master_mom,..., notit_mom are the level of education for the mother (I put only some of the variables I have in the dataset, only those I think are important for you to understand)!
      Is there a way to have the from the view point of each child the level of education of the mother ? To be more precise, is there a way to have that master_mom takes value equal 1 in child's row?
      Thank you all in advance

      Comment


      • #4
        Hi Andrea,

        First, thanks for sending a portion of your database.

        I apologize, but couldn't find a variable pointing to if an observation (row) was the mother. There is one var (named "childmother") that I assume shows if an observation is a child (the explanation of your variables on your post and the variables in your dataset don't match 100%). Another variable (named "father") shows if an observation is the father. One could think that if not a child or father, then observation is a mother. However, if you look at family 11 on your snippet, there are 2 observations, none of which are coded 1 for "childmother" or "father". Since those are not childs nor fathers, what are they? I don't know how to interpret this.

        There seems to be something wrong with the explanation of your variables, and I feel like the variable that code if an observation is a mom is missing. I believe you might have edited the output of dataex and somethings got lost in the edition. If not, please review the meaning of your variables. You can you use expressions to limit the reach of dataex:

        Code:
        dataex family individual nucleus childmother father master_mom high school_mom medie_mom element_mom notit_mom in 1/15
        This will make dataex generate a code for your dataset only for the specified variables and only for the first 15 observations in your dataset. Please make sure the variable for mother is included.

        Your question was: "is there a way to have that master_mom takes value equal 1 in child's row?" (this is different than your previous sentence " to have the from the view point of each child the level of education of the mother", this seems to be your question indeed). I'll try to tackle both:

        First question: The code below does what you asked in the first sentence above. I created a new var (because you already have a master_mom variable created) and assigned 1 to it every time the observation is a child (under the assumption that the var "childmother" codes for that).
        Code:
        gen master_mom2= .
        replace master_mom2 = 1 if childmother == 1
        This generates a variable essentially equal to childmother.

        Second question: I created a cleaner dataset with similar vars from yours, you might be able to adapt the code below to fit your dataset. This code uses a bit of brute force (since I couldn't find a good way to copy values from one obs to another inside groups - someone might have a much better alternative than mine). This code will work for families of up to 25 people (you can increase that by changing the value in the forvalue line.

        Code:
        clear
        input float(family father mother child mom_elementary mom_highsch mom_univ)
        1 1 0 0 0 0 0
        1 0 1 0 1 0 0
        1 0 0 1 0 0 0
        2 1 0 0 0 0 0
        2 0 1 0 0 1 0
        2 0 0 1 0 0 0
        2 0 0 0 0 0 0
        3 0 1 0 0 0 1
        3 0 0 1 0 0 0
        4 0 0 1 0 0 0
        4 0 0 1 0 0 0
        4 0 1 0 1 0 0
        4 0 0 1 0 0 0
        4 1 0 0 0 0 0
        end
        
        tostring mom_elementary mom_highsch mom_univ, replace //makes all mom-education vars strings
        foreach x in mom_elementary mom_highsch mom_univ{ //replace 1 in mom-education vars with the name of the var, and 0 with missing
            replace `x' = "`x'" if `x' == "1"
            replace `x' = "" if `x'== "0"
        }
        gen master_mom = "" //creates a string master_mom variable
        replace master_mom = mom_elementary if mom_elementary != "" //replace master_mom with "mom_elementary" if "mom_elementary" is not missing
        replace master_mom = mom_highsch if mom_highsch != "" //replace master_mom with "mom_highsch" if "mom_highsch" is not missing
        replace master_mom = mom_univ if mom_univ != "" //replace master_mom with "mom_univ" if "mom_univ" is not missing
        forvalues i = 1/25{ //use subscripting and by to fill blank values for all rows (childs and fathers), copying those values from master_mom and pasting them in positions 25 lines above and below the one mom is - this is why this code only works for families of 25 people
            bysort family: replace master_mom = master_mom[_n-`i'] if missing(master_mom[_n])
            bysort family: replace master_mom = master_mom[_n+`i'] if missing(master_mom[_n])
        }
        replace master_mom = "" if child==0 // cleaning master_mom, replacing by missing all observations that are not childs. You get the educational level of moms inside families for all children

        Comment


        • #5
          Hi Igor,
          thank you a lot, I used your loop and it seems it works pretty well!
          In posting my dataset I made a mistake by missing a space: there should have been two variables ("child" & "mother") not only one as you pointed out.
          Thank you again for your help, I am new on STATA and although I tried something similar I messed up with part of the code!

          Comment

          Working...
          X