Announcement

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

  • How to generate frequency table for variable that displays 0% results.

    I am generating frequency tables using the 'tab' command but values with 0% are not being displayed.

    For example the number of 'Always' Response is 0, what command will show the frequency table with the value of 'Always' and 0 frequency/percent (instead of just omitting to show only values for "Sometimes" and "Never"):


    Thanks!
    RW
    Last edited by Rebekah Wood; 13 Jun 2018, 05:36.

  • #2
    Welcome to the Stata Forum / Statalist,

    Perhaps I did not get your point, for we do have the cases with zero frequency, such as we see below:

    Code:
    . sysuse auto
    (1978 Automobile Data)
    
    . tab foreign rep78, column
    
    +-------------------+
    | Key               |
    |-------------------|
    |     frequency     |
    | column percentage |
    +-------------------+
    
               |                   Repair Record 1978
      Car type |         1          2          3          4          5 |     Total
    -----------+-------------------------------------------------------+----------
      Domestic |         2          8         27          9          2 |        48
               |    100.00     100.00      90.00      50.00      18.18 |     69.57
    -----------+-------------------------------------------------------+----------
       Foreign |         0          0          3          9          9 |        21
               |      0.00       0.00      10.00      50.00      81.82 |     30.43
    -----------+-------------------------------------------------------+----------
         Total |         2          8         30         18         11 |        69
               |    100.00     100.00     100.00     100.00     100.00 |    100.00
    Best regards,

    Marcos

    Comment


    • #3
      Hi Rebekah, dataex would help here. Please see the FAQ, specially point 12.2.

      I think you simply don't have observations with "always". If your variable accepts 3 answers ("always", "sometimes" and "never"), but only two appear on the responses ("sometimes" and "never"), Stata won't display the frequency for "always" simply because for it, this answer doesn't exist. Stata does not fill a table with 3 collumns "never", "sometimes" and "always" with the number of observations it finds, it does the opposite, it constructs a table based on the observations it finds - if a certain class is not found, it won't be present on the table.

      If this is the case, you can have a workout by encoding your variable and using the user-written tabcount command. If your variable is coded as 1, 2 and 3 (meaning "always", "sometimes" and "never"), you could then:

      Code:
      tabcount yourvar, v(1/3) zero
      You can find find tabcount using:

      Code:
      findit tabcount
      Last edited by Igor Paploski; 13 Jun 2018, 08:06.

      Comment

      Working...
      X