Announcement

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

  • Calculation of Kolm–Pollack Index.

    Hello everybody!

    I.m trying to calculate the Kolm–Pollack Index of inequality for the distribution of income, which is defined as:
    Click image for larger version

Name:	r45r.png
Views:	1
Size:	8.1 KB
ID:	1496132

    where yi is the level of income for the i-th person, y-bar is its mean for the sample which consists of n individuals and the parameter 𝛼 represents the level of inequality aversion, which is determined by the analyst. Unfortunately, I haven't found any user-written command for the calculation of this index. How can I do this with code? I think that it's probably not that difficult, but since I'm a novice in stata coding, I'd like to be sure about the code.

    Really appreciate all the help I can get.

    Thanos.



  • #2
    Here is a quick sketch

    Code:
    program kpindex , rclass
        version 11.2
        syntax varname(numeric) [ if ] [ in ] , Alpha(numlist max=1 >0)
        marksample touse
        quietly count if `touse'
        if (r(N)<2) error 2000+r(N)
        tempname e K
        summarize `varlist' if `touse' , meanonly
        quietly generate double `e' = exp(`alpha'*(r(mean)-`varlist'))
        summarize `e' if `touse' , meanonly
        scalar `K' = (1/`alpha')*ln(r(mean))
        display _newline  as txt "Kolm-Pollack index = " as res `K'
        return scalar alpha = `alpha'
        return scalar K     = `K'
    end
    I have no example to certify the results. Here is an example with in the auto data

    Code:
    . sysuse auto
    (1978 Automobile Data)
    
    . kpindex price , alpha(1)
    
    Kolm-Pollack index = 456.85556
    Best
    Daniel

    Comment


    • #3
      Really appreciate it Daniel!


      I'll give it a go, but I think that the coding is correct. I believe it will also help me to figure out on my own how to calculate other inequality indices as well.


      Again, thanks a lot!


      All the best

      Thanos
      Last edited by Thanos Chantzaras; 02 May 2019, 02:13.

      Comment


      • #4
        Thanos

        you might also want to skim through [R] Inequality.

        If you prefer coding in terms of functions, you can use Mata

        Code:
        version 11.2
        mata :
        mata set matastrict on
        real scalar kolmpollak(real colvector x, real scalar alpha)
        {
            if (missing(alpha)) _error(3351)
            else if (alpha<0)   _error(3300)
            return( (1/alpha)*ln(mean(exp(alpha*(mean(x):-x)))) )
        }
        end
        which could be reduced to one line if you completely skip error-checking. Here is how you would call this function from Stata

        Code:
        sysuse auto , clear
        mata : kolmpollak(st_data(., "price"), 1)
        Best
        Daniel


        btw. I believe that the name is Pollak, not Polloack.

        Comment


        • #5
          Thank you again Daniel for all your time. Indeed, it's called the Kolm-Pollak index. It was a typo and I apologise. I was already aware of these other commands, but I really appreciate your kind suggestion.

          I'd like to ask another question if it's not too much trouble. I think that adding to the program the "by" prefix is quite straightforward with the byable option, but if I wanted an estimation using survey data, i.e. the svy prefix? Do I need to change it to eclass?

          Best
          Thanos

          Comment


          • #6
            Thanos

            svy is primarily about getting the standard errors right. You have not provided an expression for the standard errors and currently, the program does not estimate standard errors. Below is a revised version of the program that is by-able and takes weights. If you wanted (bootstrap) standard errors with the svy prefix, you would need to make the program e-class and make a couple of changes regarding the returned results.

            Code:
            program kpindex , rclass byable(recall)
                version 11.2
                syntax varname(numeric) [ if ] [ in ] ///
                [ iweight ] , Alpha(numlist max=1 >0)
                marksample touse
                quietly count if `touse'
                if (r(N)<2) error 2000+r(N)
                if (`"`weight'"' == "iweight") local weight [`weight' `exp']
                tempname e K
                summarize `varlist' if `touse' `weight' , meanonly
                quietly generate double `e' = exp(`alpha'*(r(mean)-`varlist'))
                summarize `e' if `touse' `weight' , meanonly
                scalar `K' = (1/`alpha')*ln(r(mean))
                display _newline  as txt "Kolm-Pollak index = " as res `K'
                return scalar alpha = `alpha'
                return scalar K     = `K'
            end
            Best
            Daniel

            Comment


            • #7
              Here is another try, supporting svy; without any warranty.

              Code:
              program kpindex , eclass byable(recall) properties(svyb svyj)
                  version 11.2
                  if ( !replay() ) {
                      syntax varname(numeric) [ if ] [ in ]    ///
                      [ iweight pweight fweight ]              ///
                      , Alpha(numlist max=1 >0) [ Level(cilevel) ]
                      marksample touse
                      quietly count if `touse'
                      local N = r(N)
                      if (`N'<2) error 2000+`N'
                      if (`"`weight'"' == "fweight") local wgt [fweight `exp']
                      else if (`"`weight'"' != "")   local wgt [iweight `exp']
                      tempname e K
                      summarize `varlist' if `touse' `wgt' , meanonly
                      quietly generate double `e' = exp(`alpha'*(r(mean)-`varlist'))
                      summarize `e' if `touse' `wgt' , meanonly
                      matrix `K' = (1/`alpha')*ln(r(mean))
                      matrix colnames `K' = Kolm_Pollak
                      ereturn post `K' , obs(`N') esample(`touse')
                      ereturn scalar alpha = `alpha'
                      if ("`weight'" != "") {
                          ereturn local wtype : copy local weight
                          ereturn local wexp  : copy local exp
                      }
                      ereturn local cmdline : copy local 0
                      ereturn local cmd       "kpindex"
                  }
                  else {
                      if ("`e(cmd)'" != "kpindex") error 301
                      if ( _by() )                 error 190
                      syntax [ , Level(cilevel) ]
                  }
                  ereturn display , level(`level')
              end
              Best
              Daniel
              Last edited by daniel klein; 02 May 2019, 11:13. Reason: ereturn cmdline, weight, and weight expression

              Comment


              • #8
                Thank you Daniel. I confirm that everything works just fine with my data. That is for the second (byable and iweight) version of the programme. As far as the survey estimation version is concerned, I'll try it later on

                Best
                Thanos
                Last edited by Thanos Chantzaras; 02 May 2019, 11:18.

                Comment


                • #9
                  Hello again!

                  I've just tested the svy version of the kpindex. Unfortunately, the bootstrap standard errors cannot be computed, although the program appears to work just fine. I am not quite sure how to fix this. Any help would be much appreciated.

                  Thanos
                  Last edited by Thanos Chantzaras; 17 Nov 2019, 13:30.

                  Comment


                  • #10
                    Please provide a simple example that demonstrates the problem. Your query does not contain sufficient information to make any useful suggestions.

                    Best
                    Daniel

                    Comment


                    • #11
                      Pedant's corner: please note that it should be "Pollak" (not "Pollack")

                      Comment


                      • #12
                        Originally posted by daniel klein View Post
                        Please provide a simple example that demonstrates the problem. Your query does not contain sufficient information to make any useful suggestions.

                        Best
                        Daniel
                        I apologize for your trouble Daniel. Apparently, the code works well. Unfortunately, I wasn't aware that bootstrap doesn't work with pweight, and that it needs the svy bootstrap prefix as well as to create bootstrap weight variables beforehand.


                        Best
                        Thanos
                        Last edited by Thanos Chantzaras; 19 Nov 2019, 10:37.

                        Comment

                        Working...
                        X