Announcement

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

  • Question about intervals in rangestat

    Hi Folks,
    This is question is more of a paranoia check than anything else. I have the following code which identifies people who have had 3 or more ed visits within a 3 month time period, then generates a new variable identifying people as having No ed visits, low ed visits (<=2 edvisits in 3 months) and high ed visits (3+ edvisits in 3 months):

    Code:
    rangestat (sum) total=edvisits, interval (mdate -2 0) by (studyid)
    rangestat (max) max=total, interval (studyid 0 0)
    gen repeat_user = max>= 3
    
    mvencode edvisits, mv(0)
    
    bysort studyid (edvisits) : gen patient_cat = edvisits[_N] ==0
    replace patient_cat = 3 if repeat user == 1
    replace patient_cat = 2 if patient_cat == 0
    
    label def patient_cat 1 no 2 low 3 high
    label val patient cat patient_cat
    tab patient_cat
    I would like to modify this code to capture people who have three or more visits in a 12 month period, so I have changed it to :

    Code:
    rangestat (sum) total=edvisits, interval (mdate -11 0) by (studyid)
    rangestat (max) max=total, interval (studyid 0 0)
    gen repeat_user = max>= 3
    
    mvencode edvisits, mv(0)
    
    bysort studyid (edvisits) : gen patient_cat = edvisits[_N] ==0
    replace patient_cat = 3 if repeat user == 1
    replace patient_cat = 2 if patient_cat == 0
    
    label def patient_cat 1 no 2 low 3 high
    label val patient cat patient_cat
    tab patient_cat
    The reason that I'm concerned is that both variations on the code turn up the exact same number of people in the "no" "low" and "high" categories. I would expect there to be the same number in "no" but I would think that the distribution of people in the "low" and "high" categories would shift by expanding the window from 3 to 12 months.

    Can anyone see an issue with the code?

    Any thoughts would be much appreciated.

    Thanks so much!

  • #2
    Data example please. We appreciate that the real dataset may be large and confidential, but that point is already covered in the FAQ. Fake data that are realistic are more than fine.

    Comment


    • #3
      Thanks Nick. I managed to figure out the issue. It wasn't with the code, but was with how I had my date info formatted (which, in retrospect, could only have been spotted if I had included a data sample, so I'll be sure to do that next time) In short, my date info was in days, not months. That being the case, the range I coded originally was for 3 and 12 days, not 3 and 12 months. I changed the range to (mdate -364 0) to capture a year, and it did the trick!

      As always, your help is much appreciated.

      Thank you.

      Mike
      Last edited by Mike Reid; 25 Nov 2019, 14:26. Reason: Grammar and spelling

      Comment


      • #4
        Thanks for posting the resolution, always appreciated personally and by the community.

        Comment

        Working...
        X