全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
13151 7
2011-05-23
如题

查了很多基尼公式,好像和这里面的都不同,请教这里的基尼系数的公式还原出来是什么样的?拜谢!!!


program ineqdeco, sortpreserve rclass

version 8.2
syntax varname(numeric) [aweight fweight] [if] [in] ///
        [, BYgroup(varname numeric) Welfare Summarize ]

if "`summarize'" != "" local summ "summ"
if "`welfare'" != ""    local w "w"
local inc "`varlist'"

tempvar fi totaly py gini wgini im1 i0 i1 i2                         ///
  nk vk fik meanyk varyk lambdak loglamk lgmeank                     ///
  thetak im1k i0k i1k i2k  ginik pyk                                 ///
  im1b i0b i1b i2b  wginik                                      ///
  ahalf a1 a2 ahalfk a1k a2k                                               ///
  whalf w1 w2 whalfk w1k w2k                                         ///
  ahalfb a1b a2b edehalfk ede1k ede2k                                  ///
  edehalf ede1 ede2 withm1 with0 withh with1 with2                      ///
  awithh awith1 awith2 wi first  
  

if "`weight'" == "" gen byte `wi' = 1
else gen `wi' `exp'

marksample touse
if "`bygroup'" != "" markout `touse' `bygroup'

qui count if `touse'
if r(N) == 0 error 2000

lab var `touse' "All obs"
lab def `touse' 1 " "
lab val `touse' `touse'

if "`bygroup'" != "" {
        capture levelsof `bygroup' if `touse' , local(gp)
        qui if _rc levels `bygroup' if `touse' , local(gp)
        foreach x of local gp {
                if int(`x') != `x' | (`x' < 0) {
                        di as error "`bygroup' contains non-integer or negative values"
                        exit 459
                }
        }
}

set more off
       
quietly {

        count if `inc' < 0 & `touse'
        noi if r(N) > 0 {
                di " "
                di as txt "Warning: `inc' has `r(N)' values < 0." _c
                di as txt " Not used in calculations"
        }
       
        count if `inc' == 0 & `touse'
        noi if r(N) > 0 {
                di " "
                di as txt "Warning: `inc' has `r(N)' values = 0." _c
                di as txt " Not used in calculations"
        }
       
        replace `touse' = 0 if `inc' <= 0  // this replaces former 'badinc' stuff

        noi if "`summ'" != "" {
                di " "
                di as txt "Summary statistics for distribution of " _c
                di as txt "`inc'" ": all valid cases"
                sum `inc' [w = `wi'] if `touse', de
        }
        else  sum `inc' [w = `wi'] if `touse', de

        foreach P in 5 10 25 50 75 90 95 {
                local p`P'  = r(p`P')
        }       
       
        local sumwi = r(sum_w)
        local meany = r(mean)
        local vary = r(Var)
        local sdy = r(sd)

        return scalar mean = r(mean)
        return scalar Var = r(Var)
        return scalar sd = r(sd)
        return scalar sumw = r(sum_w)
        return scalar N = r(N)
        return scalar min = r(min)
        return scalar max = r(max)

        foreach p in 5 10 25 50 75 90 95 {
                return scalar p`p' = r(p`p')
        }
        gen double `fi' = `wi' / `sumwi' if `touse'

        gsort -`touse' `inc'

        gen double `py' = (2 * sum(`wi') - `wi' + 1)/(2 * `sumwi' ) if `touse'

        egen double `gini' = sum(`fi'*(2 / `meany') * `py' * (`inc' - `meany')) if `touse'


更详细的code请见http://fmwww.bc.edu/repec/bocode/i/ineqdeco.ado
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2013-12-26 15:46:16
stata的help ineqdeco中有说明。
“For textbook reviews of inequality measurement from the perspective of economists, see Cowell (1995) or Jenkins (1991).”

References
Cowell, F.A. 1995.  Measuring Inequality.  Hemel Hempstead: Prentice-Hall/Harvester-Wheatsheaf.
Jenkins. S.P. 1991.  The measurement of income inequality.  In L. Osberg(ed.) Economic Inequality and Poverty: International Perspectives. Armonk, NY: M.E. Sharpe.

自习看stata的帮助稳定,里面都会有公式的来源及解释。。


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2017-9-2 13:24:33
您好,请问你现在知道ineqdeco还原出来的基尼系数公式了吗?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2018-4-6 15:04:50
yongchangzuo 发表于 2017-9-2 13:24
您好,请问你现在知道ineqdeco还原出来的基尼系数公式了吗?
clear
sysuse auto,clear
mata
y=(1\2\8\9)                                             //录入矩阵
n=rows(y)                                               //矩阵的行数
gini=sum(abs(y:- J(n,1,1)*y'))/(2*n^2*mean(y))          //计算基尼系数
gini                                                    //显示计算结果
st_store((1,4),st_addvar("int","a"),y)                  //将mata矩阵变成stata数据
y=st_data(.,"price")                                    //调入stata数据
sum(abs(y:- J(rows(y),1,1)*y'))/(2*rows(y)^2*mean(y))   //计算price
end                                                     //退出mata
ssc install ineqdeco                                    //下载计算gini系数的命令,下载一次即可
ineqdeco   a                                            //用命令直接计算(1,2,8,9)的基尼系数
ineqdeco  price                                         //用命令直接计算price的基尼系数
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2018-4-6 15:06:21
Angelina_RUCER 发表于 2018-4-6 15:04
clear
sysuse auto,clear
mata
第六行计算基尼系数的公式等同于命令ineqdeco
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2018-5-1 19:55:24
Angelina_RUCER 发表于 2018-4-6 15:06
第六行计算基尼系数的公式等同于命令ineqdeco
嗯嗯,谢谢啦
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群