Announcement

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

  • Can teffects nnmatch command be used to perform one to one nearest neighbor matching WITH replacement?

    I am currently trying to find out the matched sample (observations in the treatment group that are matched with observations in the control group) by using teffects nnmatch, and applying a caliper of 0.5. I want to do one to one matching WITH replacement. i.e, one control can match with more than one treatment observations. In my case I have 100 treatment, and 350 control observations. I want a one to one matching with replacement that will yield at most 100 treated observations (i.e. if none of the treatment obvs are dropped due to lack of suitable match within the specified caliper), and less than 100 control observations (assuming some controls can match with more than one treated obvs and therefore will be less than the total treatment observations).

    I want to see difference in "OutcomeY" between treatment groups (TreatmentX = 0 Vs 1) after matching based on following variables: age, education, male, farmsize, employment, hh_type.
    My sample dataset with 100 observations is as follows, where TreatmentX (1)= 29 and TreatmentX (0)= 71.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(age education male farmsize employment hh_type OutcomeY) byte TreatmentX
    52  5 0  .625 1 1        0 0
    45 10 1  1.25 1 1     3000 0
    73  4 1  .002 1 1     -200 0
    60  0 0   .75 1 1        0 0
    59  3 0  .625 1 1  56646.2 0
    53  5 0   .25 1 1     2500 0
    52  3 0   1.5 1 0 99967.39 0
    48  3 0 1.875 1 1        0 0
    69  3 1  1.25 1 1   297640 0
    67  0 0     1 1 1        0 0
    54  7 1  .125 1 1        0 0
    45  0 0  .875 1 1        0 0
    75  0 1   1.5 1 1        0 0
    70  0 1  1.25 1 1   -20700 1
    30 15 0    .1 1 0     9930 1
    82  0 1  .625 1 1    -1590 1
    58  0 0     1 1 1     4200 1
    40  5 0  .125 1 1     8500 1
    50  7 0  .125 1 0    11350 1
    65 10 1 1.375 1 1     2500 1
    42  3 0 .0256 1 1     3350 1
    60  0 0    .7 1 1   -27290 1
    67  8 1  .875 1 1   -27000 1
    49  5 1    .3 1 1        0 0
    55  5 1   .75 1 1      200 0
    56  0 1    .5 1 1    10800 0
    50 12 1   .75 1 0        0 0
    55  0 0   .75 0 1        0 0
    25  8 0  .125 1 1        0 0
    46 12 1     1 1 1     5250 0
    45  0 0  .375 1 1        0 0
    68  0 0 1.125 1 0     3000 0
    65  0 0 1.375 0 1        0 0
    43  5 0  .625 1 1        0 0
    58  5 1   .25 1 1        0 0
    62  5 1   .75 1 1        0 0
    65  0 0    .5 1 1        0 0
    27 10 0  .125 1 0  63796.2 0
    68  5 1  1.75 1 1        0 0
    64  0 0  .125 1 1        0 0
    57  8 1    .5 1 1        0 0
    84  0 0   .75 1 1     1000 0
    48  0 0  .125 1 0        0 0
    72  0 0   1.5 1 0        0 0
    70  0 1   2.5 0 1        0 0
    85  3 1  .375 1 1        0 0
    47  7 1     2 0 1        0 0
    48  7 0  .125 1 0        0 0
    51  0 0   .75 0 1        0 0
    80  0 0   .25 1 0        0 0
    40 10 0     0 1 1        0 0
    72  0 0 1.875 1 0        0 0
    37 10 0  .375 1 0    54300 0
    50 10 1 1.125 0 1     7250 1
    51 10 1   .05 1 1    -7740 1
    68  9 1    .6 1 1   -21000 1
    54 10 1  .625 0 1   239900 1
    63 10 1    .7 1 1     7805 1
    32  6 0  .375 1 0     4100 1
    61 10 1  .875 1 1     -300 1
    46  8 1  .375 1 1     -300 1
    51  2 0   .45 1 1     2875 1
    61 11 1   2.5 1 1   296640 0
    56  3 1  .375 1 1        0 0
    60  0 0   1.5 1 0        0 0
    53 12 1  1.75 1 1        0 0
    37  8 0  .875 1 1    -2600 0
    64  0 1   .15 1 0        0 0
    73  0 1  .625 1 1        0 0
    65  0 0  1.25 1 0  45116.3 1
    29 12 1   .75 1 1  12299.9 1
    38 12 1   1.5 1 1    90250 1
    64  0 0   2.5 1 1   -23600 1
    66  0 1  .375 1 1   -20200 1
    32  6 0 .4375 1 1    42300 1
    68 10 1    .4 1 1   -18600 1
    54  5 1 1.875 1 1     -750 1
    55 10 1   .75 0 1   5933.3 1
    49  0 0   .75 1 1     5400 1
    56  0 0  .875 1 1        0 0
    46 12 1  1.25 1 0    13500 0
    52  0 0  .125 1 1        0 0
    34 10 0   .25 1 0        0 0
    68  0 0  .625 1 0        0 0
    24  7 0   .25 1 0        0 0
    80  8 1  .875 1 1        0 0
    85  0 0    .5 1 0        0 0
    53  5 1  .375 1 1        0 0
    30  5 0  .125 1 0    -2900 0
    44  8 1  .002 0 1        0 0
    35  8 0    .5 1 0        0 0
    36  7 0   .25 1 1    -4258 0
    58  3 0    .5 1 1        0 0
    43  0 0   .25 0 1        0 0
    21  5 0  .125 1 0        0 0
    53  5 1  .125 1 1        0 0
    55  6 1    .4 1 1        0 0
    70  0 1  .625 1 1        0 0
    58  0 1    .5 1 1        0 0
    42  9 1  .125 1 1        0 0
    end

    I used the following formula to get a final matched sample with equal number of treatment and control observations.

    Code:
    gen rownum = _n
    teffects nnmatch (OutcomeY  age education male farmsize employment hh_type) ( TreatmentX) , atet biasadj ( age education farmsize hh_type) ematch ( male ) dmvariables nneighbor(1) caliper(0.5) gen(nnid)
    
    save complete.dta, replace
    keep if TreatmentX == 1 & !mi(nnid1)
    save treated.dta, replace
    
    use complete.dta
    keep if TreatmentX == 0 & !mi(nnid1)
    save control.dta, replace
    
    drop nnid1
    rename rownum nnid1
    save control.dta, replace
    
    merge 1:m nnid1 using treated.dta, keepusing(nnid1)
    keep if _merge == 3
    save Matched.dta, replace
    
    append using treated.dta
    
    save Final_Matched.dta, replace
    The above code gives me 29 treatment observations and 29 control observations implying that there has been a one to one matching WITHOUT replacement. I would like to do 1:1 matching WITH replacement which means I am likely to get lesser number of controls than treated observations in the final matched sample.

    Can anyone provide me any suggestion on this? Can this be achieved with teffects nnmatch command? If not what are other alternatives?
    Thank you for replying!
    Last edited by Sanjay Sharma; 05 Jun 2021, 06:49.
Working...
X