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
Panel Data :Cross-Sectional Dependence and Driscoll-Kraay robust errors.Greetings, I'm facing some doubts regarding the solution of Driscoll-Kraay to account for the standa…
Reshaping my datasetGood evening, I would like to ask a question about my dataset: This is how my data look like Code:…
Which types of analysis? (continuous DV ranging from 0 to 1)Hi, My dependent variable is score, continuous variable ranging from 0 to 1 (e.g., 0.1, 0.23, 0.34)…
Interpreting coefficients - change in minutes vs change in hoursHi I am new to Stata and conducting research using UKHLS panel data on effects of commuting time on…
esttab different number formatting within same columnDear experts, I am currently exporting my stata table to Overleaf (LaTeX) using estpost and esttab.…
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