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
RD analysis with covariate coefficientsHi Statalist I am performing an RD analysis investigating the effects of reduced social benefits on…
attribute the displayed output of a command in local macroI am trying to attribute the output of a command that just prints and output to the Stata screen (pr…
Merge problemsHello dear stata friends, we are pretty new on stata and would like some help. We managed to merge …
Replace missing values of a variable based on another previous valuesHello Everyone, Again a very basic question. dataex: v1 v2 v3 1 12 1 1 13 2 1 15 3 2 13 4 2 14 5 …
Is there a command that is equivalent to "bsample more than _N"?The command bsample B with B > _N (e.g., if _N = 100., trying to sample more than 100 times wi…
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