amo
amo

Reputation: 3200

Return stored results with svy and tab command in Stata

I would like to put column percentages into an excel file. The first step therefore would be to capture the percentages (or counts if not possible for percentages) into a matrix and then post the values into excel using putexcel. I can not use the matcell and matrow option with svy: tab so I attempted to check the stored results using e(name). The issue I am facing is how to capture the values from the following tabulation into a matrix:

webuse nhanes2b, clear
svyset psuid [pweight=finalwgt], strata(stratid)
svy: tabulate sex race , format(%11.3g) percent 
--------------------------------------
1=male,   | 1=white, 2=black, 3=other 
2=female  | White  Black  Other  Total
----------+---------------------------
     Male |  42.3   4.35   1.33   47.9
   Female |  45.7    5.2    1.2   52.1
          | 
    Total |  87.9   9.55   2.53    100
--------------------------------------
  Key:  cell percentages

I would like to put the values above in a matrix. I tried the following which worked:

mat pct = e(b)' * 100
matrix list pct

pct[6,1]
            y1
p11  42.254909
p12  4.3497373
p13  1.3303765
p21  45.660537
p22  5.2008547
p23  1.2035865

But what I am interested in is the column percentages given by the following tabulation:

svy: tabulate sex race , format(%11.3g) col percent 

--------------------------------------
1=male,   | 1=white, 2=black, 3=other 
2=female  | White  Black  Other  Total
----------+---------------------------
     Male |  48.1   45.5   52.5   47.9
   Female |  51.9   54.5   47.5   52.1
          | 
    Total |   100    100    100    100
--------------------------------------
  Key:  column percentages

I tried this which did not return the desired values in the table above:

mat pct = e(b)' * 100
matrix list pct
pct[6,1]
            y1
p11  42.254909
p12  4.3497373
p13  1.3303765
p21  45.660537
p22  5.2008547
p23  1.2035865

After checking through various stored objects using ereturn list I did not seem to find anything corresponding to column percentages. How can I get the column percentages into a matrix?

Upvotes: 4

Views: 3151

Answers (1)

ℕʘʘḆḽḘ
ℕʘʘḆḽḘ

Reputation: 19395

easy peasy

ssc install estout
webuse nhanes2b, clear
estpost svy: tabulate race diabetes, row percent
esttab .  using "C:/table.csv", b(2) se(2) scalars(F_Pear) nostar unstack mtitle(`e(colvar)')

see also here http://repec.org/bocode/e/estout/hlp_estpost.html#svy_tabulate

Upvotes: 4

Related Questions