Announcement

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

  • dtable categories with spaces

    I'm trying to compute some summary stats by group and find categories with spaces are getting omitted. What is the correct way to go about this? Thanks!

    Code:
    clear
    set obs 3
    gen group = "Test"
    replace group = "With Space" in 2
    replace group = "More Space" in 3
    gen x = _n
    dtable x, by(group)
    gives

    Code:
    -------------------------
               group         
         Test       Total    
    -------------------------
    N 1 (33.3%)    3 (100.0%)
    x 1.000 (.) 2.000 (1.000)
    -------------------------

  • #2
    It appears to be an issue with string variables. You can alert Technical Services. As a workaround, encode the variable. Use the -label()- option to get the order that you want, or search labmask from the Stata Journal that will allow you to map the labels to a numerical variable that specifies the order.

    Code:
    clear
    set obs 3
    gen group = "Test"
    replace group = "With Space" in 2
    replace group = "More Space" in 3
    encode group, g(Group)
    gen x = _n
    dtable x, by(Gr)
    Res.:

    Code:
    . dtable x, by(Gr)
    
    -----------------------------------------------
                          Group                    
      More Space    Test   With Space     Total    
    -----------------------------------------------
    N  1 (33.3%) 1 (33.3%)  1 (33.3%)    3 (100.0%)
    x  3.000 (.) 1.000 (.)  2.000 (.) 2.000 (1.000)
    -----------------------------------------------

    Comment


    • #3
      dtable is not setting the autolevels for group correctly. We hope to fix this soon, but in the mean time you can clear the autolevels for group with
      Code:
      collect style autolevels group, clear
      and replay the table with
      Code:
      collect preview
      The levels of group should be arranged in alphabetical order, except the overall category labeled Total should still be last.

      Here is the resulting table with this work-around
      Code:
      . collect style autolevels group, clear
      
      . collect preview
      
      -----------------------------------------------
                            group                    
        More Space    Test   With Space     Total    
      -----------------------------------------------
      N  1 (33.3%) 1 (33.3%)  1 (33.3%)    3 (100.0%)
      x  3.000 (.) 1.000 (.)  2.000 (.) 2.000 (1.000)
      -----------------------------------------------

      Comment


      • #4
        Thanks both for the suggestions!

        Comment

        Working...
        X