Friday, May 5, 2023

Joining frequency and percentage in same column

Any idea on how one can join the frequency and percentage into one column and order the row labels in descending order of values, using the table command.

Code:
table (ballpoint) (progexp) , statistic(freq) statistic(percent, across(ballpoint)) totals(progexp) nformat(%5.1f) sformat("(%s%%)" freq percent)
collect recode result count = frequency
collect label levels ballpoint progexp "N", modify
collect layout (ballpoint) (progexp#result)



--------------------------------------------------------
          |                    progexp                  
          |            0                      1         
          |  Frequency    Percent   Frequency    Percent
----------+---------------------------------------------
ballpoint |                                             
  0       |       61.0    (75.3%)        13.0    (68.4%)
  1       |       20.0    (24.7%)         6.0    (31.6%)
  Total   |       81.0   (100.0%)        19.0   (100.0%)

Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input byte(ballpoint progexp)
1 0
1 0
1 0
1 1
0 0
1 0
0 0
1 1
1 0
1 0
1 0
0 0
0 0
0 1
1 0
1 0
0 0
0 0
0 1
1 0
0 0
0 1
0 0
1 0
0 0
0 0
0 0
1 1
0 0
0 0
0 0
0 0
0 0
0 0
0 1
0 1
0 1
1 1
0 0
1 0
0 0
0 1
0 1
0 1
0 1
0 1
1 1
1 1
0 1
0 1
1 0
0 0
0 0
1 0
1 0
1 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
1 0
0 0
1 0
1 0
1 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
end

No comments:

Post a Comment