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)
sample data:
Is there anyone on stata that can help me with this?
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)
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
Comment