PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, August 18, 2022

[FIXED] How to output table to LaTeX after svy: tabulate two way

 August 18, 2022     latex, output, stata, survey     No comments   

Issue

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

Solution

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


Answered By - user8682794
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing