Announcement

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

  • using tabstat for mean annual procedure volume

    Good morning,

    I have a dataset of companies (ik), case-number, year, procedure-type and quintiles.
    Now I'd like to calculate the Mean annual company procedure volume per quintile

    Therefore i created the variable casesperik, which gives me the case number per company.

    Now I've tried to use a Code to calculate the median cases per year by quintile like this one in several ways, but I wasn't successful

    Code:
     tabstat ####, stat (N mean sd) by(quintile)
    I would be very thankful for some help!!
    ik case-number year quintile casesperik procedure-typ
    260100023 11649082 2013 1 1 2
    260100034 14198663 2012 4 3 3
    260100034 6420693 2013 4 4
    260100034 12981605 2015 4 4
    260100147 999779 2015 4 3 3
    260100147 2289626 2014 4 2
    260100147 10504606 2014 4 2
    260100432 7756966 2013 3 2 4
    260100432 6988745 2014 3 3
    260100454 18313122 2014 1 1 2
    260100476 17306808 2015 1 1 2
    260100739 18212972 2013 5 5 32
    260100739 16884461 2010 5 4
    260100739 19672375 2012 5 4
    260100739 15432329 2011 5 2
    260100739 47064384 2009 5 1
    260100820 3746991 2015 1 1 3
    260100875 21989008 2011 4 4 43
    260100875 41335174 2009 4 7
    260100875 9591743 2013 4 6
    260100875 10806055 2012 4 6
    260100911 20853059 2012 1 1 4
    260101126 13001086 2014 1 1 7
    260101137 19718069 2014 3 2 4
    260101137 22636978 2010 3 8
    260101193 18595578 2015 1 1 9
    260101809 16938712 2010 1 1 1
    260101865 16206583 2013 1 1 3
    260102036 18510223 2010 1 1 4
    260102081 19520974 2014 1 1 5
    260102343 7826502 2014 3 2 1
    260102343 23254003 2012 3 7
    260102354 3064907 2011 4 3 8
    260102354 15012738 2015 4 2
    260102354 23028509 2011 4 9
    260102423 426848 2012 1 1 22
    260102434 23818021 2014 3 2 8
    260102434 9718763 2011 3 5
    260200013 18148532 2012 5 10 6
    260200013 43751584 2009 5 7
    260200013 15677131 2011 5 34
    260200013 15104951 2012 5 9
    260200013 13361926 2011 5 8
    260200013 18020290 2014 5 8
    260200013 15793788 2012 5 9
    260200013 12914825 2009 5 8
    260200013 23123201 2013 5 8
    260200013 15734117 2011 5 9
    260200035 11812412 2013 5 5 1

  • #2
    but I wasn't successful
    What does that mean precisely?

    Looking at your code: presumably #### isn't what you typed, but if there is a problem in what you did type, we can't guess what that was. Otherwise, my best guess is that

    Code:
     stat (N mean sd)
    should be closed up to

    Code:
     stat(N mean sd)
    -- except that in the one experiment I tried tabstat didn't complain about the space.

    FAQ Advice #12.1:

    Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!

    Never say just that something "doesn't work" or "didn't work", but explain precisely in what sense you didn't get what you wanted.

    Comment


    • #3
      Thank you for your answer!!

      With the following code, I get an annual company procedure volume per quintile.

      Code:
      tabstat casesperik if quintile==1, stat (N mean) by (year)
      tabstat casesperik if quintile==2, stat (N mean) by (year)
      tabstat casesperik if quintile==3, stat (N mean) by (year)
      tabstat casesperik if quintile==4, stat (N mean) by (year)
      tabstat casesperik if quintile==5, stat (N mean) by (year)
      How can I change the code, which gives me a Mean annual company procedure volume per quintile per year?
      Would it simply be the following code, or am I missing something?

      Code:
      tabstat casesperik if quintile==1, stat (N mean) 
      tabstat casesperik if quintile==2, stat (N mean) 
      tabstat casesperik if quintile==3, stat (N mean) 
      tabstat casesperik if quintile==4, stat (N mean)
      tabstat casesperik if quintile==5, stat (N mean)

      Comment


      • #4
        You could probably get what you want with the following (or close to it) or by using the collapse command. Also, you might find this post on table, tabulate, & tabstat helpful. For help on collapse, see here, here, and here

        Code:
        format id casenumber %12.0g
        sort id year proc_type
        gen row_id = _n   // just a unique id for each observation
        bysort id year proc_type: gen n = _n
        bysort id year proc_type: gen proc_total = _N  // total for each procedure type within a firm (for that year)
        bysort id year: gen year_total = _N  // total for year for that firm
        order row_id, first
        
        . tabulate quintile year
        
                   |                                     year
          quintile |      2009       2010       2011       2012       2013       2014       2015 |     Total
        -----------+-----------------------------------------------------------------------------+----------
                 1 |         0          2          0          2          2          3          3 |        12
                 3 |         0          1          1          1          1          4          0 |         8
                 4 |         1          0          3          2          2          2          3 |        13
                 5 |         3          1          4          4          3          1          0 |        16
        -----------+-----------------------------------------------------------------------------+----------
             Total |         4          4          8          9          8         10          6 |        49
        
        . tabulate quintile year, summ(year_total) wrap
        
                 Means, Standard Deviations and Frequencies of year_total
        
                   |                                 year
          quintile |      2009       2010       2011       2012       2013       2014       2015 |     Total
        -----------+-----------------------------------------------------------------------------+----------
                 1 |         .          1          .          1          1          1          1 |         1
                   |         .          0          .          0          0          0          0 |         0
                   |         0          2          0          2          2          3          3 |        12
        -----------+-----------------------------------------------------------------------------+----------
                 3 |         .          1          1          1          1          1          . |         1
                   |         .          0          0          0          0          0          . |         0
                   |         0          1          1          1          1          4          0 |         8
        -----------+-----------------------------------------------------------------------------+----------
                 4 |         1          .  1.6666667          1          1          2          1 | 1.3076923
                   |         0          .  .57735027          0          0          0          0 | .48038446
                   |         1          0          3          2          2          2          3 |        13
        -----------+-----------------------------------------------------------------------------+----------
                 5 | 1.6666667          1        2.5        2.5          1          1          . |     1.875
                   | .57735027          0          1          1          0          0          . | .95742711
                   |         3          1          4          4          3          1          0 |        16
        -----------+-----------------------------------------------------------------------------+----------
             Total |       1.5          1          2  1.6666667          1        1.2          1 | 1.3673469
                   | .57735027          0   .9258201          1          0  .42163702          0 |  .6980293
                   |         4          4          8          9          8         10          6 |        49
        
        
         table quintile year, c(n proc_type ) row col format(%6.3g)
        
        ------------------------------------------------------------------
                  |                          year                        
         quintile |  2009   2010   2011   2012   2013   2014   2015  Total
        ----------+-------------------------------------------------------
                1 |            2             2      2      3      3     12
                3 |            1      1      1      1      4             8
                4 |     1             3      2      2      2      3     13
                5 |     3      1      4      4      3      1            16
                  |
            Total |     4      4      8      9      8     10      6     49
        ------------------------------------------------------------------
        
        . table quintile year, c(mean cases_per_id) row col format(%6.3g)
        
        ------------------------------------------------------------------
                  |                          year                        
         quintile |  2009   2010   2011   2012   2013   2014   2015  Total
        ----------+-------------------------------------------------------
                1 |            1             1      1      1      1      1
                3 |                                 2      2             2
                4 |                 3.5      3                    3   3.25
                5 |                         10      5                 6.67
                  |
            Total |            1    3.5   3.75    2.8    1.5    1.5    2.3
        ------------------------------------------------------------------
        
        
        . tabstat year_total, by(quintile) stats(mean median min max)
        
        Summary for variables: year_total
             by categories of: quintile
        
        quintile |      mean       p50       min       max
        ---------+----------------------------------------
               1 |         1         1         1         1
               3 |         1         1         1         1
               4 |  1.307692         1         1         2
               5 |     1.875       1.5         1         3
        ---------+----------------------------------------
           Total |  1.367347         1         1         3
        --------------------------------------------------
        
        
        . table quintile year, c(mean year_total ) row col format(%8.3g)
        
        ------------------------------------------------------------------
                  |                          year                        
         quintile |  2009   2010   2011   2012   2013   2014   2015  Total
        ----------+-------------------------------------------------------
                1 |            1             1      1      1      1      1
                3 |            1      1      1      1      1             1
                4 |     1          1.67      1      1      2      1   1.31
                5 |  1.67      1    2.5    2.5      1      1          1.88
                  |
            Total |   1.5      1      2   1.67      1    1.2      1   1.37
        ------------------------------------------------------------------
        
        *** Breakdown of quintile==1
        . list id year quintile cases_per_id proc_type n proc_total year_total if quintile==1, sepby(year) noobs abbrev(12)
        
          +--------------------------------------------------------------------------------------+
          |        id   year   quintile   cases_per_id   proc_type   n   proc_total   year_total |
          |--------------------------------------------------------------------------------------|
          | 260101809   2010          1              1           1   1            1            1 |
          | 260102036   2010          1              1           4   1            1            1 |
          |--------------------------------------------------------------------------------------|
          | 260100911   2012          1              1           4   1            1            1 |
          | 260102423   2012          1              1          22   1            1            1 |
          |--------------------------------------------------------------------------------------|
          | 260100023   2013          1              1           2   1            1            1 |
          | 260101865   2013          1              1           3   1            1            1 |
          |--------------------------------------------------------------------------------------|
          | 260100454   2014          1              1           2   1            1            1 |
          | 260101126   2014          1              1           7   1            1            1 |
          | 260102081   2014          1              1           5   1            1            1 |
          |--------------------------------------------------------------------------------------|
          | 260100476   2015          1              1           2   1            1            1 |
          | 260100820   2015          1              1           3   1            1            1 |
          | 260101193   2015          1              1           9   1            1            1 |
          +--------------------------------------------------------------------------------------+
        
        
        *** Breakdown of quintile==5
        . list id year quintile cases_per_id proc_type n proc_total year_total if quintile==5, sepby(year id) noobs abbrev(12)
        
          +--------------------------------------------------------------------------------------+
          |        id   year   quintile   cases_per_id   proc_type   n   proc_total   year_total |
          |--------------------------------------------------------------------------------------|
          | 260100739   2009          5              .           1   1            1            1 |
          |--------------------------------------------------------------------------------------|
          | 260200013   2009          5              .           7   1            1            2 |
          | 260200013   2009          5              .           8   1            1            2 |
          |--------------------------------------------------------------------------------------|
          | 260100739   2010          5              .           4   1            1            1 |
          |--------------------------------------------------------------------------------------|
          | 260100739   2011          5              .           2   1            1            1 |
          |--------------------------------------------------------------------------------------|
          | 260200013   2011          5              .           8   1            1            3 |
          | 260200013   2011          5              .           9   1            1            3 |
          | 260200013   2011          5              .          34   1            1            3 |
          |--------------------------------------------------------------------------------------|
          | 260100739   2012          5              .           4   1            1            1 |
          |--------------------------------------------------------------------------------------|
          | 260200013   2012          5             10           6   1            1            3 |
          | 260200013   2012          5              .           9   1            2            3 |
          | 260200013   2012          5              .           9   2            2            3 |
          |--------------------------------------------------------------------------------------|
          | 260100739   2013          5              5          32   1            1            1 |
          |--------------------------------------------------------------------------------------|
          | 260200013   2013          5              .           8   1            1            1 |
          |--------------------------------------------------------------------------------------|
          | 260200035   2013          5              5           1   1            1            1 |
          |--------------------------------------------------------------------------------------|
          | 260200013   2014          5              .           8   1            1            1 |
          +--------------------------------------------------------------------------------------+
        Last edited by David Benson; 04 Mar 2019, 01:25.

        Comment


        • #5
          Thank you very much for your very detailed answer und for showing me several solutions!! I appreciate it!

          Comment

          Working...
          X