Announcement

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

  • Calculating Blau's (Herfindahl) index on ego network diversity

    Hi all,

    I've searched a few posts on this and I can't seem to quite get the code right for my dataset. I am trying to do a simple diversity index with 3 variables in an ego network. So each participant gives a list of 6 names, and then of that list I have their race of the name given (black, white, other).

    I have homogeneity scores via percent (i.e. how many names are black divided by total number of names given). But how do I translate this into a broad index that includes all three options?

    I searched some code and found:
    egen Blau = total((freq/total)^2)

    But this would only be for the frequency of one variable, right? How do I get all 3 of them in there?

    Thank you!

  • #2
    Please show us a (realistic) data example for your data.

    Comment


    • #3
      Originally posted by Nick Cox View Post
      Please show us a (realistic) data example for your data.
      Sure!

      There are up to 6 names listed for each participant so I just gave an example of some fake data here. Not everyone lists up to 6 names. So I have the percentages of black/white/other per person. I calculated that by the number of black/white/other listed by number of names given.

      But then how do I translate this into one concise diversity index where I can measure how many of each race each participant lists?
      Name1 Name2 Name3 Name4 Name5 Name6
      black white other white white white
      white black white white white
      white white white white white black
      black black black
      white black white black white

      Comment


      • #4
        Please use dataex to show us an even more realistic dataset.

        Comment


        • #5
          This takes your data example rather literally.

          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input str5(name1 name2 name3 name4 name5 name6)
          "black" "white" "other" "white" "white" "white"
          "white" "black" "white" "white" "white" ""     
          "white" "white" "white" "white" "white" "black"
          "black" "black" "black" ""      ""      ""     
          "white" "black" "white" "black" "white" ""     
          end
          
          foreach v in white black other  { 
              gen `v' = 0 
              forval j = 1/6 { 
                    replace `v' = `v' + (name`j' == "`v'")
              } 
          } 
          
          gen total = black + white + other 
          gen wanted = (white/total)^2 + (black/total)^2 + (other/total)^2 
          
          list white-wanted 
          
               +------------------------------------------+
               | white   black   other   total     wanted |
               |------------------------------------------|
            1. |     4       1       1       6         .5 |
            2. |     4       1       0       5        .68 |
            3. |     5       1       0       6   .7222222 |
            4. |     0       3       0       3          1 |
            5. |     3       2       0       5        .52 |
               +------------------------------------------+
          There are trivial adaptations should you wish to see the complementary probability or calculations on a scale up to 10000, and easy adaptations if the raw data are numeric variables with value labels.

          Comment


          • #6
            Originally posted by Nick Cox View Post
            This takes your data example rather literally.

            Code:
            * Example generated by -dataex-. For more info, type help dataex
            clear
            input str5(name1 name2 name3 name4 name5 name6)
            "black" "white" "other" "white" "white" "white"
            "white" "black" "white" "white" "white" ""
            "white" "white" "white" "white" "white" "black"
            "black" "black" "black" "" "" ""
            "white" "black" "white" "black" "white" ""
            end
            
            foreach v in white black other {
            gen `v' = 0
            forval j = 1/6 {
            replace `v' = `v' + (name`j' == "`v'")
            }
            }
            
            gen total = black + white + other
            gen wanted = (white/total)^2 + (black/total)^2 + (other/total)^2
            
            list white-wanted
            
            +------------------------------------------+
            | white black other total wanted |
            |------------------------------------------|
            1. | 4 1 1 6 .5 |
            2. | 4 1 0 5 .68 |
            3. | 5 1 0 6 .7222222 |
            4. | 0 3 0 3 1 |
            5. | 3 2 0 5 .52 |
            +------------------------------------------+
            There are trivial adaptations should you wish to see the complementary probability or calculations on a scale up to 10000, and easy adaptations if the raw data are numeric variables with value labels.
            Thank you Nick! So if I recoded my race variable to be numeric, could I use the same code? How would I change 'white black other' below to mean 1, 2, or 3?

            foreach v in white black other { gen `v' = 0 forval j = 1/6 { replace `v' = `v' + (name`j' == "`v'") } }

            Comment


            • #7
              The code assumes string variables, so must be changed if you have numeric variables instead.

              The good news is that you can tap into already existing code.

              Code:
              egen white = anycount(name*), values(1)
              egen black = anycount(name*), values(2)
              egen other = anycount(name*), values(3)

              Comment

              Working...
              X