Announcement

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

  • Creating the sum of surgeon experience

    Hi i would like to create a dummy variable that will calculate the total number of operations done by a surgeon (=experience) prior to the date of surgery (yearsurgery)


    I would expect to have the results as shown in the string variable 'experience' .As you can see, this totals the number of operations done BEFORE the actual date of surgery (what I expect)

    I used the code below-- but this generates the cumulative experience, which will include the procedure on the actual day of surgery (which I don't want this to count)

    Code:
    bysort SurgeonID(date) : gen cum_experience = sum(Surgery)
    sample data:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(SurgeonID Surgery Death) str1 experience float(yearsurgery cum_experience)
     2 1 1 "0" 14610 1
     3 1 1 "0" 14611 1
     3 1 0 "0" 14611 2
     4 1 0 "0" 15768 1
     5 1 1 "0" 16865 1
     7 1 1 "0" 17628 1
     8 1 1 "0" 18271 1
     9 1 1 "0" 16440 1
    10 1 0 "0" 18243 1
    10 1 0 "0" 18243 2
    10 1 0 "3" 19372 3
    10 1 1 "2" 18277 4
    12 1 1 "0" 16167 1
    12 1 0 "0" 16167 2
    12 1 0 "2" 16475 3
    12 1 0 "2" 16444 4
    end
    format %td yearsurgery
    Is there anyone on stata that can help me with this?




  • #2
    You can use the community-contributed command rangestat (from SSC):

    Code:
    rangestat (sum) wanted = Surgery, interval(yearsurgery . -1) by(SurgeonID)
    replace wanted = 0 if missing(wanted)

    Comment


    • #3
      Originally posted by Hemanshu Kumar View Post
      You can use the community-contributed command rangestat (from SSC):

      Nice once, I was actually attempting to use rangestat a while ago but couldn't get the code to work (i was using _n-1)

      with regards to the code:

      Code:
      rangestat (sum) wanted = Surgery, interval(yearsurgery . -1) by(SurgeonID)
      Just so I can understand - the interval here :

      Low value: Year of surgery - but I did not understand why you inserted . -1

      I understand normally . = insert a missing bound which is an inifinte number.
      I fail to understnad the . -1

      Are you able to explain if it's not too much of a hassle

      Comment


      • #4
        The interval option needs both a lower bound and an upper bound. Here, the lower bound is the missing value . (because we want even the oldest surgeries to count), and the upper bound is -1, because we want only surgeries upto the date before the current to count.

        Comment

        Working...
        X