Announcement

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

  • table y, stat(percent [x])? how does the optional variable work?

    When making tables in Stata 18 we can request a percent statistic, like "table y, stat(frequency) stat(percent)". In the help it says you can use an optional variable, like "table y, stat(frequency) stat(percent x)", but the help doesn't really give an example of this or how it would be useful. Has anyone used this varlist option for percentages in tables?

  • #2
    With auto.dta:
    Code:
    . tab foreign rep78, row
    
    +----------------+
    | Key            |
    |----------------|
    |   frequency    |
    | row percentage |
    +----------------+
    
               |                   Repair record 1978
    Car origin |         1          2          3          4          5 |     Total
    -----------+-------------------------------------------------------+----------
      Domestic |         2          8         27          9          2 |        48
               |      4.17      16.67      56.25      18.75       4.17 |    100.00
    -----------+-------------------------------------------------------+----------
       Foreign |         0          0          3          9          9 |        21
               |      0.00       0.00      14.29      42.86      42.86 |    100.00
    -----------+-------------------------------------------------------+----------
         Total |         2          8         30         18         11 |        69
               |      2.90      11.59      43.48      26.09      15.94 |    100.00
    
    . table rep78, stat(frequency)  stat(percent foreign)
    
    -----------------------------------------
                       |  Frequency   Percent
    -------------------+---------------------
    Repair record 1978 |                    
      1                |          2      0.00
      2                |          8      0.00
      3                |         30     14.29
      4                |         18     42.86
      5                |         11     42.86
      Total            |         69    100.00
    -----------------------------------------
    
    .
    That said, if the "x" variable is not dichotomous, I do not understand what the results mean:
    Code:
    . table foreign, statistic(frequency) statistic(percent rep78)
    
    ---------------------------------
               |  Frequency   Percent
    -----------+---------------------
    Car origin |                     
      Domestic |         52     61.70
      Foreign  |         22     38.30
      Total    |         74    100.00
    ---------------------------------
    I have no idea what the 61.70 and 38.30 percentages refer to.
    Last edited by Clyde Schechter; 07 Aug 2023, 15:45.

    Comment


    • #3
      From the methods and formulas section of [R] table
      proportion is computed from ratios of totals. The numerator is taken from the total for the given
      cell or cell margin, and the denominator is taken from the total for a cell margin that contains the
      given cell or cell margin.
      and separately for emphasis
      percent is proportion multiplied by 100.
      statistic(proportion) computes the cell proportion by diving the cell count by the overall count.

      statistic(proportion varname) does the same, except the totals of varname is used instead of counts.

      This gets weird (harder to explain) with weights and n-way tables.

      Consider the following examples
      Code:
      . sysuse auto
      (1978 automobile data)
      
      .
      . table rep78, stat(percent)
      
      -----------------------------
                         |  Percent
      -------------------+---------
      Repair record 1978 |        
        1                |     2.90
        2                |    11.59
        3                |    43.48
        4                |    26.09
        5                |    15.94
        Total            |   100.00
      -----------------------------
      
      . table rep78 [fw=mpg], stat(percent)
      
      -----------------------------
                         |  Percent
      -------------------+---------
      Repair record 1978 |        
        1                |     2.86
        2                |    10.42
        3                |    39.69
        4                |    26.55
        5                |    20.49
        Total            |   100.00
      -----------------------------
      
      . table rep78, stat(percent mpg)
      
      -----------------------------
                         |  Percent
      -------------------+---------
      Repair record 1978 |        
        1                |     2.86
        2                |    10.42
        3                |    39.69
        4                |    26.55
        5                |    20.49
        Total            |   100.00
      -----------------------------
      
      . table rep78 [fw=turn*mpg], stat(percent)
      
      -----------------------------
                         |  Percent
      -------------------+---------
      Repair record 1978 |        
        1                |     3.00
        2                |    11.52
        3                |    41.20
        4                |    25.62
        5                |    18.65
        Total            |   100.00
      -----------------------------
      
      . table rep78 [fw=turn], stat(percent mpg)
      
      -----------------------------
                         |  Percent
      -------------------+---------
      Repair record 1978 |        
        1                |     3.00
        2                |    11.52
        3                |    41.20
        4                |    25.62
        5                |    18.65
        Total            |   100.00
      -----------------------------
      Thus varname with statistics proportion and percent act as weights.

      Comment


      • #4
        Thank you Clyde Schechter and Jeff Pitblado (StataCorp) for answering my question. I had tried a continuous variable and did not understand the results.

        Comment

        Working...
        X