Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Create and export contingency table of sum and percentages

    Hi all,
    (On Stata 15)

    Foremost, my apologies if the question has been given an answer before, but I can’t seem to find what I’m looking for (please direct me to the conversation if that is the case).

    I’m trying to create and export a “contingency” table that would contain the n size as a sum (rather than frequency), and row or column percentages.

    * Here is an example for the dataset

    Code:
    input float obs byte month str16 salestype str66 item float support double units
    1 1 "In sales" "Baum, INTRO" 0 45
    1 2 "On sales" "Baum, INTRO" 1 36
    1 3 "In sales" "Baum, INTRO" 0 65
    1 4 "In sales" "Baum, INTRO" 0 49
    2 1 "On sales" "Gould, MATA" 1 29
    2 2 "In sales" "Gould, MATA" 0  9
    2 3 "In sales" "Gould, MATA" 0 58
    2 4 "In sales" "Gould, MATA" 0 17
    3 1 "In sales" "Thompson, BAYES"  0  6
    3 2 "In sales" "Thompson, BAYES"  0 18
    3 3 "On sales" "Thompson, BAYES"  1 36
    3 4 "On sales" "Thompson, BAYES"  1 49
    end
    label values month month
    label def month 1 "Janvier", modify
    label def month 2 "Février", modify
    label def month 3 "Mars", modify
    label def month 4 "Avril", modify
    
    label values support support
    label def support 0 "HARD BOOK", modify
    label def support 1 "ELECT BOOK", modify

    The closest thing to what I’m looking for (and can get) is the table given by:
    Code:
    table salestype month, c(sum units) row col format(%15.0g) mi
    And for extracting...
    Code:
    tabout salestype month using table1.csv, replace sum cells(sum units) f(0c) clab(_ ) mi
    Unfortunately, neither of these tables includes the percentages. Unless I’m mistaken, the tabout command does not allow the sum and percentages (it only does so for frequency and percentages).

    Without going all my attempts (which did not include putexcel), I would like to be able to make and export a table such as this one.


    Click image for larger version

Name:	Picture_Stataex2.png
Views:	1
Size:	12.5 KB
ID:	1550238


    Thank you in advance,
    Charles O.
Working...
X