Announcement

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

  • dtable-frequencies only?

    I have a silly question. How do I get a table with only frequencies? I don't want the percentages in the parentheses.


    code example:

    webuse nlswork.dta, clear

    codebook race union year

    tab year

    tab year union if union == 1

    keep if year > 86

    label define yesno 0 "no" 1 "yes"
    label values union yesno


    dtable i.race i.union , by(year, nototals)

    /*

    --------------------------------------
    Interview year
    87 88
    --------------------------------------
    N 2,164 (48.8%) 2,272 (51.2%)
    Race
    White 1,572 (72.6%) 1,657 (72.9%)
    Black 567 (26.2%) 589 (25.9%)
    Other 25 (1.2%) 26 (1.1%)
    1 if union
    no 1,679 (77.7%) 1,423 (75.4%)
    yes 482 (22.3%) 465 (24.6%)
    --------------------------------------
    */

    Thank you!

  • #2
    Code:
    webuse nlswork.dta, clear
    
    codebook race union year
    
    tab year
    
    tab year union if union == 1
    
    keep if year > 86
    
    label define yesno 0 "no" 1 "yes"
    label values union yesno
    table (race) (year), nototals name(counts) replace
    table (union) (year), nototals name(counts) append
    collect layout (race union) (year)
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Running collect layout after dtable will show you the current collection. Therefore, you can also build the table from this collection.

      Code:
      webuse nlswork.dta, clear
      codebook race union year
      keep if year > 86
      label define yesno 0 "no" 1 "yes"
      label values union yesno
      qui dtable i.race i.union , by(year, nototals)
      collect layout (var) (year#result[fvfrequency])
      Res.:

      Code:
      . qui dtable i.race i.union , by(year, nototals)
      
      .
      . collect layout (var) (year#result[fvfrequency])
      
      Collection: DTable
            Rows: var
         Columns: year#result[fvfrequency]
         Table 1: 7 x 2
      
      -------------------------
                 Interview year
                    87     88  
      -------------------------
      Race                    
        White      1,572  1,657
        Black        567    589
        Other         25     26
      1 if union              
        no         1,679  1,423
        yes          482    465
      -------------------------
      Last edited by Andrew Musau; 27 Jul 2024, 08:34.

      Comment


      • #4

        To compiliment the above excellent solutions, here is how you control the factor variable statistics in the call to dtable.
        Code:
        . * sample and factor frequencies
        . dtable i.race i.union , ///
        >         sample(, statistic(frequency)) ///
        >         factor(, statistic(fvfrequency)) ///
        >         by(year, nototals)
        
        -------------------------
                   Interview year
                      87     88  
        -------------------------
        N            2,164  2,272
        Race                     
          White      1,572  1,657
          Black        567    589
          Other         25     26
        1 if union               
          no         1,679  1,423
          yes          482    465
        -------------------------
        
        . 
        . * factor frequencies only
        . dtable i.race i.union , ///
        >         nosample ///
        >         factor(, statistic(fvfrequency)) ///
        >         by(year, nototals)
        
        -------------------------
                   Interview year
                      87     88  
        -------------------------
        Race                     
          White      1,572  1,657
          Black        567    589
          Other         25     26
        1 if union               
          no         1,679  1,423
          yes          482    465
        -------------------------

        Comment


        • #5
          Thank you, Andrew and Jeff! Both those solutions worked for me!

          Comment

          Working...
          X