Announcement

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

  • Randomly assign dates treatment control

    Dear All, Please, I would like to randomly assign the dates of a treatment from individuals who had this treatment to those who didn't, in order to analyse treatment occurrences within similar timeframes for both groups. That's, create a pool of treatment dates from the treat group and then randomly assign these dates to the control group. Thank you.

    The data looks like this:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(id yearexam yearill monthill dayill score illdate ill)
     1 2000 2000 11  3 100 14917 1
     1 2001    .  .  . 150     . 0
     1 2002    .  .  . 111     . 0
     2 2000    .  .  . 123     . 0
     2 2001 2001  5  2 200 15097 1
     2 2002    .  .  . 214     . 0
     2 2003    .  .  . 203     . 0
     2 2004    .  .  . 302     . 0
     2 2005    .  .  . 136     . 0
     3 2001 2001  7  6 222 15162 1
     4 2001    .  .  . 158     . 0
     4 2002    .  .  . 178     . 0
     4 2003    .  .  . 228     . 0
     4 2004    .  .  . 311     . 0
     5 2000    .  .  . 197     . 0
     5 2001 2001  2 17 106 15023 1
     5 2002    .  .  . 147     . 0
     5 2003    .  .  . 241     . 0
     5 2004    .  .  . 299     . 0
     6 2002 2002  3  3 321 15402 1
     6 2003    .  .  . 139     . 0
     6 2004    .  .  . 284     . 0
    13 2002 2002  5 23 123 15483 1
    13 2005    .  .  . 214     . 0
    end
    format %td illdate

  • #2
    I'm guessing (?) that you intend your "treatment" and "treatment" variables to be the ones named "ill" and "illdate." On that assumption, here's one way to do what I believe you want, which is to assign treatment dates to the non-treated by sampling from the observed distribution of treatment dates.
    Code:
    // For clarity, give "treament" names to  ill and illdate.
    rename (ill illdate) (treat treatdate)
    // Create a vector of the observed treatment dates and count them.
    mkmat treatdate if treat, matrix(T)
    local ntreat = rowsof(T)
    // Assign  a random treatment date to untreated individuals by sampling
    // *with replacement* from observed distribution of treatment dates.
    set seed 347544
    gen tdate = T[runiformint(1,`ntreat'), 1] if !treat
    replace tdate = treatdate if treat
    You could, of course, put these values into the original treatment variable, but I'd prefer to preserve those original values untouched to avoid error.

    Comment


    • #3
      Thank you very much prof. Mike. It worked well! Now, what if I wanted to randomly assign treatment dates to the non-treated but this randomisation occurred according to certain similar characteristics between treat and non-treat.
      For example,
      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input float(id yearexam yearill monthill dayill score illdate ill female race)
       1 2000 2000 11  3 100 14917 1 0 1
       1 2001    .  .  . 150     . 0 0 1
       1 2002    .  .  . 111     . 0 0 1
       2 2000    .  .  . 123     . 0 0 1
       2 2001 2001  5  2 200 15097 1 0 1
       2 2002    .  .  . 214     . 0 0 1
       2 2003    .  .  . 203     . 0 0 1
       2 2004    .  .  . 302     . 0 0 1
       2 2005    .  .  . 136     . 0 0 1
       3 2001 2001  7  6 222 15162 1 0 1
       4 2001    .  .  . 158     . 0 1 3
       4 2002    .  .  . 178     . 0 1 3
       4 2003    .  .  . 228     . 0 1 3
       4 2004    .  .  . 311     . 0 1 3
       5 2000    .  .  . 197     . 0 1 3
       5 2001 2001  2 17 106 15023 1 1 3
       5 2002    .  .  . 147     . 0 1 3
       5 2003    .  .  . 241     . 0 1 3
       5 2004    .  .  . 299     . 0 1 3
       6 2002 2002  3  3 321 15402 1 1 4
       6 2003    .  .  . 139     . 0 1 4
       6 2004    .  .  . 284     . 0 1 4
      13 2002 2002  5 23 123 15483 1 1 2
      13 2005    .  .  . 214     . 0 1 2
      end
      format %td illdate
      So, the treatment date will be assigned to a control that have similar characteristics of the treatment obs, for instance, by female and race. Thank you!

      Comment


      • #4
        By "randomisation occurred according to certain similar characteristics between treat and non-treat." I'm going to assume you mean "assign treatment dates to each non-treated individual from among the treated individuals who match that non-treated individual on (e.g.) female and race." I'm also going to assume that you'd still use random assignment *with* replacement."

        However, before going further, we need to resolve a complication you didn't describe and which I implicitly ignored: I see that you have multiple observations with the same value of the id variable, and presumably observations with the same id are from the same individual. By ignoring that feature of your data, the code I proposed above would allow a treatment date for a treated observation to be assigned randomly to an untreated observation for that *same individual, that is, another observation with the same id. That *might* be acceptable to you, but I'd suspect it is not ok. Please clarify on this issue before we go any further.

        Comment

        Working...
        X