Hello,

I have a dataset of unique observations that have been grouped according to whether the participant had an event (Event = Yes) or did not have an event (Event = No). I have too few events in the dataset compared to controls so I would like to keep all the cases, N = 5 in the dataset below. For each case, I would like to select only the 2 closest controls based on the time from admission to event (So for example, case 1 closest match based on admission to having the event will be control 16 and 23). I tried to use Psmatch for this but it gets rid of my cases or requires that I match on other factors. Thank you in advance.


Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input byte id int(Admitdate eventdate) str3 Event float time
 1 20089 20106 "Yes"  17
 2 20577 20665 "No"   88
 3 20226 20228 "Yes"   2
 4 20227 20229 "Yes"   2
 5 20972 20982 "No"   10
 6 20281 20315 "No"   34
 7 20820 20911 "No"   91
 8 20211 20240 "No"   29
 9 20226 20237 "No"   11
10 20241 20254 "No"   13
11 20270 20272 "Yes"   2
12 20298 20344 "No"   46
13 20089 20097 "No"    8
14 20211 20342 "Yes" 131
15 20226 20230 "No"    4
16 20089 20108 "No"   19
17 20577 20590 "No"   13
18 20226 20233 "No"    7
19 20227 20228 "No"    1
20 20607 20633 "No"   26
21 20089 20152 "No"   63
22 20211 20278 "No"   67
23 20592 20607 "No"   15
24 20241 20350 "No"  109
end
format %tdnn/dd/CCYY Admitdate
format %tdnn/dd/CCYY eventdate