Hello everyone,
my question is basic, however I cannot find an appropriate command for my problem:
The observations in my sample can be assigned to a treatment group (var1 =1) and a control group (var1 = 0). Now I would like to assign exactly one observation of the control group to one observation of the treatment group based on var2 (both must have the same value of var2). The matching observation from the control group should be chosen randomly if there is more than one possible matching partner (e.g. No. 3 and No.4 could both be matched with no.1).
No. var1 var2
1 1 2
2 1 3
3 0 2
4 0 2
5 0 3
6 0 5
-> I would like to match 1) obs. No. 1 with either No. 3 or No. 4 and 2) obs. No. 2 with No. 5.
It would be perfect to either get a sample with only the matched observations (e.g. No. 1,2,3,5) or a new variable that indicates whether an observation is matched or not.
I tried to use the “cross”-command – unfortunately my dataset is too large for all possible combinations. The use of “merge” is also difficult as I cannot randomly choose between variables with the same value of var2. Are there any other possibilities or commands?
Thank you very much in advance for your help!
my question is basic, however I cannot find an appropriate command for my problem:
The observations in my sample can be assigned to a treatment group (var1 =1) and a control group (var1 = 0). Now I would like to assign exactly one observation of the control group to one observation of the treatment group based on var2 (both must have the same value of var2). The matching observation from the control group should be chosen randomly if there is more than one possible matching partner (e.g. No. 3 and No.4 could both be matched with no.1).
No. var1 var2
1 1 2
2 1 3
3 0 2
4 0 2
5 0 3
6 0 5
-> I would like to match 1) obs. No. 1 with either No. 3 or No. 4 and 2) obs. No. 2 with No. 5.
It would be perfect to either get a sample with only the matched observations (e.g. No. 1,2,3,5) or a new variable that indicates whether an observation is matched or not.
I tried to use the “cross”-command – unfortunately my dataset is too large for all possible combinations. The use of “merge” is also difficult as I cannot randomly choose between variables with the same value of var2. Are there any other possibilities or commands?
Thank you very much in advance for your help!
Comment