Since John brought up -estout-, here's a solution.
Approach 1: collect all results in a matrix and then tabulate the matrix
--- begin log ---
. local xvars "`r(xvars)'"
. local nx : list sizeof xvars
. foreach s in sf mean cv {
2. tempname `s'
3. matrix ``s'' = J(`nx'+2, 1, 1)
4. matrix rownames ``s'' = residual `r(xvars)' Total
5. forv i = 0/`nx' {
6. matrix ``s''[`i'+1, 1] = `r(`s'_Z`i')'
7. }
8. }
. matrix `cv'[rowsof(`sf'), 1] = `r(cv_tot)'
. matrix `mean'[rowsof(`mean'), 1] = `r(mean_tot)'
. matrix ineqrbd = ///
> `sf' * 100 , /// col1: 100*s_f
> `sf' * `r(cv_tot)' , /// col2: S_f
> `mean' / `r(mean_tot)' * 100, /// col3: 100*m_f/m
> `cv', /// col4: CV_f
> `cv' / `r(cv_tot)' // col5: CV_f/CV(total)
. matrix colnames ineqrbd = 100*s_f S_f 100*m_f/m CV_f CV_f/CV(total)
. estout matrix(ineqrbd)
-----------------------------------------------------------------------------
ineqrbd
100*s_f S_f 100*m_f/m CV_f CV_f/CV(to~)
-----------------------------------------------------------------------------
residual 79.95965 .1722628 -5.65e-13 -3.41e+13 -1.58e+14
aedu 15.70092 .0338256 14.98038 .5777869 2.681927
edad 7.907086 .0170348 56.25589 .3317181 1.539744
edad2 -4.37962 -.0094353 -23.43346 -.6496455 -3.015475
exper .8119627 .0017493 .535417 1.856268 8.616283
Total 100 .2154372 100 .2154372 1
-----------------------------------------------------------------------------
. esttab matrix(ineqrbd) using test1.csv // export to Excel (CSV format)
(output written to test1.csv)
--- end log ---
Click on 'test1.csv' should open the file in Excel. (Depending on the
language of your Excel you might have to specify the -scsv- option
with the last command.)
Approach 2: post the single columns as vectors in e(); this makes
tabulation more flexible
--- begin log ---
. ereturn post
. tempname tmp
. local i 0
. foreach col in s_f100 S_f m_f100 CV_f CV_ftot {
2. local ++i
3. matrix `tmp' = ineqrbd[1...,`i']'
4. quietly estadd matrix `col' = `tmp'
5. }
. ereturn list
matrices:
e(CV_ftot) : 1 x 6
e(CV_f) : 1 x 6
e(m_f100) : 1 x 6
e(S_f) : 1 x 6
e(s_f100) : 1 x 6
.
. esttab, cell("s_f100 S_f m_f100 CV_f CV_ftot") noobs
-----------------------------------------------------------------------------
(1)
s_f100 S_f m_f100 CV_f CV_ftot
-----------------------------------------------------------------------------
residual 79.95965 .1722628 -5.65e-13 -3.41e+13 -1.58e+14
aedu 15.70092 .0338256 14.98038 .5777869 2.681927
edad 7.907086 .0170348 56.25589 .3317181 1.539744
edad2 -4.37962 -.0094353 -23.43346 -.6496455 -3.015475
exper .8119627 .0017493 .535417 1.856268 8.616283
Total 100 .2154372 100 .2154372 1
-----------------------------------------------------------------------------
. esttab using test2.csv, cell("s_f100 S_f m_f100 CV_f CV_ftot") noobs
(output written to test2.csv)
--- end log ---
Here's the whole code:
--- begin code ---
prog postrres, rclass
ret local sf_Z4 = ".0081196268060714"
ret local cv_Z4 = "1.856268010856377"
ret local sd_Z4 = ".0329355355049573"
ret local mean_Z4 = ".0177428772743666"
ret local sf_Z3 = "-.0437961986553662"
ret local cv_Z3 = "-.6496454738603447"
ret local sd_Z3 = ".5044808392506561"
ret local mean_Z3 = "-.776547916593513"
ret local sf_Z2 = ".0790708585726617"
ret local cv_Z2 = ".3317180771607708"
ret local sd_Z2 = ".6183993788812"
ret local mean_Z2 = "1.864231772275365"
ret local sf_Z1 = ".1570092491099513"
ret local cv_Z1 = ".577786946494659"
ret local sd_Z1 = ".286828667617012"
ret local mean_Z1 = ".4964263546574661"
ret local sf_Z0 = ".7995964641666858"
ret local cv_Z0 = "-34099290428909.52"
ret local sd_Z0 = ".6383929043798791"
ret local mean_Z0 = "-1.87215891108e-14"
ret local cv_tot = ".2154372178269523"
ret local sd_tot = ".7139250469472358"
ret local mean_tot = "3.313842678383865"
ret local total = " loginhr"
ret local xvars = "aedu edad edad2 exper"
ret local yvar = "loginhr"
ret local varlist = "loginhr aedu edad edad2 exper"
end
postrres // post ineqrbd results for purpose of illustration
local xvars "`r(xvars)'"
local nx : list sizeof xvars
foreach s in sf mean cv {
tempname `s'
matrix ``s'' = J(`nx'+2, 1, 1)
matrix rownames ``s'' = residual `r(xvars)' Total
forv i = 0/`nx' {
matrix ``s''[`i'+1, 1] = `r(`s'_Z`i')'
}
}
matrix `cv'[rowsof(`sf'), 1] = `r(cv_tot)'
matrix `mean'[rowsof(`mean'), 1] = `r(mean_tot)'
matrix ineqrbd = ///
`sf' * 100 , /// col1: 100*s_f
`sf' * `r(cv_tot)' , /// col2: S_f
`mean' / `r(mean_tot)' * 100, /// col3: 100*m_f/m
`cv', /// col4: CV_f
`cv' / `r(cv_tot)' // col5: CV_f/CV(total)
matrix colnames ineqrbd = 100*s_f S_f 100*m_f/m CV_f CV_f/CV(total)
estout matrix(ineqrbd)
esttab matrix(ineqrbd) using test1.csv // export to Excel (CSV format)
ereturn post
tempname tmp
local i 0
foreach col in s_f100 S_f m_f100 CV_f CV_ftot {
local ++i
matrix `tmp' = ineqrbd[1...,`i']'
quietly estadd matrix `col' = `tmp'
}
ereturn list
esttab, cell("s_f100 S_f m_f100 CV_f CV_ftot") noobs
esttab using test2.csv, cell("s_f100 S_f m_f100 CV_f CV_ftot") noobs
--- end code ---
ben
On Mon, Jan 12, 2009 at 4:10 PM, Ana R. Rios <[email protected]> wrote:
> Stata users,
>
> I would like to create tables with results estimated using ineqrbd. I am particularly interested in the column "100*s_f" for "residual" and "aedu". Is there any way to do this without manipulating the following output in Excel? Any help is greatly appreciated.
>
> . ineqrbd loginhr aedu edad edad2 exper [aweight=weight] if muestraok==1, noreg
>
> Regression-based decomposition of inequality in loginhr
> ---------------------------------------------------------------------------
> Decomp. | 100*s_f S_f 100*m_f/m CV_f CV_f/CV(total)
> ---------+-----------------------------------------------------------------
> residual | 79.9596 0.1723 -0.0000 -3.41e+13 -1.58e+14
> aedu | 15.7009 0.0338 14.9804 0.5778 2.6819
> edad | 7.9071 0.0170 56.2559 0.3317 1.5397
> edad2 | -4.3796 -0.0094 -23.4335 -0.6496 -3.0155
> exper | 0.8120 0.0017 0.5354 1.8563 8.6163
> ---------+-----------------------------------------------------------------
> Total | 100.0000 0.2154 100.0000 0.2154 1.0000
> ---------------------------------------------------------------------------
> Note: proportionate contribution of composite var f to inequality of Total,
> s_f = rho_f*sd(f)/sd(Total). S_f = s_f*CV(Total).
> m_f = mean(f). sd(f) = std.dev. of f. CV_f = sd(f)/m_f.
> Total = loginhr
>
> . return list
>
> macros:
> r(sf_Z4) : ".0081196268060714"
> r(cv_Z4) : "1.856268010856377"
> r(sd_Z4) : ".0329355355049573"
> r(mean_Z4) : ".0177428772743666"
> r(sf_Z3) : "-.0437961986553662"
> r(cv_Z3) : "-.6496454738603447"
> r(sd_Z3) : ".5044808392506561"
> r(mean_Z3) : "-.776547916593513"
> r(sf_Z2) : ".0790708585726617"
> r(cv_Z2) : ".3317180771607708"
> r(sd_Z2) : ".6183993788812"
> r(mean_Z2) : "1.864231772275365"
> r(sf_Z1) : ".1570092491099513"
> r(cv_Z1) : ".577786946494659"
> r(sd_Z1) : ".286828667617012"
> r(mean_Z1) : ".4964263546574661"
> r(sf_Z0) : ".7995964641666858"
> r(cv_Z0) : "-34099290428909.52"
> r(sd_Z0) : ".6383929043798791"
> r(mean_Z0) : "-1.87215891108e-14"
> r(cv_tot) : ".2154372178269523"
> r(sd_tot) : ".7139250469472358"
> r(mean_tot) : "3.313842678383865"
> r(total) : " loginhr"
> r(xvars) : "aedu edad edad2 exper"
> r(yvar) : "loginhr"
> r(varlist) : "loginhr aedu edad edad2 exper"
>
> Thank you for your time.
>
> Regards,
>
> Ana Rios
>
>
>
>
>
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
>
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/