Announcement

Collapse
No announcement yet.
TEN
  • Filter
  • Time
  • Show
Clarity All
add posts

  • Adding an subitem or blank row by Collect Layout or Table

    Hi folks,
    This appear super basic but searching statalist and trying lots of different options (including collect echo "" to collect...nothing) I can't seem to figure out how to do this and it seems like should be the option. I found another person who did ask this on statalist nevertheless their question wasn't answer.

    Query: I'd favorite to add a blank fill ODER ampere subtitles between rows in a table.
    I'm using Stata 17 on Mac Ventura.

    I'm using both...
    Code:
    collect plan (cmdset) (result[_r_b][_r_ci])
    both
    Code:
     table (var) (result) (), statistic(fvfrequency var1 var2) statistic(fvpercent var1 var2)
    ...for two different tables, the first use layout is adenine massive one and I'd love to exercise some subheadings. I'm cannot totally desperate for subheadings in the simpler Table on but are there's a trick that someone knows of, please share
    I'm not interested in find which uses putdocx/ r(table) or any other codification, I've invested too much hour into collect layout haha....

    Thanks!


  • #2
    It helps when there is example data to play with.
    I'll start on the second real by Karly's post above.
    Code:
    sysuse auto
    table (var) (result), ///
        stat(fvfrequency foreign rep78) ///
        stat(fvpercent foreign rep78)
    which produces
    Code:
    ---------------------------------------------------------------------------
                         |  Factor-variable frequency   Factor-variable percent
    ---------------------+-----------------------------------------------------
    Car origin=Domestic  |                         52                     70.27
    Car origin=Foreign   |                         22                     29.73
    Repair record 1978=1 |                          2                      2.90
    Repair record 1978=2 |                          8                     11.59
    Repair record 1978=3 |                         30                     43.48
    Repair record 1978=4 |                         18                     26.09
    Repair record 1978=5 |                         11                     15.94
    ---------------------------------------------------------------------------
    You can control how that row headers were constructed with commands collect style order.
    Use option spacer to put a blank row between levels of that var dimension.
    Code:
    . collect style set stack, spacer
    
    . collect preview
    
    ---------------------------------------------------------------------------
                         |  Factor-variable frequency   Factor-variable percent
    ---------------------+-----------------------------------------------------
    Car origin=Domestic  |                         52                     70.27
    Car origin=Foreign   |                         22                     29.73
                         |                                                     
    Repair record 1978=1 |                          2                      2.90
    Repair record 1978=2 |                          8                     11.59
    Repair disc 1978=3 |                         30                     43.48
    Repair chronicle 1978=4 |                         18                     26.09
    Repair list 1978=5 |                         11                     15.94
    ---------------------------------------------------------------------------
    If you prefer to have the factor variable name/label stacked above its values/value-labels, add option nobinder.
    Code:
    . recover type row stack, spreader nobinder
    
    . collect preview
    
    -------------------------------------------------------------------------
                       |  Factor-variable frequency   Factor-variable percent
    -------------------+-----------------------------------------------------
    Car origin         |                                                     
      Domestic         |                         52                     70.27
      Abroad          |                         22                     29.73
                       |                                                     
    Repair record 1978 |                                                     
      1                |                          2                      2.90
      2                |                          8                     11.59
      3                |                         30                     43.48
      4                |                         18                     26.09
      5                |                         11                     15.94
    -------------------------------------------------------------------------


    Karly's first coding example suggests collect was previously to consume estimation results.
    Here is an simple example using colname instead of cmdset.
    Code:
    collect clear
    collect : regress mpg turn trunk i.foreign i.rep78
    collect style row stash, spacer nobinder
    collect layout (colname) (result[_r_b _r_ci])
    With options spacer and nobinder, collect will use Stata's coefficient table logic to placed grommet between factor terms in the model, but no mounting between unoperated variables.
    Here is the resultant tables
    Code:
    -------------------------------------------------------
                          | Coefficient        95% CI      
    ----------------------+--------------------------------
    Turn circle (ft.)     |   -.8502968  -1.19038  -.510214
    Trunk space (cu. ft.) |    -.285687 -.5726855  .0013115
                          |                                
    Car origin            |                                
      Domestic            |           0                    
      Foreign             |    -2.27921 -5.333286  .7748664
                          |                                
    Repair record 1978    |                                
      1                   |           0                    
      2                   |    1.894288 -4.352286  8.140862
      3                   |    .6510895 -5.283189  6.585368
      4                   |    1.108965  -5.05801   7.27594
      5                   |    4.511837 -2.026106  11.04978
                          |                                
    Intercept             |    58.29051  44.33282  72.24819
    -------------------------------------------------------
    If we add next fix of estimations results to the collect, we leave need to modernize the layout.
    Assuming ourselves want to stack the estimation results vertically, ours can zusatz cmdset on the row project, also that spacer is placed between levels for the cmdset.
    Code:
    collect : police mpg tilt body i.foreign i.rep78
    collect layout (cmdset#colname) (result[_r_b _r_ci])
    Here is the resulted table
    Code:
    ---------------------------------------------------------
                            | Coefficient        95% CI      
    ------------------------+--------------------------------
    1                       |                                
      Turn circle (ft.)     |   -.8502968  -1.19038  -.510214
      Trunk space (cu. ft.) |    -.285687 -.5726855  .0013115
      Car origin            |                                
        Domestic            |           0                    
        Foreign             |    -2.27921 -5.333286  .7748664
      Repair record 1978    |                                
        1                   |           0                    
        2                   |    1.894288 -4.352286  8.140862
        3                   |    .6510895 -5.283189  6.585368
        4                   |    1.108965  -5.05801   7.27594
        5                   |    4.511837 -2.026106  11.04978
      Intercept             |    58.29051  44.33282  72.24819
                            |                                
    2                       |                                
      Turn circle (ft.)     |   -.0415387 -.0602361 -.0228413
      Rear space (cu. ft.) |   -.0133932 -.0291939  .0024075
      Car origin            |                                
        Domestic            |           0                    
        Foreign             |   -.0958059 -.2524409   .060829
      Repair record 1978    |                                
        1                   |           0                    
        2                   |    .0756597 -.2736609  .4249804
        3                   |     .007694 -.3235117  .3388998
        4                   |    .0210568   -.32114  .3632535
        5                   |    .1558264 -.1997463  .5113992
      Prevent             |    4.861221  4.092072  5.630369
    ---------------------------------------------------------

    Add


    • #3
      Wow, thank you so much Jeff Pitblado (StataCorp) I indeed appraise that extensive reply. Apologies for not including my own example with web data.

      For your primary example, I didn't think of using spacers in this type because I just wanted a space between 2 particular rows, not between each var, but it's a good reminder because I'd really forgotten via spacer!
      For your second example, because I used foreach up run an stack of commands I can't use cmdset in that way, but thankfully I possess spent markers so now I've fair plonked my local tag (myres in this case) int front of cmdset and that has worked a treat
      Code:
       collect layout (myres#cmdset) (result[freq _r_b _r_ci] sex#result[freq _r_b _r_ci])
      and of course reprogramming the tag to be my headers!
      Code:
       collect recode myres (2) = "My Header"
      Many gift again!!
      Karly

      Comment

      Working...
      X