{"id":1353,"date":"2019-07-05T19:33:24","date_gmt":"2019-07-05T23:33:24","guid":{"rendered":"http:\/\/kaichen.work\/?p=1353"},"modified":"2019-07-06T23:03:20","modified_gmt":"2019-07-07T03:03:20","slug":"stata-command-to-order-tabulation-result-with-only-top-values-shown","status":"publish","type":"post","link":"https:\/\/www.kaichen.work\/?p=1353","title":{"rendered":"Stata command to order tabulation result with only top values shown"},"content":{"rendered":"<p><code>tabulate varname<\/code> command is handy in Stata, but sometimes it returns a too long result, if <code>varname<\/code> contains too many unique values.<\/p>\n<p>The third-party command, <code>groups<\/code>, will solve the problem by showing top values only. Please use <code>ssc install groups<\/code> to install <code>groups<\/code>. The usage of <code>group<\/code> is very similar to <code>tabulate<\/code>. Here are some examples:<\/p>\n<pre class=\"lang:default decode:true\">. sysuse auto\r\n(1978 Automobile Data)\r\n\r\n. groups mpg, order(h) select(5)\r\n\r\n  +-------------------------------+\r\n  | mpg   Freq.   Percent    Cum. |\r\n  |-------------------------------|\r\n  |  18       9     12.16   12.16 |\r\n  |  19       8     10.81   22.97 |\r\n  |  14       6      8.11   31.08 |\r\n  |  21       5      6.76   37.84 |\r\n  |  22       5      6.76   44.59 |\r\n  +-------------------------------+\r\n\r\n. groups mpg, order(h) select(f &gt;= 3)\r\n\r\n  +-------------------------------+\r\n  | mpg   Freq.   Percent    Cum. |\r\n  |-------------------------------|\r\n  |  18       9     12.16   12.16 |\r\n  |  19       8     10.81   22.97 |\r\n  |  14       6      8.11   31.08 |\r\n  |  21       5      6.76   37.84 |\r\n  |  22       5      6.76   44.59 |\r\n  |-------------------------------|\r\n  |  25       5      6.76   51.35 |\r\n  |  16       4      5.41   56.76 |\r\n  |  17       4      5.41   62.16 |\r\n  |  24       4      5.41   67.57 |\r\n  |  20       3      4.05   71.62 |\r\n  |-------------------------------|\r\n  |  23       3      4.05   75.68 |\r\n  |  26       3      4.05   79.73 |\r\n  |  28       3      4.05   83.78 |\r\n  +-------------------------------+<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>tabulate varname command is handy in Stata, but sometimes it returns a too long result, if varname contains too many unique values. The third-party command, groups, will solve the problem by showing top values only. Please use ssc install groups &hellip; <a href=\"https:\/\/www.kaichen.work\/?p=1353\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"_links":{"self":[{"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/posts\/1353"}],"collection":[{"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1353"}],"version-history":[{"count":3,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/posts\/1353\/revisions"}],"predecessor-version":[{"id":1357,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/posts\/1353\/revisions\/1357"}],"wp:attachment":[{"href":"https:\/\/www.kaichen.work\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1353"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1353"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}