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
Latent Class Model: problem with choosing the number of classesDear Specialists, I have tried the lclogit2 for each class (2,3 and 4), I could receive results fro…
How to create a identifiers in Stata?I have around 40,000 obs in my dataset and I wish to club 1-10 obs as code 1, 11-20 as code 2.. so o…
categorize a variable if certain words are found in it from a big listHi everyone, I want to categorize a variable based on a list that I have maintained. This list is c…
How to make a binary outcome variable of 3 other variablesHi all, My outcome variable is Entrepreneur =Yes=1 and Entrepreneur = No=wageworker=0 I'm using GEM…
Difference-in-Difference with continuous variables and fixed effectsDear Stata friends I try to run a difference-in-difference regression with a continuous treatment (…
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