Announcement

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

  • Trouble intermingling continuous and factor variables using new "table" command with column-wise stratification variable

    I'n trying to generate a publication-ready table (LaTeX) of summary statistics over values of a stratification variable. I want the stratification variable splayed across the columns of the table, and the variables I'm summarizing split across rows of the table. The variables I want to summarize include continuous and factor variables. For the continuous variables I want to characterize the mean and standard devaiation, but for the factor variables, I just want the percentages.

    So far, all I've managed to make is something like this:

    Code:
    . sysuse auto
    (1978 automobile data)
    
    . table (var result) (foreign) , stat(mean price mpg trunk) stat(sd price mpg trunk) stat(fvpercent rep78) stat(count rep78)
    
    ---------------------------------------------------------------
                                  |            Car origin          
                                  |  Domestic    Foreign      Total
    ------------------------------+--------------------------------
    Price                         |                                
      Mean                        |  6072.423   6384.682   6165.257
      Standard deviation          |  3097.104   2621.915   2949.496
    Mileage (mpg)                 |                                
      Mean                        |  19.82692   24.77273    21.2973
      Standard deviation          |  4.743297   6.611187   5.785503
    Trunk space (cu. ft.)         |                                
      Mean                        |     14.75   11.40909   13.75676
      Standard deviation          |  4.306288   3.216906   4.277404
    Repair record 1978=1          |                                
      Factor variable percent     |      4.17       0.00       2.90
    Repair record 1978=2          |                                
      Factor variable percent     |     16.67       0.00      11.59
    Repair record 1978=3          |                                
      Factor variable percent     |     56.25      14.29      43.48
    Repair record 1978=4          |                                
      Factor variable percent     |     18.75      42.86      26.09
    Repair record 1978=5          |                                
      Factor variable percent     |      4.17      42.86      15.94
    Repair record 1978            |                                
      Number of nonmissing values |        48         21         69
    ---------------------------------------------------------------
    But what I'm trying to arrive at should look something like this:

    Code:
    -----------------------------------------------------------
                              |            Car origin          
                              |  Domestic    Foreign      Total
    --------------------------+--------------------------------
    Price                     |                                
      Mean                    |  6072.423   6384.682   6165.257
      Standard deviation      |  3097.104   2621.915   2949.496
    Mileage (mpg)             |                                
      Mean                    |  19.82692   24.77273    21.2973
      Standard deviation      |  4.743297   6.611187   5.785503
    Trunk space (cu. ft.)     |                                
      Mean                    |     14.75   11.40909   13.75676
      Standard deviation      |  4.306288   3.216906   4.277404
    Repair record 1978        |                                
      % 1                     |      4.17       0.00       2.90
      % 2                     |     16.67       0.00      11.59
      % 3                     |     56.25      14.29      43.48                     
      % 4                     |     18.75      42.86      26.09                     
      % 5                     |      4.17      42.86      15.94
      N                       |        48         21         69
    -----------------------------------------------------------
    I'd also like to sensibly format the values in the table, so there aren't excessive decimal places/significant figures displayed.

    Any suggestions how to proceed?

  • #2
    While I'm a bit late, what you want to do needs to be done after the table command using collect. I think what you need to include is something like the following which will suppress the level header for only the statistics generated with fvpercent:
    Code:
    collect style header result[fvpercent], level(hide)
    If you do not include the [fvpercent] after result then the labels for Mean and Standard deviation will also be removed


    The formatting is simpler and comes in your table command, where you might choose to use something like this:
    Code:
    nformat(%6.2f mean) nformat(%6.2f sd) sformat("%s%%" fvpercent)

    Comment

    Working...
    X