Announcement

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

  • Building a comparison group with nearest neighbor matching

    Hello,

    I would like to build a comparison group for a difference in differences regression. I have 12 treated panels and would like to match each panel to 5 comparison panels with nearest neighbor matching. I imagine I will be using teffects nnmatch for this but I don't know the correct procedure. I would guess that the best way to do this would be to match in the year prior to treatment, and then include the entire panel of every matched and treated observation.

    Can anyone suggest code for doing this?

  • #2
    here is a data sample

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str23 School_No float(Year MathProf_z) long Enrollment double(FreeLunch STRatio) float treatment
    "0010" 2008  -.4053205 1605             .8368 20.23204453318812 0
    "0010" 2009  -.4254744 1728             .8096 18.98976223235205 0
    "0010" 2010  -.3733076 1899             .9142   19.201426911725 0
    "0010" 2011   -.386545 1930 .9295336787564766 19.29828245286169 0
    "0010" 2012 -.24461243 1903  .929584866001051 21.92757562593837 0
    "0010" 2013  -.4685268 1764  .938208616780045 17.41381199598416 0
    "0010" 2014  -.5036725 1509  .966865473823724 16.59830453104015 0
    "0040" 2008 -.57989913  441             .9342 9.811053787266987 0
    "0040" 2009 -.52127063  434             .9977  11.4381496552742 0
    "0040" 2010 -.54113054  381                 1 11.41593556738099 0
    "0040" 2011  -.6784725  333                 1 11.49988949055144 0
    "0040" 2012  -.7326867  287 .9965156794425087 9.407183548245412 0
    "0040" 2013   -.632798  256         .99609375 7.627924161747747 0
    "0040" 2014   -.712518  238  .995798319327731 6.964399627785031 0
    "0067" 2008  -.7425414   69             .6522 17.06231454005934 0
    "0067" 2009          .   86             .8256 14.33333333333333 0
    "0067" 2010          .  100               .73  16.7266036631262 0
    "0067" 2011          .  116 .8793103448275862 15.77844881525613 0
    "0067" 2012          .  139 .8705035971223022 15.89770569801221 0
    "0067" 2013          .  154   .85064935064935 19.09698540444687 0
    "0067" 2014  -.8398182  153  .849673202614379 17.28481534620469 0
    "0069" 2009 -1.5607686  429             .4499 13.91813282894972 0
    "0099" 2014          .   99  .787878787878787 15.77161428047984 0
    "0133" 2008  -.8207042   42             .9762 4.669520262382567 0
    "0133" 2009 -1.1437243   55             .9636 6.111111111111111 0
    "0133" 2010  -1.081512   47             .8936             5.875 0
    "0220" 2008  -.6447309  507             .9388 17.48275862068966 0
    "0220" 2009  -.4146334  552              .943 16.94098583033848 0
    "0220" 2010 -.58224106  625              .946 17.85714285714286 0
    "0220" 2011  -.6540507  593 .9429657794676806 16.94285714285714 0
    "0220" 2012  -.7519145  583 .9616858237547893 19.11475409836066 0
    "0220" 2013  -.9320149  592  .953398058252427 19.11990310859911 0
    "0220" 2014  -.5691682  577  .970414201183431 16.72463768115942 0
    "0388" 2008  1.6492746  316             .5887              15.8 0
    "0388" 2009   .8901469  338             .5309              16.9 0
    "0388" 2010  1.0007874  355              .513 16.02708803611738 0
    "0388" 2011   1.246476  379 .5363636363636364 15.72614107883817 0
    "0388" 2012   1.018331  313 .4792332268370607 17.73612275890206 0
    "0388" 2013  1.3327397  325  .406153846153846 16.88311688311688 0
    "0388" 2014  1.1636374  319  .420062695924764 15.37349397590361 0
    "0408" 2008  -.5333232  385             .8182  15.3999384002464 1
    "0408" 2009 -1.1833991  396             .8297 15.23076923076923 1
    "0408" 2010   -.979735  389              .894 16.64164003576455 1
    "0408" 2011  -.6170721  369 .8078291814946619 15.38512854295745 1
    "0408" 2012  -.8126353  361 .7472118959107806 16.40909090909091 1
    "0408" 2013   -.778394  392  .678200692041522 16.60313426514189 1
    "0408" 2014  -.4034532  382  .631399317406143             15.28 1
    "0418" 2008  -.8154407  353              .911 18.10237843714424 1
    "0418" 2009  -.8128619  346             .9252 17.65306122448979 1
    "0418" 2010  -.7609491  358             .9063 15.07362074264951 1
    "0418" 2011  -.9976937  345 .8242811501597445 15.01063797386844 1
    "0418" 2012  -.8576472  354 .9623824451410659  18.1560807483998 1
    "0418" 2013  -.3710062  346  .968253968253968 17.08641975308642 1
    "0418" 2014 -.50930065  335  .957095709570957             16.75 1
    "0520" 2008  -.7179403  489             .8899 18.38345864661654 0
    "0520" 2009  -.7171136  500              .919 17.09401709401709 0
    "0520" 2010   -.962998  470             .9178 17.57009345794393 0
    "0520" 2011  -.4937375  460 .9789719626168224 18.21774963267472 0
    "0520" 2012  -.3872159  489 .9387308533916849  19.5609389250684 0
    "0520" 2013  .10059621  484  .958057395143487 17.28571428571429 0
    "0520" 2014 -.25959274  488  .953947368421052 16.26666666666667 0
    "0540" 2008  -.9332751  250             .8357 14.71038199919975 0
    "0540" 2009 -1.4197037  285             .6894 13.90243902439024 0
    "0540" 2010 -1.0429078  226             .9133 11.03316295395851 0
    "0540" 2011  -.9638467  207 .9548022598870056  12.9506935190225 0
    "0540" 2012 -1.4588873  222 .9470588235294117 14.55251030802813 0
    "0540" 2013 -1.1159313  198  .945454545454545 12.57142857142857 0
    "0540" 2014  -.8085597  199  .939759036144578 12.83870967741935 0
    "0650" 2008   .7757837  307             .9491 14.97955559025304 0
    "0650" 2009  1.3448157  352             .9625 17.17073170731707 0
    "0650" 2010   1.943675  314             .9574  14.7764705882353 0
    "0650" 2011  1.7230413  354 .9658385093167702 16.65874513531701 0
    "0650" 2012 -.52202857  363 .9606060606060606 21.04494225685265 0
    "0650" 2013  -.7867045  328  .926174496644295 17.09669012249153 0
    "0650" 2014  -.6559926  319  .889655172413793 16.35897435897436 0
    "0964" 2008   .4965309  377             .4751 16.39130434782609 0
    "0964" 2009   .4510616  456             .4658 16.29520042024464 0
    "0964" 2010  .58784854  503             .4767  16.7109634551495 0
    "0964" 2011   .3648212  534 .4468546637744035 16.69600452730609 0
    "0964" 2012     .79764  521 .5088495575221239 19.01626419832394 0
    "0964" 2013   .7031274  552  .483221476510067 19.74955277280859 0
    "0964" 2014   1.129601  540  .491916859122401                18 0
    "1056" 2008  2.1728177  323              .096 18.99988823595155 0
    "1056" 2009  1.9719183  331             .0967 17.42105263157895 0
    "1056" 2010  1.9094822  317             .1009 16.68421052631579 0
    "1056" 2011   1.827833  317 .0757097791798107 15.87579817202955 0
    "1056" 2012   2.073251  319 .0909090909090909 18.23107168983175 0
    "1056" 2013  1.9338557  322  .077639751552795 18.14084507042254 0
    "1056" 2014   1.758117  304 .0822368421052631 15.29559748427673 0
    "1076" 2008  -.4007153  358             .7795 13.51779969490553 0
    "1076" 2009   .3101333  385             .7179 15.10769629213968 0
    "1076" 2010   .2354104  461             .6118 15.76068376068376 0
    "1076" 2011   .3172948  492 .5131578947368422            15.375 0
    "1076" 2012   .6720814  494 .5076586433260394 19.18446601941747 0
    "1076" 2013   .6880204  502  .465665236051502 18.34795321637427 0
    "1076" 2014   .8257858  553  .494186046511627 16.56928838951311 0
    "1106" 2008  .10545943  490             .9483 18.84615384615385 0
    "1106" 2009  .16507357  466             .9617 17.92307692307692 0
    "1106" 2010  -.4384472  456             .9455 17.53846153846154 0
    "1106" 2011 -.01061506  459 .9498861047835991 17.33697951290264 0
    end

    Comment

    Working...
    X