Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Summarise String Variable

    I have a list of companies in different industries - I am trying to summarise how many I have in each industry. I understand there is a sum function, however, this only shows me numbers. Is there a way to get it to sum like this
    Mining 20
    Retail 7
    Healthcare 12

  • #2
    As you do not show example data, the following code is based on a guess as to what your data organization is. I'm assuming here that your data set has (at least) two variables: company_name and industry. I also assume that company_name and industry, taken together, uniquely identify observations in this data set. If this is right,
    Code:
    tab industry
    is all you need.

    If your data set is not as I have imagined, and the code doesn't produce the needed results, please show example data when you post back. And be certain to use the -dataex- command to do that. If you are running version 18, 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Comment

    Working...
    X