Announcement

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

  • collapsing and getting unique values

    I have a dataset with procedures performed by type (type), per hospital code (cnes) and year (year). I have different rows of a same type of procedure, same year and same hospital as I am dealing with microdata. I would like to know the number of different hospitals that offer the procedures by type and year.

    I can do so with the codebook variable, as below. However, how could I do so collapsing my dataset by type and year?

    Code:
    codebook cnes if type==1 & year==1999
    codebook cnes if type==2 & year==2000

  • #2
    Do you have a bunch of other variables you want details on? If so, you might be doing about the best you can (though running a set of nested loops is probably already something you considered). If you do want details on the additional variables, will summary statistics be satisfactory? I'm guessing not, otherwise you'd already be using some combination of egen and/or collapse to get at what you need.

    Or is all you care about is type of procedure and # hospitals by year? If so, collapse should be all you need?

    Comment


    • #3
      Yes, all I need is the number of different hospitals that perform each type of procedure per year. As I have different rows with same type of procedure for a same hospital-month, I do not know how to do so with collapse. Could you please help me?

      Comment


      • #4
        So maybe this?

        Code:
        keep hospital type year
        drop if missing(hospital)
        duplicates drop
        collapse (count) hospital, by(type year)
        Note added: If hospital is a string variable, -collapse- will object that there is a type mismatch. In that case you need to first -encode- hospital and then substitute the encoded variable for hospital in the -collapse- command.
        Last edited by Clyde Schechter; 13 Mar 2016, 18:05.

        Comment


        • #5
          Can you please post a snippet of data for us to work with? I think the question is clearer now, but the solution, well, the solution needs data and I don't feel like making my own. Besides, I could be wrong in my assumptions (is procedure a string or a number? What about hospital ID?).

          [edit] Darnit, I had code that was almost identical to Clyde's, but wasn't sure if it was close enough to what was needed.
          Last edited by ben earnhart; 13 Mar 2016, 18:13.

          Comment


          • #7
            Perfect, thank you!

            Comment

            Working...
            X