Announcement

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

  • Collect: Title of first column

    I would like to have a title in the first column of a table generated with collect, for example the column title "Variables":
    Code:
    ------------------------------------------------------------------------------------
    Variables      |  Yule's Y   Std. err.       z       p      N   [95% conf. interval]
    ---------------+--------------------------------------------------------------------
    rowvar, colvar |    0.6305      0.0168   37.44   0.000   4703      0.5975     0.6635
    ------------------------------------------------------------------------------------
    but not as a title of the dimensions as in version 1
    Code:
    --------------------------------------------------------------------------------------
                     |  Yule's Q   Std. err.       z       p      N   [95% conf. interval]
    -----------------+--------------------------------------------------------------------
    Variables        |                                                                    
      rowvar, colvar |    0.9023      0.0104   86.85   0.000   4703      0.8819     0.9227
    --------------------------------------------------------------------------------------
    nor as titel of the complete table as in version 2
    Code:
    Variables
    ------------------------------------------------------------------------------------
                   |  Yule's Y   Std. err.       z       p      N   [95% conf. interval]
    ---------------+--------------------------------------------------------------------
    rowvar, colvar |    0.6305      0.0168   37.44   0.000   4703      0.5975     0.6635
    ------------------------------------------------------------------------------------
    The syntax that produces these to versions (perhaps too complicated):
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str14 vars float(Q se_Q z_Q p_Q lb_Q ub_Q Y se_Y z_Y p_Y lb_Y ub_Y N)
    "rowvar, colvar" .9022996 .01038957 86.84668 0 .8819364 .9226629 .6304896 .016839812 37.440422 0 .5974842 .6634951 4703
    end
    label var vars "Variables"
    label var Q "Yule's Q"
    label var se_Q "Std. err."
    label var z_Q "z"
    label var p_Q "p"
    label var Y "Yule's Y"
    label var se_Y "Std. err."
    label var z_Y "z"
    label var p_Y "p"
    
    // Version 1:
    qui table (vars) (), statistic(first Q se_Q z_Q p_Q lb_Q ub_Q N) nototal
    collect style header vars
    collect style cell var[Q se_Q], nformat(%6.4f)
    collect style cell var[z_Q],    nformat(%9.4g)
    collect style cell var[p_Q],    nformat(%5.3f)
    qui collect recode result first = lb_Q, fortags(var[lb_Q])
    qui collect recode result first = ub_Q, fortags(var[ub_Q])
    collect style cell result[lb_Q ub_Q], nformat(%6.4f)
    collect composite define ci_Q = lb_Q ub_Q, trim delimiter("     ")
    collect label levels result ci_Q "[95% conf. interval]"
    qui collect layout (vars) (var[Q se_Q z_Q p_Q N] result[ci_Q])
    collect style header result, level(label)
    collect preview
    
    // Version 2:
    qui table (vars) (), statistic(first Y se_Y z_Y p_Y lb_Y ub_Y N) nototal
    collect style header vars, title(hide)
    collect style cell var[Y se_Y], nformat(%6.4f)
    collect style cell var[z_Y], nformat(%9.4g)
    collect style cell var[p_Y], nformat(%5.3f)
    qui collect recode result first = lb_Y, fortags(var[lb_Y])
    qui collect recode result first = ub_Y, fortags(var[ub_Y])
    collect style cell result[lb_Y ub_Y], nformat(%6.4f)
    collect composite define ci_Y = lb_Y ub_Y, trim delimiter("     ")
    collect label levels result ci_Y "[95% conf. interval]"
    qui collect layout (vars) (var[Y se_Y z_Y p_Y N] result[ci_Y])
    collect style header result, level(label)
    collect title Variables
    collect preview
    Last edited by Dirk Enzmann; 14 Aug 2026, 07:25. Reason: Minor layout corrections

  • #2
    I don't think that you can do this directly. However, you can suppress the row header and create a new column in the intended format. Here's how:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str14 vars float(Q se_Q z_Q p_Q lb_Q ub_Q Y se_Y z_Y p_Y lb_Y ub_Y N)
    "rowvar, colvar" .9022996 .01038957 86.84668 0 .8819364 .9226629 .6304896 .016839812 37.440422 0 .5974842 .6634951 4703
    end
    label var vars "Variables"
    label var Q "Yule's Q"
    label var se_Q "Std. err."
    label var z_Q "z"
    label var p_Q "p"
    label var Y "Yule's Y"
    label var se_Y "Std. err."
    label var z_Y "z"
    label var p_Y "p"
    
    
    
    // Version 2:
    collect clear
    qui table (vars) (), statistic(first Y se_Y z_Y p_Y lb_Y ub_Y N) nototal
    collect style header vars, title(hide)
    collect style cell var[Y se_Y], nformat(%6.4f)
    collect style cell var[z_Y], nformat(%9.4g)
    collect style cell var[p_Y], nformat(%5.3f)
    qui collect recode result first = lb_Y, fortags(var[lb_Y])
    qui collect recode result first = ub_Y, fortags(var[ub_Y])
    collect style cell result[lb_Y ub_Y], nformat(%6.4f)
    collect composite define ci_Y = lb_Y ub_Y, trim delimiter("     ")
    collect label levels result ci_Y "[95% conf. interval]"
    qui collect layout (vars) (var[Y se_Y z_Y p_Y N] result[ci_Y])
    collect style header result, level(label)
    collect preview
    collect get row= "rowvar, colvar", tags(vars[`"rowvar, colvar"'] var[Variables] )
    collect style cell var[Variables],smcl(text) border(right)
    collect style header vars, level(hide)
    collect layout (vars) (var[Variables Y se_Y z_Y p_Y N] result[ci_Y])
    Res.:

    Code:
    . collect get row= "rowvar, colvar", tags(vars[`"rowvar, colvar"'] var[Variables] )
    
    . collect style cell var[Variables],smcl(text) border(right)
    
    . collect style header vars, level(hide)
    
    . collect layout (vars) (var[Variables Y se_Y z_Y p_Y N] result[ci_Y])
    
    Collection: Table
          Rows: vars
       Columns: var[Variables Y se_Y z_Y p_Y N] result[ci_Y]
       Table 1: 1 x 7
    
    -------------------------------------------------------------------------------------
         Variables  |  Yule's Y   Std. err.       z       p      N   [95% conf. interval]
    ----------------+--------------------------------------------------------------------
    rowvar, colvar  |    0.6305      0.0168   37.44   0.000   4703      0.5975     0.6635
    -------------------------------------------------------------------------------------

    Comment


    • #3
      Excellent! Thank you.

      Comment

      Working...
      X