如题
查了很多基尼公式,好像和这里面的都不同,请教这里的基尼系数的公式还原出来是什么样的?拜谢!!!
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