*! conindex 1.5 18 July 2018 *! Copyright (C) 2015 Owen O'Donnell, Stephen O'Neill, Tom Van Ourti & Brendan Walsh. *! svy option added (16 Feb 2016) *| using lorenz.ado for graphs (18 July 2018) * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see . capture program drop conindex program define conindex, rclass sortpreserve byable(recall) version 11.0 syntax varname [if] [in] [fweight aweight pweight] , [RANKvar(varname)] [, robust] [, CLUSter(varname)] [, truezero] [, LIMits(numlist min=1 max=2 missingokay)] [, generalized][, generalised] [, bounded] [, WAGstaff] [, ERReygers] [, v(string)] [,beta(string)] [, graph] [, loud] [, COMPare(varname)] [, KEEPrank(string)] [, ytitle(string)] [, xtitle(string)] [,compkeep(numlist)] [,extended] [,symmetric] [,bygroup(numlist)] [,svy] marksample touse tempname grouptest counter tempvar wght sumw cumw cumw_1 cumwr cumwr_1 frnk temp sigma2 meanlhs meanlhs_star cumlhs cumlhs1 lhs rhs1 rhs2 xmin xmax varlist_star weight1 meanweight1 tempx temp1x sumlhsx temps tempex lhsex rhs1ex rhs2ex sigma2ex exrank tempgx lhsgex lhsgexstar symrank smrankmean tempsym sigma2sym lhssym lhssymstar rhs1sym rhs2sym lhsgsym tempgxstar raw_rank_c wi_c cusum_c wj_c rank_c var_rank_c mean_c lhs_c split_c ranking extwght temp1 meanweight sumlhs sumwr counts meanoverall tempdis temp0 meanlhs2 rhs temp2 frnktest meanlhsex2 equality group lhscomp rhs1comp rhs2comp rhscomp intercept scale local weighted [`weight'`exp'] if "`weight'" != "" local weighted [`weight'`exp'] if "`weight'" == "" qui gen byte `wght' = 1 else qui gen `wght'`exp' if "`svy'"!=""{ if "`weight'" != "" { di as error "When the svy option is used, weights should only be specified using svyset." exit 498 } if "`cluster'"!="" { di as error "Warning: cluster option is redundant when using the svy option. svyset should be used to identify the survey design characteristics" } if "`robust'"!="" { di as error "Warning: robust option is redundant when using the svy option. svyset should be used to identify the survey design characteristics" } qui svyset if r(settings) == ", clear"{ di as error "svyset must be used to identify the survey design characteristics prior to running conindex with the svy option." exit 498 } local wtype = r(wtype) local wvar = r(wvar) if "`wtype'" != "." { local weighted "[`wtype' = `wvar']" qui replace `wght'=`wvar' } else replace `wght'=1 local survey "svy:" } markout `touse' `rankvar' `wght' `clus' `compare' quietly { local xxmin: word 1 of `limits' local xxmax: word 2 of `limits' if _by()==1 { if "`compare'"!="" { di as error "The option compare cannot be used in conjunction with by." exit 498 } } if "`compkeep'"=="" local bygroup = _byindex() if "`generalised'"=="generalised" local generalized="generalized" if "`extended'"!="" | "`symmetric'"!="" { di as error "Please see the help file for the correct syntax for the extended and symmetric indices" exit 498 } if "`xxmin'"=="" { scalar xmin=. } else scalar xmin=`xxmin' if "`xxmax'"=="" { scalar xmax=. } else scalar xmax=`xxmax' if "`weight'"!="" { sum `varlist' [aweight`exp'] if `touse' } else sum `varlist' if `touse' return scalar N=r(N) scalar testmean=r(mean) count if `varlist' < 0 & `touse' if r(N) > 0 { noisily disp as txt _n "Note: `varlist' has `r(N)' values less than 0" } if "`rankvar'" == "`varlist'" | "`rankvar'" ==""{ local index = "Gini" } else local index = "CI" gen double `ranking'=`varlist' if "`rankvar'" != "" { replace `ranking'=`rankvar' local label : variable label `rankvar' label variable `ranking' `"`label'"' } gen double `varlist_star'=`varlist' local CompWT_options = " `varlist'" if "`if'"!="" { local compif0="`if' & `compare'==0" local compif1="`if' & `compare'==1" } else { local compif0=" if `compare'==0" local compif1=" if `compare'==1" } forvalues i=0(1)1 { if "`weight'"!=""{ local CompWT_options`i' = "`CompWT_options' [`weight'`exp'] `compif`i'' `in'," } else local CompWT_options`i' = "`CompWT_options' `compif`i'' `in'," } if "`rankvar'"!="" { local Comp_options = "`Comp_options' rankvar(`rankvar')" } if "`cluster'"!="" { local Comp_options = "`Comp_options' cluster(`cluster')" } if xmin!=. { local Comp_options = "`Comp_options' limits(`limits')" } if "`v'"!="" { local Comp_options = "`Comp_options' v(`v')" } if "`beta'"!="" { local Comp_options = "`Comp_options' beta(`beta')" } if "`loud'"!="" { local Comp_options = "`Comp_options' loud" } if "`'"!="" { local Comp_options = "`Comp_options' " } foreach opt in robust truezero generalized bounded wagstaff erreygers svy{ if "``opt''"!="" { local Comp_options = "`Comp_options' `opt'" } } local extended=0 local symmetric=0 local modified=0 local problem=0 if "`truezero'"=="truezero" { if testmean==0 { if `problem'==0 di as err="The mean of the variable (`varlist') is 0 - the standard concentration index is not defined in this case." local problem=1 } if xmin != . { if xmin>0 { if `problem'==0 di as err="The lower bound for a ratio scale variable cannot be greater than 0." local problem=1 } } } if "`generalized'"=="generalized" { local generalized=1 } else local generalized=0 if "`truezero'"!="truezero" { if `generalized'==1 { if `problem'==0 di as err="The option truezero must be used when specifying the generalized option." local problem=1 } else local generalized=0 } if "`bounded'"!="" { if xmax==. { if `problem'==0 di as err="For bounded variables, the limits option must be specified as limits(#1 #2) where #1 is the minimum and #2 is the maximum." local problem=1 } local bounded=1 if xmin > xmax |xmin == xmax | xmin ==.{ if `problem'==0 di as err="For bounded variables, the limits option must be specified as limits(#1 #2) where #1 is the minimum and #2 is the maximum." local problem=1 } sum `varlist' if xmin!=.{ if r(min)xmax{ if `problem'==0 di as err="The variable (`varlist') takes values outside of the specified limits." local problem=1 } if r(min)>=xmin & r(max)<=xmax{ replace `varlist_star'=(`varlist'-xmin)/(xmax-xmin) } } } else local bounded=0 if "`wagstaff'"=="wagstaff" local wagstaff=1 else local wagstaff=0 if "`erreygers'"=="erreygers" local erreygers=1 else local erreygers=0 if `bounded'==0 & (`erreygers'==1| `wagstaff'==1){ di as err="Wagstaff and Erreygers Normalisations are only for use with bounded variables." di as err="Hence the bounded and limits(#1 #2) options must be used to specify the theoretical minimum (#1) and maximum (#2)." local problem=1 } if (`erreygers'==1 & `wagstaff'==1){ di as err="The option wagstaff cannot be used in conjunction with the option erreygers." local problem=1 } if "`v'"!="" { capture confirm number `v' if _rc { di as err="For the option v(#), # must be a number greater than 1." local problem=1 } if `v'<=1 & _rc==0 { di as err="For the option v(#), # must not be less than 1." local problem=1 } local extended=1 } if "`beta'"!="" { capture confirm number `beta' if _rc { di as err="For the option beta(#), # must be a number greater than 1." local problem=1 } if `beta'<=1 & _rc==0 { di as err="For the option beta(#), # must not be less than 1." local problem=1 } local symmetric=1 } if `extended'==1 & `symmetric'==1{ di as err="The option v(#) cannot be used in conjunction with the option beta(#)." local problem=1 } if (`extended'==1 | `symmetric'==1) & (`erreygers'==1| `wagstaff'==1){ di as err="Wagstaff and Erreygers Normalisations are not supported for extended/symmetric indices." local problem=1 } if (`generalized'==1) & (`erreygers'==1| `wagstaff'==1){ di as err="Cannot specify generalized in conjunction with Wagstaff or Erreygers Normalisations." local problem=1 } if xmin != . { sum `varlist' if r(min)