Announcement

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

  • How to generate counts

    I have a dataset that shows different providers that participated in studies at different hospitals. The variables are: id, name, hospital, type. I'm trying to generate the number and percentage of hospitals that participated by the type and also the number and percentage of unique hospitals that participated by the type. Here is an example dataset:
    Click image for larger version

Name:	Untitled.jpg
Views:	1
Size:	36.3 KB
ID:	1703779


    Last edited by Amber Pong; 28 Feb 2023, 08:25.

  • #2
    Something like this:
    Code:
    split hospital, parse(";") gen(hosp)
    reshape long hosp, i(id)
    
    //  TABULATION OF HOSPITALS BY INTERVENTION TYPE
    tab type
    
    //  TABULATION OF DISTINCT HOSPITALS BY INTERVENTION TYPE
    egen flag = tag(type hosp)
    tab type if flag
    In the future, when showing data examples, please use the -dataex- command to do so. If you are running version 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.

    Comment


    • #3
      Thanks, Clyde. Also thanks for pointing out dataex. I'll be sure to use that in the future.

      Comment

      Working...
      X