Announcement

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

  • DTABLE - A Few Seemingly Simple Issues

    A couple of questions that I have not been able to find an answer to. I apologize for how simple they are but, in Stata, I usually fin the simple things are the most difficult:

    1. How to remove the parentheses around the percentages shown in the table:
    dtable i.stay i.own i.agex i.fam_status i.wrkly i.foreign i.ethnic i.division [pw=asecwt], by(year, nototals) ///
    title(Title) nosample factor(, statistics(fvpercent))
    2. How to move the N to below the horizontal line at the bottom.

    Thanks,

  • #2
    Code:
    dtable i.stay i.own i.agex i.fam_status i.wrkly i.foreign i.ethnic i.division [pw=asecwt], by(year, nototals) ///
    title(Title) nosample factor(, statistics(fvpercent)) sformat("%s%%" percent fvpercent)
    

    will accomplish your first request.

    I do not know how to do the second one, but I'm confident somebody else who does will jump in.

    Comment


    • #3
      For the second question, you will have to remove the nosample option, it prevents dtable from computing the sample sizes and percentages.

      Here is some code, using the auto data, that shows how to move the N to the bottom, and change how the bottom border is drawn.
      Code:
      sysuse auto
      gen odd = mod(_n,2)
      
      dtable i.foreign, by(odd, nototals) factor(, statistics(fvpercent))
      
      * look at the layout specification
      collect layout
      * look at levels of the row specification's only dimension; note that
      * _N identifies the sample size and percent, so get all the other levels
      * of this dimension, then set the autolevels to the order you want with
      * _N last
      collect levelsof var
      local levels `"`s(levels)'"'
      local levels : subinstr local levels "_N" "", word
      collect style autolevels var `levels' _N, clear
      * replay layout
      collect layout
      
      * move the bottom border to above the N row
      collect style cell border_block[row-header item], border(bottom, pattern(none))
      collect style cell var[_N], border(top)
      * replay layout
      collect layout
      Here is the resulting table.
      Code:
      --------------------------------
                          odd
                      0          1
      --------------------------------
      Car origin
        Domestic    (70.3%)    (70.3%)
        Foreign     (29.7%)    (29.7%)
      --------------------------------
      N          37 (50.0%) 37 (50.0%)

      Comment


      • #4
        Thank you on both accounts. These details also provide good insight into these functions. Appreciate the help!

        Comment

        Working...
        X