Hi,
I do not understand why -collect layout- seems to sort numeric levels based on the text conversion of the numeric level. This is a problem when there is a level 10 or higher.
Comparing the two tables, in the second one the order of month has been sorted as though it is text.
This happens whether or not the levels are labelled.
How can I avoid this?
I have not found a way to stop it.
Maybe I am just not thinking straight on Friday afternoon before a long weekend...
Thanks,
Scott
I do not understand why -collect layout- seems to sort numeric levels based on the text conversion of the numeric level. This is a problem when there is a level 10 or higher.
Comparing the two tables, in the second one the order of month has been sorted as though it is text.
This happens whether or not the levels are labelled.
How can I avoid this?
I have not found a way to stop it.
Code:
. clear
. set obs 1000
Number of observations (_N) was 0, now 1,000.
. gen month = runiformint(1,12)
. gen group = runiformint(0,1)
. compress
variable month was float now byte
variable group was float now byte
(6,000 bytes saved)
.
. table (var), stat(fvfrequency month)
-------------------------------------
| Factor-variable frequency
---------+---------------------------
month=1 | 70
month=2 | 80
month=3 | 90
month=4 | 71
month=5 | 91
month=6 | 91
month=7 | 82
month=8 | 99
month=9 | 77
month=10 | 89
month=11 | 74
month=12 | 86
-------------------------------------
. collect layout (var[month])(result[fvfrequency])
Collection: Table
Rows: var[month]
Columns: result[fvfrequency]
Table 1: 12 x 1
-------------------------------------
| Factor-variable frequency
---------+---------------------------
month=1 | 70
month=10 | 89
month=11 | 74
month=12 | 86
month=2 | 80
month=3 | 90
month=4 | 71
month=5 | 91
month=6 | 91
month=7 | 82
month=8 | 99
month=9 | 77
-------------------------------------
.
. label define month ///
> 1 "Jan" 2 "Feb" 3 "Mar" 4 "Apr" 5 "May" 6 "Jun" ///
> 7 "Jul" 8 "Aug" 9 "Sep" 10 "Oct" 11 "Nov" 12 "Dec"
. label values month month
.
. table (var)(group), stat(fvfrequency month)
----------------------------
| group
| 0 1 Total
----------+-----------------
month=Jan | 30 40 70
month=Feb | 43 37 80
month=Mar | 47 43 90
month=Apr | 33 38 71
month=May | 48 43 91
month=Jun | 45 46 91
month=Jul | 45 37 82
month=Aug | 51 48 99
month=Sep | 46 31 77
month=Oct | 41 48 89
month=Nov | 37 37 74
month=Dec | 52 34 86
----------------------------
. collect layout (var[month])(group#result[fvfrequency])
Collection: Table
Rows: var[month]
Columns: group#result[fvfrequency]
Table 1: 12 x 3
----------------------------------------------------------------------------------------------
| group
| 0 1 Total
| Factor-variable frequency Factor-variable frequency Factor-variable frequency
----------+-----------------------------------------------------------------------------------
month=Jan | 30 40 70
month=Oct | 41 48 89
month=Nov | 37 37 74
month=Dec | 52 34 86
month=Feb | 43 37 80
month=Mar | 47 43 90
month=Apr | 33 38 71
month=May | 48 43 91
month=Jun | 45 46 91
month=Jul | 45 37 82
month=Aug | 51 48 99
month=Sep | 46 31 77
----------------------------------------------------------------------------------------------
Thanks,
Scott

Comment