*! version 1.0.0 Stephen P. Jenkins, Dec 1998 STB-48 sg104 *! Decomposition of inequality of total income by *! factor components (after Shorrocks, 1982, 1984) program define ineqfac version 5.0 local varlist "req ex min(2)" local if "opt" local in "opt" local options "Stats TOTal(string) i2" local weight "aweight fweight" parse "`*'" parse "`varlist'", parse (" ") local nfac : word count `varlist' tempvar wi touse if "`weight'" == "" {ge `wi' = 1} else {ge `wi' `exp'} if "`total'" ~= "" {confirm new variable `total' } else {tempvar total} mark `touse' `if' `in' markout `touse' `varlist' set more 1 quietly { count if `touse' if _result(1) == 0 { di in red "No observations" exit } egen `total' = rsum(`varlist') if `touse' lab var `total' "Total" su `total' [w = `wi'] if `touse' local meantot = _result(3) local vartot = _result(4) local cvtot = sqrt(`vartot'/(`meantot')^2 ) noi di " " noi di in gr "Factor" _col(10) "|" _c noi di in gr _skip(3) " 100*s_f S_f" _c if "`i2'" == "" { noi di in gr _skip(3) " 100*m_f/m CV_f" _c noi di in gr _skip(3) "CV_f/CV(Total)" } else if "`i2'" ~= "" { noi di in gr _skip(3) " 100*m_f/m I2_f" _c noi di in gr _skip(3) "I2_f/I2(Total)" } noi di in gr _dup(9) "-" "+" _dup(65) "-" local i = 1 while `i' <= `nfac' { su ``i'' [w = `wi'] if `touse' local mean`i' = _result(3) local var`i' = _result(4) local cv`i' = sqrt(`var`i''/(`mean`i'')^2 ) regress ``i'' `total' [w = `wi'] if `touse' local sf`i' = _b[`total'] noi di in gr "``i''" _col(10) "|" _c noi di _skip(3) in ye %9.4f 100*`sf`i'' _c if "`i2'" == "" { noi di _skip(3) in ye %9.4f `sf`i''*`cvtot' _c noi di _skip(3) in ye %9.4f 100*`mean`i''/`meantot' _c noi di _skip(3) in ye %9.4f `cv`i'' _c noi di _skip(3) in ye %9.4f `cv`i''/`cvtot' } if "`i2'" ~= "" { noi di _skip(3) in ye %9.4f `sf`i''*.5*(`cvtot')^2 _c noi di _skip(3) in ye %9.4f 100*`mean`i''/`meantot' _c noi di _skip(3) in ye %9.4f .5*(`cv`i'')^2 _c noi di _skip(3) in ye %9.4f (`cv`i''/`cvtot')^2 } local i = `i'+1 } noi di in gr _dup(9) "-" "+" _dup(65) "-" noi di in gr "Total" _col(10) "|" _c noi di _skip(3) in ye %9.4f " 100.0000" _c if "`i2'" == "" { noi di _skip(3) in ye %9.4f `cvtot' _c noi di _skip(3) in ye %9.4f " 100.0000" _c noi di _skip(3) in ye %9.4f `cvtot' _c } if "`i2'" ~= "" { noi di _skip(3) in ye %9.4f .5*(`cvtot')^2 _c noi di _skip(3) in ye %9.4f " 100.0000" _c noi di _skip(3) in ye %9.4f .5*(`cvtot')^2 _c } noi di _skip(3) in ye %9.4f " 1.0000" noi di in gr _dup(75) "-" noi di in gr "Note: The proportionate contribution of factor" _c noi di in gr _skip(1) "f to inequality of Total," noi di in gr " s_f = rho_f*sd(f)/sd(Total)." _c if "`i2'" == "" { noi di in gr _skip(1) "S_f = s_f*CV(Total)." noi di in gr " m_f = mean(f). sd(f) = std.dev. of f." _c noi di in gr _skip(1) "CV_f = sd(f)/m_f." } if "`i2'" ~= "" { noi di in gr _skip(1) "S_f = s_f*I2(Total)." noi di in gr " m_f = mean(f). sd(f) = std.dev. of f." _c noi di in gr _skip(1) "I2_f = .5*[sd(f)/m_f]^2." } * Optionally Produce correlations, means, and std deviations if "`stats'" ~= "" { nobreak { rename `total' Total noi di " " noi di "Means, s.d.s and correlations for factors and total income" noi corr `varlist' Total [w = `wi'] if `touse', means rename Total `total' } } } /* end of quietly block */ end