The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Topics » Wealth Index » Gini - Income Inequality
Gini - Income Inequality [message #2727] Fri, 15 August 2014 18:12 Go to next message
ahmed89o is currently offline  ahmed89o
Messages: 26
Registered: August 2013
Location: Germany
Member
Dear DHS team,
I have noted that in your recent reports you start to provide Gini by City. I am assuming you have built using wealth index. I would like to kindly ask you to share with your do file for stata on how to develop Gini by city so I can run for older surveys. All the best,
Re: Gini - Income Inequality [message #2731 is a reply to message #2727] Sun, 17 August 2014 23:54 Go to previous messageGo to next message
Trevor-DHS is currently offline  Trevor-DHS
Messages: 802
Registered: January 2013
Senior Member
Dear Ahmed89o

Unfortunately we do not have a Stata do file for calculating the Gini coefficient. We use CSPro for producing the tabulations for the DHS reports, and the code is written in CSPro.

You can find an explanation of the calculation of the Gini coefficient in the DHS6 tabulation plan ( http://www.dhsprogram.com/pubs/pdf/DHSM6/Final_Report_Tab_Pl an_05June2013_DHSM6.pdf) starting on page 12.
Re: Gini - Income Inequality [message #2733 is a reply to message #2731] Mon, 18 August 2014 04:38 Go to previous messageGo to next message
ahmed89o is currently offline  ahmed89o
Messages: 26
Registered: August 2013
Location: Germany
Member
Dear DHS team,
I have looked at the report and it explains the idea of Gini. But I want to be informed how did you deal with negative values in wealth index. What kind of transformation did you use? Can you please share the code of cspro and I will try to use it? I will try to download it and replicate your estimates.
Re: Gini - Income Inequality [message #2892 is a reply to message #2731] Sun, 07 September 2014 15:44 Go to previous messageGo to next message
ahmed89o is currently offline  ahmed89o
Messages: 26
Registered: August 2013
Location: Germany
Member
Dear Dhs team,
I have not answer regarding my second post. I would like how you death with negative values on the wealth index to build gini
Re: Gini - Income Inequality [message #2899 is a reply to message #2892] Mon, 08 September 2014 12:49 Go to previous messageGo to next message
Trevor-DHS is currently offline  Trevor-DHS
Messages: 802
Registered: January 2013
Senior Member
Here is some code for calculating the Gini coefficient. To run this for subgroups, drop the cases not needed - see example:

use "BDHR61FL.DTA", clear

* Use a selection here to run this for a specific subgroup
* e.g. for urban
* drop if hv025!=1

* Summarize and get the minimum and the maximum
quietly summ hv271
local w_min = r(min)
local w_max = r(max)

* Calculating the range
local w_range = `w_max' - `w_min'
* Create 100 groups
gen w_group = int( (hv271-`w_min') / (`w_range'/(100-1)) ) + 1
* Transformed wealth score - 0 based
gen wscore_trans = hv271 - `w_min'

* Summarize by the 100 groups
collapse (sum) pop=hv012 ws=wscore_trans [pw=hv005/1000000], by(w_group)

* Accumulate population and wealth scores across groups
gen pop_accum = pop
replace pop_accum = pop_accum[_n-1] + pop if _n>1
gen wdx_accum = ws
replace wdx_accum = wdx_accum[_n-1] + ws if _n>1

* Sum total population and total wealth scores
quietly summ pop
local pop_tot = r(sum)
quietly summ ws
local wdx_tot = r(sum)

* Calculate proportion in each group for population and wealth
gen pop_prop = pop_accum / `pop_tot'
gen wdx_prop = wdx_accum / `wdx_tot'

* Calculate Gini coefficient elements
gen gini = (pop_prop - pop_prop[_n-1]) * (wdx_prop + wdx_prop[_n-1]) if _n>1

* Gini coefficient is 1 - sum of elements, multiplied by 100 to be a percentage
quietly summ gini
local gini_coeff 100 * (1 - r(sum))
di "Gini coefficient: " `gini_coeff'
Re: Gini - Income Inequality [message #2908 is a reply to message #2899] Tue, 09 September 2014 05:12 Go to previous messageGo to next message
ahmed89o is currently offline  ahmed89o
Messages: 26
Registered: August 2013
Location: Germany
Member
Thanks a million Trevor for this. In case I want to get gini by city or governorate. It seems to me I can simply run the do file on each city or governorate or subsample separately, right?

[Updated on: Tue, 09 September 2014 05:17]

Report message to a moderator

Re: Gini - Income Inequality [message #2910 is a reply to message #2908] Tue, 09 September 2014 10:29 Go to previous messageGo to next message
Trevor-DHS is currently offline  Trevor-DHS
Messages: 802
Registered: January 2013
Senior Member
You can use the drop command in the 5th line. So, if you wanted to produce an estimate just for urban areas, drop those areas that are not urban with
drop hv025!=1
If you wanted just the second governorate, for example, use
drop hv024!=2

I could probably make the code work to produce the Gini coefficient by background variables, but it would take rewriting the code in a different way - not using summarize and not using the locals - but it seems easy enough just to add in the drop to select the cases you want.
Re: Gini - Income Inequality [message #9243 is a reply to message #2910] Fri, 26 February 2016 07:26 Go to previous messageGo to next message
schoumaker is currently offline  schoumaker
Messages: 65
Registered: May 2013
Location: Belgium
Senior Member
Thanks a lot for providing this code. For information, the ineqdeco Stata command can also be used to compute the Gini index. This gives the same results as Trevor's syntax.
Best,
Bruno


Bruno Schoumaker
Centre for Demographic Research
Université catholique de Louvain
Re: Gini - Income Inequality [message #9557 is a reply to message #2727] Fri, 15 April 2016 12:50 Go to previous messageGo to next message
ttuti is currently offline  ttuti
Messages: 4
Registered: March 2016
Member
Is it possible to get the formula to generate the GINI coefficient in a software independent kind of way? Having a difficult time translating this Stata code into R equivalent. I am trying to calculate the GINI coefficient using the entire country sample and in RStudio (R). Any help is welcomed.
Re: Gini - Income Inequality [message #9566 is a reply to message #2727] Mon, 18 April 2016 14:12 Go to previous messageGo to next message
Trevor-DHS is currently offline  Trevor-DHS
Messages: 802
Registered: January 2013
Senior Member
See the DHS tabulation plan, pages 12-13 for an explanation of the Gini index and its calculation.
Re: Gini - Income Inequality [message #12517 is a reply to message #2731] Thu, 01 June 2017 08:49 Go to previous messageGo to next message
r01efa16
Messages: 10
Registered: November 2016
Location: UK
Member

Hello

This file is no longer available

Please I need the code and steps to run the command in STATA

Thanks in advance
Re: Gini - Income Inequality [message #12518 is a reply to message #12517] Thu, 01 June 2017 12:26 Go to previous message
Trevor-DHS is currently offline  Trevor-DHS
Messages: 802
Registered: January 2013
Senior Member
For the file you say is not available, which file is that? If you mean the DHS tabulation plan, pages 12-13, the link still works fine for me - can you test the link again.

The Stata code is already shown in this thread, so I'm not sure what else you need.
Previous Topic: Construction
Next Topic: Error detected (Zimbabwe 2010-11)
Goto Forum:
  


Current Time: Thu Oct 10 18:57:43 Coordinated Universal Time 2024