Announcement

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

  • -tabout- -show(all)- and -mi- not working

    Hello all,

    First and foremost, thank you in advance to anybody that is able to help out. I tried searching Statalist and Google for a solution or something that could point me in the right direction but I have had no luck. Now to the issue.

    Version information: Stata version 15, current update level is 21 Mar 2019; tabout version 3

    Data background: This is a single year survey that has been weighted using the -svy- command. I cannot upload it or portions of it due to contractual and data sensitivity reasons.

    Issue: I am attempting to produce survey weighted cross tabulation tables which contains an outcome variable (on top of table) by 6 cross variables (rows). For some of the cross variables, none of the respondents selected a response option, but for the other cross variables they have selected all options so there are no missing data. This may be hard to visualize so I will create a fake data table below to visually show what is occurring. The -tabout- has an option of -show(all)- that should fix this issue, but is not; Stata also returns an error stating to use this option that I'm already using, but it appears to not be processing this option since it's already apart of my code. I have also tried including the -mi- option, but this doesn't work either. I have referenced the manual and I have not had any luck.

    My code
    Code:
    foreach var of varlist been_homeless {
      2.         
    .         quietly tabout age_cat female race_eth fpl region any_chronic `var' using `var'.tex, ///
    >                 show(all) cells(row) format(1) clab(Row%) ///
    >                 svy percent stats(chi2) npos(lab) ptotal(single) replace ///
    >                 style(tex) bt font(bold) topstr(18cm) topf(top.tex) botf(bot_Sweave.tex)
      3. }
    Note: There actually about 20 variables in this loop; I shortened it to a single variable that this issue occurs with for cleanliness

    Error received
    Code:
    Warning: not all panels have the same number of columns.
    Include show(all) in your syntax to view panels.
    and now for the fake table to visually show what is occuring.

    Table 1. Fake Table (Row %) - These %s are actual %s
    Homeless in past 3 years
    Yes No Don't know Refused Total
    Age
    19-35 20% 60% 2% 18% 100%
    36-49 5% 84% 0% 1% 100%
    50-64 1% 95% 2% 1% 100%
    Gender
    Male 34% 66% 0% 100%
    Female 34% 66% 0% 100%

    As one can see, the 'Refused' column shows the percentages for the 'Total' column instead of displaying 0s or being blank. When I run the code within Stata not outputting tables using -tabout-, it executes how it should. Any help trying to identify the mechanism that is causing this behavior, or a work around would be greatly appreciated.


    I apologize if I did not include something that I should have. Thank you again and I hope you have a great day!

  • #2
    Ian Watson is the author of the tabout command distributed from SSC, so he would be the definitive source of advice on this. If he does not see this topic, you could email the address shown for support in the output of ssc describe tabout and ask his advice.

    Withg that said, I believe ​​you misunderstand the show(all) option. It is not intended to fix the problem, it will simply include the tabulations that become the output tables in the log so that you can easily see how the panels differ.

    Here is a much-simplified example which may point you in a useful direction for a workaround.
    Code:
    cls
    clear
    set obs 1000
    generate y = runiformint(1,4)
    generate x1 = runiformint(1,3)
    generate x2 = runiformint(1,2) if y<4
    label define y  1 "Y=1"  2 "Y=2"  3 "Y=3"  4 "Y=4"
    label define x1 1 "X1=1" 2 "X1=2" 3 "X1=3"
    label define x2 1 "X2=1" 2 "X2=2"
    label values y  y
    label values x1 x1
    label values x2 x2
    
    tabout x1 x2 y using tabout.txt, cells(row) replace
    mvencode x2, mv(9999)
    label define x2 9999 "NA", modify
    tabout x1 x2 y using tabout.txt, cells(row) replace
    Code:
    . tabout x1 x2 y using tabout.txt, cells(row) replace
    
    Table output written to: tabout.txt
    
            y                               
            Y=1     Y=2     Y=3     Y=4     Total
            %       %       %       %       %
    x1                                      
    X1=1    21.6    23.4    30.7    24.3    100.0
    X1=2    29.7    21.2    22.1    27.1    100.0
    X1=3    23.3    26.0    26.6    24.2    100.0
    Total   24.9    23.5    26.4    25.2    100.0
    
    x2                              
    X2=1    31.5    33.3    35.2    100.0
    X2=2    35.1    29.5    35.4    100.0
    Total   33.3    31.4    35.3    100.0
    
    Warning: not all panels have the same number of columns.
    Include show(all) in your syntax to view panels.
    
    
    . mvencode x2, mv(9999)
              x2: 252 missing values recoded
    
    . label define x2 9999 "NA", modify
    
    . tabout x1 x2 y using tabout.txt, cells(row) replace
    
    Table output written to: tabout.txt
    
            y                               
            Y=1     Y=2     Y=3     Y=4     Total
            %       %       %       %       %
    x1                                      
    X1=1    21.6    23.4    30.7    24.3    100.0
    X1=2    29.7    21.2    22.1    27.1    100.0
    X1=3    23.3    26.0    26.6    24.2    100.0
    Total   24.9    23.5    26.4    25.2    100.0
    
    x2                                      
    X2=1    31.5    33.3    35.2    0.0     100.0
    X2=2    35.1    29.5    35.4    0.0     100.0
    NA      0.0     0.0     0.0     100.0   100.0
    Total   24.9    23.5    26.4    25.2    100.0
    
    .

    Comment


    • #3
      Morning William,

      Thank you for your response and the clarification of the -show(all)- option, I was wondering if my understanding of its function was incorrect and it was. I was able to find a work around. I want to clarify something I said in case somebody comes across this thread.

      Options Attempted
      1) I attempted to use the -show(all)- option to fix this issue, but as William pointed out my understanding of this option was incorrect- I point you to his explanation above for clarification.

      2) I tried using the -mi- option for the missing responses; this was also an incorrect attempt on my end. On p. 52 of the manual, link to the manual in my original post, it states that this is only a valid option for basic tables, which mine is not - it's a summary table.

      Work Around - unfortunately specific to my case
      I recognize this is not a valid route for everybody, but it worked for myself. I turned to Python since I can program in it as well; I was able to create a Python script to add a column in the output file to the rows that this issue occurred with to fix the alignment.


      Thank you again and best regards,

      Corey

      Comment

      Working...
      X