Announcement

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

  • Creating a summary index with the weighted average of the ordinal values of a variable for one group

    Dear members of the list,

    I want to compute the average level of gender egalitarianism for each wave and country in a panel survey. The gender egalitarianism variable at the individual level is ordinal (1==low, 2==medium, 3==high). This variable is created out of the interviewee's agreement with the following statement: 'Jobs scarce: Men should have more right to a job than women', duly inverted. For instance, for a given country and wave, the distribution of the sample across levels of gender egalitarianism is as follows:
    Click image for larger version

Name:	Statalist.png
Views:	2
Size:	6.3 KB
ID:	1752551


    For the summary index I want to create, I need to consider the frequencies of each level for each wave and country; that is, how frequently the answers for values 1, 2, 3 in the gndr_eg variable above were chosen

    I suspect I have to create first a variable with the total number of respondents for each level....

    HTML Code:
    bysort cntry S020: egen gndreg_count1 = total(gndr_eg == 1)
    bysort cntry S020: egen gndreg_count2 = total(gndr_eg == 2)
    bysort cntry S020: egen gndreg_count3 = total(gndr_eg == 3)
    ....and then a weighted average of the three responses. Something like this:

    HTML Code:
    bysort cntry S020: egen av_gndr_eg = (gndr_count1+gndr_count2+ gndr_count3/ total number of cases per wave and country) * 1000
    But this last step is what I don't know how to do. I do not even know if the whole procedure is correct.

    I would appreciate any help from you.

    As previously advised in this list, I paste a sample of the data with dataex (see below). Thanks for your attention

    And best wishes

    Luis Ortiz

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(female gndr_eg) int S020
    1 1 2008
    1 1 2008
    1 1 2008
    1 1 2008
    2 1 2008
    1 1 2008
    2 2 2008
    1 1 2008
    1 3 2008
    2 1 2008
    2 1 2008
    1 1 2008
    2 3 2008
    2 1 2008
    2 3 2008
    1 1 2008
    1 1 2008
    2 1 2008
    2 1 2008
    1 1 2008
    1 3 2008
    1 1 2008
    2 1 2008
    2 1 2008
    1 1 2008
    1 1 2008
    2 3 2008
    2 1 2008
    1 1 2008
    1 1 2008
    1 1 2008
    2 2 2008
    2 1 2008
    2 1 2008
    1 1 2008
    2 1 2008
    2 2 2008
    1 1 2008
    2 1 2008
    1 3 2008
    2 1 2008
    2 1 2008
    2 1 2008
    1 1 2008
    1 1 2008
    1 1 2008
    2 1 2008
    1 1 2008
    2 1 2008
    2 1 2008
    2 1 2008
    2 1 2008
    1 1 2008
    1 1 2008
    2 1 2008
    2 1 2008
    2 1 2008
    2 1 2008
    2 1 2008
    2 1 2008
    1 1 2008
    2 1 2008
    2 1 2008
    1 1 2008
    1 1 2008
    1 1 2008
    2 1 2008
    2 1 2008
    2 1 2008
    1 1 2008
    1 1 2008
    2 1 2008
    2 1 2008
    1 1 2008
    1 1 2008
    2 1 2008
    1 1 2008
    1 1 2008
    2 1 2008
    1 1 2008
    1 1 2008
    1 1 2008
    1 1 2008
    2 1 2008
    1 1 2008
    1 1 2008
    1 1 2008
    1 1 2008
    1 1 2008
    2 1 2008
    1 1 2008
    1 1 2008
    2 1 2008
    2 1 2008
    2 1 2008
    2 1 2008
    1 1 2008
    2 1 2008
    1 1 2008
    2 1 2008
    end
    label values female X001
    label def X001 1 "Male", modify
    label def X001 2 "Female", modify
    label values S020 S020
    label def S020 2008 "       2008", modify

  • #2
    Since you have individuals in the sample, why doesn't the simple mean by country/year give you want you want?

    Comment


    • #3
      I came here to say what George Ford just said. Plus to mention another possibility:

      fraction reporting 3 MINUS fraction reporting 1 -- which is bounded by -1 and 1.

      Since there is only one country, at least by implication, and only one year, in the data example I show technique for each sex and add some test observations as proof of concept.

      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input byte(female gndr_eg) int S020
      1 1 2008
      1 1 2008
      1 1 2008
      1 1 2008
      2 1 2008
      1 1 2008
      2 2 2008
      1 1 2008
      1 3 2008
      2 1 2008
      2 1 2008
      1 1 2008
      2 3 2008
      2 1 2008
      2 3 2008
      1 1 2008
      1 1 2008
      2 1 2008
      2 1 2008
      1 1 2008
      1 3 2008
      1 1 2008
      2 1 2008
      2 1 2008
      1 1 2008
      1 1 2008
      2 3 2008
      2 1 2008
      1 1 2008
      1 1 2008
      1 1 2008
      2 2 2008
      2 1 2008
      2 1 2008
      1 1 2008
      2 1 2008
      2 2 2008
      1 1 2008
      2 1 2008
      1 3 2008
      2 1 2008
      2 1 2008
      2 1 2008
      1 1 2008
      1 1 2008
      1 1 2008
      2 1 2008
      1 1 2008
      2 1 2008
      2 1 2008
      2 1 2008
      2 1 2008
      1 1 2008
      1 1 2008
      2 1 2008
      2 1 2008
      2 1 2008
      2 1 2008
      2 1 2008
      2 1 2008
      1 1 2008
      2 1 2008
      2 1 2008
      1 1 2008
      1 1 2008
      1 1 2008
      2 1 2008
      2 1 2008
      2 1 2008
      1 1 2008
      1 1 2008
      2 1 2008
      2 1 2008
      1 1 2008
      1 1 2008
      2 1 2008
      1 1 2008
      1 1 2008
      2 1 2008
      1 1 2008
      1 1 2008
      1 1 2008
      1 1 2008
      2 1 2008
      1 1 2008
      1 1 2008
      1 1 2008
      1 1 2008
      1 1 2008
      2 1 2008
      1 1 2008
      1 1 2008
      2 1 2008
      2 1 2008
      2 1 2008
      2 1 2008
      1 1 2008
      2 1 2008
      1 1 2008
      2 1 2008
      1 3 2024
      1 3 2024
      1 3 2024
      2 1 2024
      2 1 2024
      2 1 2024
      end
      label values female X001
      label def X001 1 "Male", modify
      label def X001 2 "Female", modify
      label values S020 S020
      label def S020 2008 "       2008", modify
      
      bysort female S020 : egen wanted = mean(cond(inrange(gndr_eg, 1, 3), (gndr_eg == 3) - (gndr_eg == 1), .))
      
      tabdisp female S020, c(wanted)
      
      ------------------------------------
                |           S020          
         female |        2008         2024
      ----------+-------------------------
           Male |        -.88            1
         Female |        -.82           -1
      ------------------------------------
      More at https://www.stata.com/support/faqs/d...lity-measures/

      That FAQ really is not "frequently asked", but there you go. A notable advantage of that kind of measure is that it doesn't impute interval scale measurement. It just depends on the values being ordered.

      Comment


      • #4
        Dear George and Nick,

        Many thanks for your answers and suggestions

        George.--> "Since you have individuals in the sample, why doesn't the simple mean by country/year give you what you want?"
        My answer: It is because I want to consider also the number of people who took each answer; in the table that I pasted before (and I pasted) again, 136 individuals (out of a total of 1204) chose the less gender egalitarian answer; 157 chose the middle one and 911 chose the most gender egalitarian one. The mean that I want should account for that; would you agree?

        Click image for larger version

Name:	Statalist.png
Views:	2
Size:	6.3 KB
ID:	1752584


        Regarding the code you propose, Nick, I'm sorry I added gender ('female') in dataex. I shouldn't have done that because it's misleading. So far, I do not want the index to be separated by gender. But I definitely want a summary measure of how gender egalitarian the answers were in each country and wave... considering that a different number of people chose each option (answer). In the table above, 3 was preferred over 1, since it was chosen by 911 individuals in the sample, whereas 1 was chosen just by 136.

        Sorry if the whole comment/answer is too naif

        And thanks again for your attention

        Best wishes

        Luis Ortiz

        Comment


        • #5
          Working backwards:

          As said, I only segregated the genders to add a little variety. Otherwise your data example could only produce a single result and that would be a less stringent test of the code.

          Otherwise, it's simple. Please show us how you would calculate by hand a summary for values (1, 2, 3) and frequencies (136, 157, 911) as it's hard for me to see how what you want doesn't boil down ro a mean, which you can get directly without any messing around.
          Last edited by Nick Cox; 07 May 2024, 12:51.

          Comment


          • #6
            Many thanks, Nick

            In response to your request, the figure below captures what I would like to get.

            Click image for larger version

Name:	Statalist.png
Views:	1
Size:	3.5 KB
ID:	1752606

            This is a weighted average if I'm not wrong. In that particular case, the result is 2.63, which on a 1-3 scale, can be assumed as a good level of gender egalitarianism.

            I appreciate the link you pasted before ( https://www.stata.com/support/faqs/d...lity-measures/ ) but, as far as I have understood it, it disregards the value in the middle. I would prefer that all the values participate in the aggregate measure of gender egalitarianism I am trying to create.

            Again, many thanks for your attention

            And kind regards

            Luis Ortiz

            Comment


            • #7
              Trivially, I suggest that your denominator is wrong: the calculation is below, but mental arithmetic with the last digits alone 6 + 7 + 1 doesn't yield 9.

              Otherwise, as conjectured by George Ford and myself, you're talking about a plain mean.

              Here is the calculation done any way you want: from the frequencies, or from the complete data.

              Code:
              clear
              input freq y
              136  1
              157  2
              911  3
              end
              
              su freq
              
              di r(sum)
              
              su y [fw=freq]
              
              expand freq
              
              su y
              Code:
              . clear
              
              . input freq y
              
                        freq          y
                1. 136  1
                2. 157  2
                3. 911  3
                4. end
              
              .
              . su freq
              
                  Variable |        Obs        Mean    Std. dev.       Min        Max
              -------------+---------------------------------------------------------
                      freq |          3    401.3333    441.5092        136        911
              
              .
              . di r(sum)
              1204
              
              .
              . su y [fw=freq]
              
                  Variable |        Obs        Mean    Std. dev.       Min        Max
              -------------+---------------------------------------------------------
                         y |      1,204    2.643688    .6750155          1          3
              
              .
              . expand freq
              (1,201 observations created)
              
              .
              . su y
              
                  Variable |        Obs        Mean    Std. dev.       Min        Max
              -------------+---------------------------------------------------------
                         y |      1,204    2.643688    .6750155          1          3

              Code:
              bysort cntry S020: egen gndr_mean = mean(gndr_eg)
              is a simple way to get what you want.

              No measure will satisfy everyone. There is a whole legion out there who sit at the feet of S.S. Stevens and regard taking means of ordinal scales as wrong. (The same people usually feel happy with Spearman rank correlation, which does exactly that.)
              Last edited by Nick Cox; 07 May 2024, 16:41.

              Comment


              • #8
                Dear Nick,

                First, you were right about the denominator. It was wrong; it should have been 1204, not 1209.

                Then, you are also absolutely right that the easiest way of getting what I want is....
                HTML Code:
                bysort cntry S020: egen avg_gndr_eg = mean(gndr_eg)
                I do not know why I got so complicated in the first instance.

                My apologies for that, and thanks for your patient guidance.

                I'm truly grateful

                All the best

                Luis Ortiz

                Comment


                • #9
                  We've all been there. Sometimes you have to write down long-winded code before you can see how to write it more concisely. I wrote some commands to plot circular data such as compass directions. but the graphs looked awful if the data are just N E S W. Or if the data are just N NE ... W NW. So, I wrote a command to deal directly with 4 distinct values or 8 distinct values. Then I realised that months are just 12 distinct values on a circle, and added that case. The code kept getting longer and more awkward. Eventually I realised that just one option was needed for however many distinct values the user wants: 4, 8, 12, whatever. A general program is much shorter!

                  Comment

                  Working...
                  X