I apologize for even asking, assuming there is something very simple I simply cannot find.
As [table] is the new go-to tabular presentation and analysis command in version 17, and I very much appreciate the ability to manipulate styles and easily export the results, I am trying to change my workflow to use this command instead of say [tabulate] for summary representations.
What I cannot figure out how to do, using the new [table] command, is sort summary results by order of (descending) frequency, which is extremely easy to do in tabulate. I can't seem to find a "sort", "rowsort", or "colsort" equivalent.
I can definitely get the tables I want with other commands, so that is not by itself the problem. I just can't do it with [table]. And I can get creative with value labels and renaming, and [bysort v:replace vnum = _N] etc., but that seems inelegant. Likewise, I am familiar with several SSC packages that address this challenge, but I'd prefer to do this within Stata proper if possible.
The problem I'd like to solve is described below:
* Example generated by -dataex-. For more info, type help dataex
clear
input str1 v
"a"
"a"
"b"
"b"
"b"
"c"
"c"
"c"
"c"
"d"
"d"
"d"
"d"
"e"
end
This is the table I'd let to get out of [table], that is trivial to get out of [tabulate]:
tabulate v, sort
v | Freq. Percent Cum.
------------+-----------------------------------
c | 4 28.57 28.57
d | 4 28.57 57.14
b | 3 21.43 78.57
a | 2 14.29 92.86
e | 1 7.14 100.00
------------+-----------------------------------
Total | 14 100.00
This is the closest I can come in a single command - but I can't figure out how to sort by descending frequency.
table v, stat(freq) stat(perc)
------------------------------
| Frequency Percent
--------+---------------------
v |
a | 2 14.29
b | 3 21.43
c | 4 28.57
d | 4 28.57
e | 1 7.14
Total | 14 100.00
------------------------------
It seems no matter what I do, the [v] column is sorted by the value of [v] and not by the order of the calculated summary statistics.
Again, apologies for being inept. A search through StataList and through the help files and manuals has not delivered the syntax or an example I am seeking.
Related Posts with Request syntax assistance with v17 [table] command to get table of frequency in descending frequency order
How to store p-value and CI in a new variable in prais-winsten regression?Hi! I'm new to Stata! I have a database model as shown below (hypothetical data). When running Prai…
spatial weight matrixHello, As part of my research, I want to build a spatial weight matrix. I want a variable that shows…
generate t-statHow can we modify this code to generate t-stat of the means instead of standard deviation (sd), and …
Assuming ICCHello everyone, This is my first post here. I need icc for power calculation. I have outcome variabl…
Transform a table: making options as variableDear all, I have this type of table: ID Date Culture ID Culture type Sample result 1 1 Jan 202…
Subscribe to:
Post Comments (Atom)
0 Response to Request syntax assistance with v17 [table] command to get table of frequency in descending frequency order
Post a Comment