1

I'm performing decomposition analysis of socioeconomic inequality of health, and have gotten the code down, generally following the World Bank procedure. Here's the relevant part of my code.

foreach x of global X {
qui {
    sca b_`x' = _b[`x']
    corr rank `x' [aw=newweight], c
    sca cov_`x' = r(cov_12)
    sum `x' [aw=newweight]
    sca elas_`x' = (b_`x'*r(mean))/avg
    sca CI_`x' = 2*cov_`x'/r(mean)
    sca con_`x' = elas_`x'*CI_`x'
    sca prcnt_`x' = con_`x'/c
    }
di "`x' elasticity:", elas_`x'
di "`x' concentration index:", CI_`x'
di "`x' contribution:", con_`x'
di "`x' percentage contribution:", prcnt_`x'
}

Now, what I want is these final four estimates to be able to be displayed for all of my variables x in X, similar to four regression tables appended together with their coefficients. I am struggling to find how to properly "save" these estimates and call them up in esttab, tabout, table, etc. I merely display the original regression coefficients.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

2 Answers2

3
foreach x of global X {
    qui {
        sca b_`x' = _b[`x']
        corr rank `x' [aw=newweight], c
        sca cov_`x' = r(cov_12)
        sum `x' [aw=newweight], meanonly
        sca elas_`x' = (b_`x'*r(mean))/avg
        sca CI_`x' = 2*cov_`x'/r(mean)
        sca con_`x' = elas_`x'*CI_`x'
        sca prcnt_`x' = con_`x'/c
    }
    di "`x' elasticity:", elas_`x'
    di "`x' concentration index:", CI_`x'
    di "`x' contribution:", con_`x'
    di "`x' percentage contribution:", prcnt_`x'
    matrix results = nullmat(results) \ ///
                     ( elas_`x', CI_`x', con_`x', prcnt_`x')
}
matrix rownames results = $X
matrix colnames results = elasticity concentration_index ///
                          contribution percentage_contribution

Now you can feed the matrix results to whatever output program in Stata you may wish to use.

Nick Cox
  • 35,529
  • 6
  • 31
  • 47
Maarten Buis
  • 2,684
  • 12
  • 17
1

I would approach this with nlcom, post that can produce the proper e(b) and e(V) matrices that estimation formatting command such as estout can pick up. Something along the lines of

gen rank_n = rank / _N
gen rank_sq = rank_n * rank_n
foreach x of global X {
    gen cross_rank_`x' = rank_n * `x'
    gen `x'_sq = `x' * `x'

    svy : mean `x' `x'_sq rank_n rank_sq cross_rank_`x'

    nlcom ///
       (corr: (_b[cross_rank_`x']-_b[`x']*_b[rank_n]) ///
          /sqrt( (_b[`x'_sq]-_b[`x']*_b[`x'])*(_b[rank_sq]-_b[rank_n]*_b[rank_n]) ) ///
       (concentration: 2*(_b[cross_rank_`x']-_b[`x']*_b[rank_n]) / _b[`x'] )

    estout /*the way you like it*/
}

Since, as I noted in the comment, I can't tell where _b[x] is coming from, I am not sure how to wrap it into the mean and nlcom.

Also note that the use of globals is the biggest thing in Stata... at least according to the votes on SO :).

Community
  • 1
  • 1
StasK
  • 1,525
  • 10
  • 21