Announcement

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

  • To bring values of a variable in first row of the household and household head

    Dear Statalist,

    I am working on a survey type data, i generated a variable of school going children by assigning 0 to none going, 1 to public schools and 2 to private school.
    For further analysis i want that the value of this variable appears in the first row of Household or House hold head.
    e g data is like this
    HHcode member code School
    112 Household head .
    112 wife .
    112 Brother .
    112 son 2

    and i want it to be like this

    HHcode member code School
    112 Household head 2
    112 wife .
    112 Brother .
    112 son 2

    I have tried a number of options like gen Egen etc as i am new to stata i was unable to figure it out please help me sort out this issue.

  • #2
    Please show a data example as explained at https://www.statalist.org/forums/help#stata

    Comment


    • #3
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input double hhcode byte idc float Facit
      1111000101 1.
      1111000101 2 .
      1111000101 3 .
      1111000101 4 .
      1111000101 5 .
      1111000102 1 .
      1111000102 2 .
      1111000102 3 .
      1111000102 4 2
      1111000102 5 .
      1111000102 6 .
      1111000102 7 .
      1111000103 1 .
      1111000103 2 2
      1111000103 3 .
      1111000103 4 .
      1111000103 5 .
      1111000103 6 .
      1111000103 7 .

      end
      [/CODE]

      The Values in the bold are required to in the column in front of Idc=1 i.e 1111000102 1 2 and 1111000103 1 2.

      Comment


      • #4
        Thanks for your data example.

        This copies the maximum value found in a household to the head of household.

        Code:
        bysort hhcode : egen tocopy = max(Facit)
        bysort hhcode : gen wanted = tocopy if idc == 1
        That leaves open what you want if two or more children have non-missing values and what to do about different values (0, 1, 2).

        Comment


        • #5
          There are no different values in the data set but if there are two or more children then this issue needs to be resolved through generating another variable, Thanks for your input, I will try to sort out this issue. if no solutions found would ask help again.

          Comment


          • #6
            it's easy enough to count the number of 0 1 2 in a household's responses like this

            Code:
            foreach x in 0 1  2 { 
                egen count`x' = total(Facit == `x'), by(hhcode) 
                gen wanted`x' = count`x' if idc == 1 
            }

            Comment


            • #7
              WOW! that is really helpful Thanks Nick, i guess its like a loop command.
              what if i want to repeat a value like age of the household head in front of all columns. lets say its 30 for idc==1 and i want 30 to be in all columns of the household, What do you suggest or should i write another post for this question.
              Thanks Again you are really helpful.

              Comment


              • #8
                See material at

                https://www.stata.com/support/faqs/d...ble-recording/

                https://www.stata-journal.com/articl...article=dm0055

                Comment


                • #9
                  Thanks for your help these articles are really interesting.

                  Comment

                  Working...
                  X