John Wyclif
John Wyclif

Reputation: 65

How to output table to LaTeX after svy: tabulate two way

I am trying to output a table to TeX after using svy: tab. Consider this example:

use https://www.stata-press.com/data/r16/nhanes2f, clear
svyset psuid [pweight=finalwgt], strata(stratid)
eststo sexrace: svy, subpop(rural): tab sex race, row percent format(%9.3g)
esttab sexrace

But this gives me only the cell percentages, not the row percentages. I ran ereturn list and it seems that these row percentages are not stored at all; they are used only to display the results.

I have also tried:

tabout sex race using table2.tex, replace c(row) layout(row) svy stats(chi2) percent

but I get different numbers.

Note: if you have not already installed estout and tabout, to run the above commands you need to install the two packages thus:

ssc install estout
ssc install tabout

Upvotes: 1

Views: 483

Answers (1)

user8682794
user8682794

Reputation:

The following works for me:

use https://www.stata-press.com/data/r16/nhanes2f, clear
svyset psuid [pweight=finalwgt], strata(stratid)

svy, subpop(rural): tab sex race, row percent format(%9.3g)

--------------------------------------
1=male,   | 1=white, 2=black, 3=other 
2=female  | White  Black  Other  Total
----------+---------------------------
     Male |  94.3   3.87   1.79    100
   Female |  96.1   2.87   .993    100
          | 
    Total |  95.2   3.37    1.4    100
--------------------------------------
  Key:  row percentage

  Pearson:
    Uncorrected   chi2(2)         =   19.0178
    Design-based  F(1.81, 52.45)  =    2.1654     P = 0.1294


tabout sex race if rural == 1 using table2.tex, style(tex) ///
replace c(row) svy stats(chi2) f(3) mult(100)

        1=white, 2=black, 3=other
        White   Black   Other   Total
        %       %       %       %
1=male, 2=female
Male    94.346  3.865   1.789   100.000
Female  96.137  2.870   0.993   100.000
Total   95.231  3.373   1.396   100.000
Pearson: Uncorrected chi2(2)= 19.018
Design-based F(1.81, 52.45)= 2.165
P-value= 0.129

Upvotes: 1

Related Questions