Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Shapley.ado


From   Ramani Gunatilaka <Ramani.Gunatilaka@buseco.monash.edu.au>
To   statalist@hsphsun2.harvard.edu
Subject   st: Shapley.ado
Date   Sun, 01 Feb 2004 07:11:01 +0000

Hi Stas,
Following your feedback, I tried using your ado programme to decompose the Gini coefficient. However, I don't seem to have done it right and I would be grateful for further help. I hope you will bear with me as I am a neophyte to both Stata and statistics. Computing Ginis, Lorenz curves and running consumption functions is about the sum of my achievements so far!

My code is given at the end (I have more variables but used just a few to try it out). The called programme is to calculate Gini from x, which is per capita consumption. But when I run it, I get an error message as in the following extract from the log.

Can you please tell me what I seem to be doing wrong?
Thanks so much,
Ramani
--------------------------

   - local rc=_rc
    - if `rc'~=0 {
    = if 111~=0 {
    - noi di in red "Error in the called program! " _c "
Error in the called program!     - if "`trace'"=="" {
    = if ""=="" {
    - noi di in red

    - exit `rc'
    = exit 111
      }


---------------------------- 

use shaptest, clear
keep lx  h_dage  h_male  m_adults  hhsize  unemployed  lwage_y   
qui gen n=hhsize
foreach x of varlist lx h_dage  h_male  m_adults  hhsize  unemployed  lwage_y {
gen VVV`x' = `x'
}
regress lx VVV*

shapley lx h_dage  h_male  m_adults  hhsize  unemployed  lwage_y, result(global GI) perc fromto d sto(shapstas) replace:gini @

cap prog drop gini
prog define gini

gen x=e(lx)
gsort -x
qui generate nlag=n[_n-1]
qui replace nlag=1 if nlag==.
qui gen rhoh=sum(nlag)
qui gen rhohbar=rhoh+0.5*(n-1)
qui gen nx=x*n
qui generate rhohx=nx*rhohbar
qui sum rhohx
local totrhohx=r(sum) 
qui sum n
qui gen popN=r(sum)
qui sum nx
local bigX=r(sum)
local xbar=`bigX'/popN
global GI=(popN+1)/(popN-1)-((2/(popN*(popN-1)*`xbar'))*`totrhohx')

end
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index