Skip to content

Commit

Permalink
Merge branch 'release/v1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
mtyszler committed Jun 16, 2020
2 parents 6b9014b + 76b414a commit f21d77c
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 53 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![License: CC BY-SA 4.0](https://img.shields.io/badge/License-CC%20BY--SA%204.0-lightgrey.svg)](https://creativecommons.org/licenses/by-sa/4.0/)

## Developed by [KIT](http://www.kit.nl) and [COSA](http://thecosa.org/)
[Last update 4/5/2020]
[Last update 16/6/2020]

'kit_livingincome' provides stata ado-file to produce tables and charts of the Gap to the Living Income Benchmark

Expand All @@ -20,7 +20,7 @@ Carlos de los Rios. COSA. [email protected]

### Requirements

* Stata version 15.1
* Stata version 13

### Installing `kit_livingincome`

Expand Down
4 changes: 2 additions & 2 deletions kit_livingincome.pkg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
v 0.1
v 1.0
d 'kit_livingincome': LIVING INCOME CALCULATIONS AND OUTPUTS: stata package to produce tables and charts of the Gap to the Living Income Benchmark
d Marcelo Tyszler, PhD, KIT Royal Tropical Institute
d
Expand All @@ -11,7 +11,7 @@ d
d package maintained at:
d https://github.com/mtyszler/KIT_LivingIncome/
d
d Distribution-Date: 20200505
d Distribution-Date: 20206516
d
F kitli_gap2bm.ado
F kitli_gap2bm.sthlp
Expand Down
100 changes: 58 additions & 42 deletions kitli_compare2bm.ado
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,19 @@ To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/
-----------------------------------------------------------------------------
Last Update:
01/05/2020
16/6/2020
*****************************************************************************/

version 15.1
version 13
capture program drop kitli_compare2bm
program define kitli_compare2bm, sortpreserve
syntax varname(numeric) [if] [in], ///
hh_income(varname numeric) ///
[grouping_var(varname numeric) ///
ytitle(string) ///
spacing(real 0.02) ///
step_size(integer -1) ///
colors(string) ///
show_graph ///
show_detailed_graph ///
Expand All @@ -54,7 +55,7 @@ program define kitli_compare2bm, sortpreserve
marksample touse, novarlist

** color can only be provided if graph is requested:
if "`show_graph'" == "" & "`show_detailed_graph'" == "" & ("`colors'" !="" | "`ytitle'" !="" | `spacing' !=0.02 ) {
if "`show_graph'" == "" & "`show_detailed_graph'" == "" & ("`colors'" !="" | "`ytitle'" !="" | `spacing' !=0.02 | `step_size' != -1 ) {
display as error "WARNING: Graph options will be ignored if neither {it:show_graph} nor {it:show_detailed_graph} are requested."
}

Expand Down Expand Up @@ -91,12 +92,12 @@ program define kitli_compare2bm, sortpreserve
local li_benchmark = "`varlist'"

* key components
tempvar temp_bm_achieved
tempvar temp_bm_not_achieved
if "`grouping_var'" !="" {
qui: gen `temp_bm_achieved' = `hh_income' > `li_benchmark' if `touse' & `grouping_var' !=. & `hh_income' !=. & `li_benchmark'!=.
qui: gen `temp_bm_not_achieved' = `hh_income' < `li_benchmark' if `touse' & `grouping_var' !=. & `hh_income' !=. & `li_benchmark'!=.
}
else {
qui: gen `temp_bm_achieved' = `hh_income' > `li_benchmark' if `touse' & `hh_income' !=. & `li_benchmark'!=.
qui: gen `temp_bm_not_achieved' = `hh_income' < `li_benchmark' if `touse' & `hh_income' !=. & `li_benchmark'!=.
}

* for kernels
Expand Down Expand Up @@ -150,29 +151,44 @@ program define kitli_compare2bm, sortpreserve

********************************************
* Prepare graph:
if r(max) < = 2 {
local w = 0.1
}
else if r(max) < = 50 {
local w = 1
}
else if r(max) < = 100 {
local w = 10
}
else if r(max) < = 500 {
local w = 25
}
else if r(max) < = 1000 {
local w = 50
}
else if r(max) < = 2000 {
local w = 100
}
else if r(max) < = 5000 {
local w = 200

if `step_size' == -1 {
if r(max) < = 2 {
local w = 0.1
}
else if r(max) < = 50 {
local w = 1
}
else if r(max) < = 100 {
local w = 10
}
else if r(max) < = 500 {
local w = 25
}
else if r(max) < = 1000 {
local w = 50
}
else if r(max) < = 2000 {
local w = 100
}
else if r(max) < = 5000 {
local w = 200
}
else if r(max) < = 10000 {
local w = 1000
}
else if r(max) < = 50000 {
local w = 10000
}
else if r(max) < = 1000000 {
local w = 100000
}
else {
local w = 1000000
}
}
else {
local w = 1000
local w = `step_size'
}
local ticks_x = "xlabel(0(`w')`r(max)')"

Expand Down Expand Up @@ -272,7 +288,7 @@ program define kitli_compare2bm, sortpreserve
local this_mean = `r(mean)'
local this_median = `r(p50)'

qui: sum `temp_bm_achieved' if `grouping_var' == `group' & `touse'
qui: sum `temp_bm_not_achieved' if `grouping_var' == `group' & `touse'
local share_li = round((`r(mean)')*100,0.1)
local share_li_`counter' = ustrleft(string(`share_li'),4) + "%"

Expand All @@ -294,7 +310,7 @@ program define kitli_compare2bm, sortpreserve
pci 0 `this_mean' `h' `this_mean', color(blue) || ///
pci 0 `this_median' `h' `this_median', color(green) ///
xtitle("`hh_income_label'") ///
text(`h' `li_benchmark_`counter'' "`share_li_`counter'' above the benchmark", place(right)) ///
text(`h' `li_benchmark_`counter'' "`share_li_`counter'' below the benchmark", place(right)) ///
name("detailed_`counter'")

if "`save_graph_as'" != "" {
Expand All @@ -312,7 +328,7 @@ program define kitli_compare2bm, sortpreserve
local this_mean = `r(mean)'
local this_median = `r(p50)'

qui: sum `temp_bm_achieved' if `touse' & `grouping_var' !=.
qui: sum `temp_bm_not_achieved' if `touse' & `grouping_var' !=.
local share_li = round((`r(mean)')*100,0.1)
local share_li_`counter' = ustrleft(string(`share_li'),4) + "%"

Expand All @@ -334,7 +350,7 @@ program define kitli_compare2bm, sortpreserve
pci 0 `this_mean' `h' `this_mean', color(blue) || ///
pci 0 `this_median' `h' `this_median', color(green) ///
xtitle("`hh_income_label'") ///
text(`h' `li_benchmark_`counter'' "`share_li_`counter'' above the benchmark", place(right)) ///
text(`h' `li_benchmark_`counter'' "`share_li_`counter'' below the benchmark", place(right)) ///
name("detailed_all_groups")

if "`save_graph_as'" != "" {
Expand All @@ -351,7 +367,7 @@ program define kitli_compare2bm, sortpreserve
local this_mean = `r(mean)'
local this_median = `r(p50)'

qui: sum `temp_bm_achieved' if `touse'
qui: sum `temp_bm_not_achieved' if `touse'
local share_li = round((`r(mean)')*100,0.1)
local share_li_`counter' = ustrleft(string(`share_li'),4) + "%"

Expand All @@ -373,7 +389,7 @@ program define kitli_compare2bm, sortpreserve
pci 0 `this_mean' `h' `this_mean', color(blue) || ///
pci 0 `this_median' `h' `this_median', color(green) ///
xtitle("`hh_income_label'") ///
text(`h' `li_benchmark_`counter'' "`share_li_`counter'' above the benchmark", place(right)) ///
text(`h' `li_benchmark_`counter'' "`share_li_`counter'' below the benchmark", place(right)) ///
name("detailed")

if "`save_graph_as'" != "" {
Expand Down Expand Up @@ -441,7 +457,7 @@ program define kitli_compare2bm, sortpreserve
gettoken this_color all_colors: all_colors, parse("|")
}
local group_bm_line = "`group_bm_line' || pci 0 `li_benchmark_`counter'' `h_`counter'' `li_benchmark_`counter'', color(`this_color')"
local group_bm_box = `"`group_bm_box' text(`h_`counter'' `li_benchmark_`counter'' "Living Income `group_label': `share_li_`counter'' above", size(small) place(right) box margin(1 1 1 1) fcolor(`this_color'))"'
local group_bm_box = `"`group_bm_box' text(`h_`counter'' `li_benchmark_`counter'' "Living Income `group_label': `share_li_`counter'' below", size(small) place(right) box margin(1 1 1 1) fcolor(`this_color'))"'

local counter = `counter'+1

Expand All @@ -452,7 +468,7 @@ program define kitli_compare2bm, sortpreserve
else {
gettoken this_color all_colors: all_colors, parse("|")
local group_bm_line = " || pci 0 `li_benchmark_1' `h_1' `li_benchmark_1', color(`this_color')"
local group_bm_box = `" text(`h_1' `li_benchmark_1' "Living Income Benchmark: `share_li_1' above", size(small) place(right) box margin(1 1 1 1) fcolor(`this_color'))"'
local group_bm_box = `" text(`h_1' `li_benchmark_1' "Living Income Benchmark: `share_li_1' below", size(small) place(right) box margin(1 1 1 1) fcolor(`this_color'))"'
}


Expand All @@ -477,7 +493,7 @@ program define kitli_compare2bm, sortpreserve
* display table with results

display in b _newline
display in b "Share of observations above the Living Income Benchmark"
display in b "Share of observations below the Living Income Benchmark"

if "`grouping_var'" !="" { // show per group, than total

Expand All @@ -486,38 +502,38 @@ program define kitli_compare2bm, sortpreserve

local group_label: label (`grouping_var') `group'

qui: sum `temp_bm_achieved' if `grouping_var' == `group' & `touse'
qui: sum `temp_bm_not_achieved' if `grouping_var' == `group' & `touse'
local share_li = `r(mean)'*100
display in b ""
display in b "`group_label'"
display in b "n = `r(N)'"
display in b ""
display as text %35s "Above the Living Income Benchmark: " /*
display as text %35s "Below the Living Income Benchmark: " /*
*/ as result /*
*/ %9.1f `share_li' "%"
di as text "{hline 73}"
}

** all groups together
qui: sum `temp_bm_achieved' if `grouping_var' != . & `touse'
qui: sum `temp_bm_not_achieved' if `grouping_var' != . & `touse'
local share_li = `r(mean)'*100
display in b ""
display in b "All groups"
display in b "n = `r(N)'"
display in b ""
display as text %35s "Above the Living Income Benchmark: " /*
display as text %35s "Below the Living Income Benchmark: " /*
*/ as result /*
*/ %9.1f `share_li' "%"
di as text "{hline 73}"
}
else { // no groups

qui: sum `temp_bm_achieved' if `touse'
qui: sum `temp_bm_not_achieved' if `touse'
local share_li = `r(mean)'*100
display in b ""
display in b "n = `r(N)'"
display in b ""
display as text %35s "Above the Living Income Benchmark: " /*
display as text %35s "Below the Living Income Benchmark: " /*
*/ as result /*
*/ %9.1f `share_li' "%"
di as text "{hline 73}"
Expand Down
10 changes: 7 additions & 3 deletions kitli_compare2bm.sthlp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{smcl}
{* *! version 0.1 5may2020}{...}
{* *! version 1.0 16mjune2020}{...}

{title:Title}

Expand Down Expand Up @@ -30,7 +30,8 @@
{syntab: Graph options}

{synopt :{opt ytitle:(text)}} Text for y axis. Default "Proportion of households (%)" {p_end}
{synopt :{opt spacing:(number)}} Value for spacing between the boxes of the combined graph of all groups. Default to 0.02 {p_end}
{synopt :{opt spacing:(number)}} Value for spacing between the boxes of the combined graph of all groups. Defaults to 0.02 {p_end}
{synopt :{opt step_size:(integer)}} Value for step size in the x-axis. Defaults to a value calculated internally {p_end}
{synopt :{opt colors:(text)}} String with colors for the graph. Default "ebblue%30 | blue%30 | green%30 | orange%30" {p_end}

{syntab: Graph exporting}
Expand Down Expand Up @@ -84,7 +85,10 @@
{opt ytitle:(text)} Text for y axis. If not specified, {it:Proportion of households(%)} is shown. {p_end}

{pmore}
{opt spacing:(number)} Value for spacing between the boxes of the combined graph of all groups. Only relevant if grouping_var:(varname) is provided. Default to 0.02 {p_end}
{opt spacing:(number)} Value for spacing between the boxes of the combined graph of all groups. Only relevant if grouping_var:(varname) is provided. Defaults to 0.02 {p_end}

{pmore}
{opt step_size:(integer)} Value for step size in the x-axis. Bin size for the density calculation is set as half of this value. If ommitted, it is calculated internally. Because the internal calculation might not suit all ranges of values, the user can choose to override its value {p_end}

{pmore}
{opt colors:(text)} Colors for the curves. Multiple colors need to be separated by a "|". Default "ebblue%30 | blue%30 | green%30 | orange%30". {p_end}
Expand Down
4 changes: 2 additions & 2 deletions kitli_gap2bm.ado
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/
-----------------------------------------------------------------------------
Last Update:
05/05/2020
16/06/2020
*****************************************************************************/

version 15.1
version 13
capture program drop kitli_gap2bm
program define kitli_gap2bm, sortpreserve
syntax varname(numeric) [if] [in], ///
Expand Down
2 changes: 1 addition & 1 deletion kitli_gap2bm.sthlp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{smcl}
{* *! version 0.1 5may2020}{...}
{* *! version 1.0 16mjune2020}{...}

{title:Title}

Expand Down
2 changes: 1 addition & 1 deletion stata.toc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
v 0.1
v 1.0
d Marcelo Tyszler, PhD, KIT Royal Tropical Institute
d
d 'KIT_LIVINGINCOME': LIVING INCOME CALCULATIONS AND OUTPUTS: stata ado-file produces tables and charts of the Gap to the Living Income Benchmark
Expand Down

0 comments on commit f21d77c

Please sign in to comment.