Announcement

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

  • Append tables with collect

    Hi, i'm dealing with this append and i can't detect the error. The problem is that the collect gives me a table with dim 8*12 because it places the percentages as new columns, when what I need is for the percentages to be below the frequencies.

    table tra_ola1 tra_ola4, ///
    stat(frequency) stat(percent, across(tra_ola4)) nototal sformat("%s%%" percent)
    table tra_ola3 tra_ola4, ///
    stat(frequency) stat(percent, across(tra_ola4)) nototal sformat("%s%%" percent) append

    collect style header result, level(hide)
    collect style cell, empty(0)
    collect style tex, nocentering
    collect levelsof result
    collect layout (tra_ola1 tra_ola3) (result#tra_ola4)
    collect preview

    . dataex tra_ola1 tra_ola3 tra_ola4 in 1/100 if tra_tra1 != .

    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(tra_ola1 tra_ola3 tra_ola4)
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    0 3 3
    1 1 5
    0 3 3
    1 1 5
    0 3 3
    1 1 5
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    end
    label values tra_ola1 tra_ola1
    label def tra_ola1 0 "No ola 1", modify
    label def tra_ola1 1 "Sólo 1", modify
    label values tra_ola3 tra_ola3
    label def tra_ola3 1 "Ola 1", modify
    label def tra_ola3 2 "Ola 1 y 3", modify
    label def tra_ola3 3 "Ola 3", modify
    label values tra_ola4 tra_ola4
    label def tra_ola4 3 "Ola 3", modify
    label def tra_ola4 4 "Ola 1, 3 y 4", modify
    label def tra_ola4 5 "Ola 1 y 4", modify
    Last edited by sladmin; 30 Jan 2026, 14:54. Reason: Anonymize original poster

  • #2
    Originally posted by Guest
    The problem is that the collect gives me a table with dim 8*12 because it places the percentages as new columns, when what I need is for the percentages to be below the frequencies.
    Don't you request for this when you specify the column layout as the product of the dimensions result and tra_ola4?

    collect layout (tra_ola1 tra_ola3) (result#tra_ola4)
    Most likely you want:

    Code:
    collect layout ((tra_ola1 tra_ola3)#result) (tra_ola4)


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(tra_ola1 tra_ola3 tra_ola4)
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    0 3 3
    1 1 5
    0 3 3
    1 1 5
    0 3 3
    1 1 5
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    1 2 4
    end
    label values tra_ola1 tra_ola1
    label def tra_ola1 0 "No ola 1", modify
    label def tra_ola1 1 "Sólo 1", modify
    label values tra_ola3 tra_ola3
    label def tra_ola3 1 "Ola 1", modify
    label def tra_ola3 2 "Ola 1 y 3", modify
    label def tra_ola3 3 "Ola 3", modify
    label values tra_ola4 tra_ola4
    label def tra_ola4 3 "Ola 3", modify
    label def tra_ola4 4 "Ola 1, 3 y 4", modify
    label def tra_ola4 5 "Ola 1 y 4", modify
    
    collect clear
    table tra_ola1 tra_ola4, ///
    stat(frequency) stat(percent, across(tra_ola4)) nototal sformat("%s%%" percent)
    table tra_ola3 tra_ola4, ///
    stat(frequency) stat(percent, across(tra_ola4)) nototal sformat("%s%%" percent) append
    collect style header result, level(hide)
    collect style cell, empty(0)
    collect style tex, nocentering
    collect layout ((tra_ola1 tra_ola3)#result) (tra_ola4)
    collect preview
    Res.:

    Code:
    . collect preview
    
    -------------------------------------------------
                |               tra_ola4            
                |    Ola 3   Ola 1, 3 y 4   Ola 1 y 4
    ------------+------------------------------------
    tra_ola1    |                                    
      No ola 1  |        3              0           0
                |  100.00%             0%          0%
      Sólo 1    |        0             21           3
                |       0%         87.50%      12.50%
    tra_ola3    |                                    
      Ola 1     |        0              0           3
                |       0%             0%     100.00%
      Ola 1 y 3 |        0             21           0
                |       0%        100.00%          0%
      Ola 3     |        3              0           0
                |  100.00%             0%          0%
    -------------------------------------------------
    Last edited by sladmin; 30 Jan 2026, 14:55. Reason: Anonymize original poster

    Comment

    Working...
    X