Announcement

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

  • Specifying Columns with Table Command

    I have a very particular format of tables for which I need to fill in statistics, and my current goal is to get as close to this format as possible using Stata17's table command functionality.

    I will use the auto.dta dataset to illustrate my situation.

    Below is the current code and output I have.

    . table rep78 foreign, stat(freq) stat(perc, across(rep78)) nformat(%9.0fc) sformat("%s%%" percent) missing total(foreign) name(new_coll) replace

    ----------------------------------------
    | Car origin
    | Domestic Foreign
    -------------------+--------------------
    Repair record 1978 |
    1 |
    Frequency | 2
    Percent | 4%
    2 |
    Frequency | 8
    Percent | 15%
    3 |
    Frequency | 27 3
    Percent | 52% 14%
    4 |
    Frequency | 9 9
    Percent | 17% 41%
    5 |
    Frequency | 2 9
    Percent | 4% 41%
    . |
    Frequency | 4 1
    Percent | 8% 5%
    Total |
    Frequency | 52 22
    Percent | 100% 100%
    ----------------------------------------




    I want the table to look like the one below essentially. I copied it from Word so I am hoping the formatting isn't terribly distorted. Basically, I want each value of the row variable to have exactly one row, so there are 4 columns with data for each row. Does anyone know how I would be able to achieve this?

    Repair Record 1978 Domestic Foreign
    # % # %
    1 % %
    2 % %
    3 % %
    4 % %
    5 % %
    Missing % %
    Total 100% 100%





  • #2
    This example might start you in a helpful direction.
    Code:
    . table (rep78) (foreign result) (), stat(freq) stat(perc, across(rep78)) total(foreign)
    
    ---------------------------------------------------------------
                       |                  Car origin               
                       |        Domestic              Foreign      
                       |  Frequency   Percent   Frequency   Percent
    -------------------+-------------------------------------------
    Repair record 1978 |                                           
      1                |          2      4.17                      
      2                |          8     16.67                      
      3                |         27     56.25           3     14.29
      4                |          9     18.75           9     42.86
      5                |          2      4.17           9     42.86
      Total            |         48    100.00          21    100.00
    ---------------------------------------------------------------

    Comment


    • #3
      William, this seems like just what I'm looking for. Thanks so much!

      Comment

      Working...
      X