Announcement

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

  • Creating a new variable

    Hello. I want to create a variable that shows average attainment at the household level. The weights for averaging across individuals within a household are defined as follows: Attainment score of individual i in the dimension under consideration divided by the total attainment score of that dimension. How can I carry it out?
    I have attached an example dataset below.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte(hh_id a total_a)
    11 4 9
    12 4 9
    13 6 9
    21 6 9
    22 6 9
    23 6 9
    31 7 9
    32 6 9
    33 5 9
    end

  • #2
    so you just want 4/9 for id 11?

    Comment


    • #3
      That will be the weight for averaging the variable 'a'. Basically, I want 4/9(4)+4/9(4)+6/9(6) for household 1, and likewise for other households.

      Comment


      • #4
        how big does hh_id get? and are there more than 9 members in a household? you're going to need a hh_id that does not include the person number.

        Comment


        • #5
          how big does hh_id get? and are there more than 9 members in a household? you're going to need a hh_id that does not include the person number.

          here's a sketch


          Code:
          tostring hh_id, g(hh_ids)   
          g hid = substr(hh_ids,1,1) //identify household, won't work when bigger than 1 digit 
          g shr = a/total_a    // create share to sum
          bys hid: egen wgt = sum(shr) //sum to weight
          drop shr

          Comment


          • #6
            Hello, George. hh_id is a concatenation of the cluster and household numbers. At max, it is a 9-digit number. And yes, there are households in the dataset with more than 9 members.

            Comment


            • #7
              you got to get a unique household id. then you can egen within that household id.

              Comment


              • #8
                Thank you, George.

                Comment

                Working...
                X