Announcement

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

  • Flexible case-control matching command

    Hello,

    First, thanks in advance for anyone who can help me with this. I haven't had much luck recently with other avenues so I hoped I might find some advice here.

    I'm performing a case-control analysis on a dataset of mine in which I want to match 2 controls to 1 case based on a date value (matched on day). To increase the power I'm trying to add some flexibility by allowing controls to be matched +/- 1 day, rather than only on the specific day. For example, if I have 1 case whose date is 06/29/2018, and there's only 1 control who shares that specific date, I want to be able to match a second control whose date is either 06/28/2018 or 06/30/2018.

    Variables:
    case (binary, 0 or 1)
    date (str11, format is mm/dd/yyyy)

    I'm using the ccmatch command, which does match entries on one variable based on a given set of other variables. However it does not match multiple controls to a case and doesn't account for flexible matching criteria like mine.

    The only way I can do this now is by painstakingly poring through the (rather large) dataset and individually matching a second control to each identified case, and since ccmatch matches 1:1 at random, such additional code is difficult to replicate.

    Let me know if any more information is needed, I'm happy to explain myself better. This is my first post so apologies if I've made an error with this post.
    Last edited by Austin Weynand; 26 Jun 2022, 20:02.

  • #2
    This problem arises often here on Statalist and if you search the forum no doubt you will find many examples of ways to do this.

    For concrete assistance, post back with an example of your data. Make sure your example contains both cases and controls, and that at least some of the cases will have 1 or 2 valid matches with the controls. To show the example data, be sure to use the -dataex- command. If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Also, specify whether you want to match with or without replacement.

    Comment


    • #3
      Thanks for your reply Clyde, I'm happy to provide more details. I want to match without replacement. Below is a snippet of example data, and it's all I really need to make my matches (by this point I've already restricted the dataset to observations with no missing entries for case status and date). I did find code that may be useful for me here, but I struggle with converting and generating dates correctly. In my dataset the dates are in string 11 format and wonder if I need to convert them to date format in order to specify my matching range (controls matched 2:1 to cases +/- 1 day) so would love input on that as well. Sample data:

      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input float death str11 doa
      0 "5/27/2018"
      0 "9/21/2018"
      0 "10/16/2017"
      1 "2/28/2018"
      0 "9/13/2018"
      0 "5/23/2018"
      0 "4/25/2018"
      0 "8/5/2018"
      0 "5/28/2018"
      0 "4/18/2018"
      1 "2/18/2018"
      1 "10/28/2017"
      1 "9/15/2018"
      0 "11/29/2017"
      1 "2/23/2018"

      Thanks again for the swift response.
      Last edited by Austin Weynand; 27 Jun 2022, 13:31.

      Comment


      • #4
        Yes, absolutely must convert your date to a Stata internal format date variable to use it in this kind of matching. Actually, to use it for anything in Stata, you need to do that. A string variable is just not useful as a representation of dates in Stata. Fortunately, the conversion is simple:

        Code:
        gen date = daily(doa, "MDY")
        format date %td

        Comment

        Working...
        X