Announcement

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

  • How to match my target observations with similair control observations

    Hi,

    I am using panel data for comparing the characteristics of firms that have been taken-private (dummy=1) vs firms that have not been taken-private (dummy=0). I want to test which characteristics might explain why certain firms are being acquired, i.e. taken-private.

    I would like to match my target firms, i.e. taken-private, with my non-target firms based on the year (exact), industry (exact) and size (2 or 3 closest matches, e.g. neighbor matching method).

    My data looks like this:

    Code:
    *dataex firmidyear DataYearFiscal target industry_nr size ROA Productivity*

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str10 firmidyear int DataYearFiscal float(target industry_nr size ROA Productivity)
    "6568112004" 2004 0 1  6.291856   -.08254483  .02777599
    "2572872004" 2004 0 1  6.799002    .12323848   .3160155
    "1523122004" 2004 0 1  9.904041    .07864489  .14068367
    "75971T2005" 2005 0 1 2.3084679    .05706333  .11831761
    "29257A2005" 2005 0 1 3.3718715     .3966636   .6837465
    "92299U2005" 2005 0 1  3.750797     .5038891    .491998
    "69291A2005" 2005 0 1 4.1148334    .24617092   .4493946
    "5538592005" 2005 0 1 4.2239537    .19215848   .4034766
    "0400492005" 2005 0 1 4.3097515     .2027492   .6122354
    "91851C2005" 2005 0 1 4.5866194     .6559463   .7485371
    "4026352005" 2005 0 1 4.7168903    .09743337   .3384385
    "68628V2005" 2005 0 1 4.7416744     .0795282  .06508681
    "0196452005" 2005 0 1  4.922569    .06557461  .12547463
    "20605P2005" 2005 0 1  5.448395   .017182693  .22679117
    "96949L2005" 2005 0 1  5.484552      .022657  .10034963
    "9628792005" 2005 0 1  5.584064      .095025   .3458918
    "0493032005" 2005 0 1   5.59991    .15319043  .18679124
    "92275P2005" 2005 0 1  5.712273    .08742786  .30358166
    "7496602005" 2005 0 1  5.742314     .3231073    .200036
    "40499Z2005" 2005 0 1  5.887428   -.00952072   .4501192
    "02341W2005" 2005 0 1  5.909519    .13007118   .0827524
    "N227172005" 2005 0 1  5.977875    .11805596  .12642434
    "41754V2005" 2005 0 1  5.993458     .3071223   .5236451
    "23311P2005" 2005 0 1   6.00955    .09329733  .05425369
    "1999082005" 2005 0 1   6.01294  -.005742837  .03620331
    "4509132005" 2005 0 1  6.150571    .04723392  .04302095
    "0500952005" 2005 0 1  6.205959     .0516609  .14641543
    "13123X2005" 2005 0 1  6.279976     .0749097   .4270154
    "4620442005" 2005 0 1    6.2876    .03745392   .0681451
    "58977Q2005" 2005 0 1  6.320412    .08411448  .27614304
    "45684P2005" 2005 0 1  6.331568    .04028027 .029490704
    "5763232005" 2005 0 1  6.370182    .03478133  .04237388
    "7595942005" 2005 0 1  6.373431       .18694     .38356
    "6568112005" 2005 0 1  6.375043   -.03612198  .09892186
    "9694902005" 2005 0 1  6.375596 -.0003303055  .23795995
    "7212832005" 2005 0 1  6.384275   .008917133   .0676917
    "1921082005" 2005 0 1  6.388252   .020231467   .0449935
    "2120152005" 2005 0 1   6.39732     .3256163   .5476123
    "75885Y2005" 2005 0 1  6.483603  -.018272294  .01966206
    "70799Y2005" 2005 0 1  6.489021    .07776658  .17291486
    "6936652005" 2005 0 1  6.492159    .07751834  .17291486
    "56845T2005" 2005 0 1  6.500593    .09281992   .3555806
    "2674752005" 2005 0 1  6.546368    .08415852  .07570338
    "09738U2005" 2005 0 1  6.569344    .10399185   .4217073
    "3767752005" 2005 0 1  6.580916    .05144204   .1939783
    "88162F2005" 2005 0 1   6.58872    .07870675  .11224457
    "4436282005" 2005 0 1  6.591335     .1021169  .13020453
    "20451N2005" 2005 0 1  6.620473    .05677729  .19250977
    "4824342005" 2005 0 1  6.679903     .2167155  .53806305
    "22576C2005" 2005 0 1   6.69493    .01564029  .12945625
    "1520062005" 2005 0 1  6.713249    .06996979  .13185795
    "88889T2005" 2005 0 1  6.715384     .1259394  .14470236
    "12618H2005" 2005 0 1  6.774059     .1905662  .27154446
    "43114K2005" 2005 0 1  6.790035     .0439026  .13930301
    "9011092005" 2005 0 1  6.819204   .007561819  .02789365
    "26883D2005" 2005 0 1  6.836565     .1231492  .27645075
    "20453E2005" 2005 0 1   6.84338    .09381083  .15274386
    "92343P2005" 2005 0 1  6.873783    .07887767  .10132235
    "0084742005" 2005 0 1  6.883533   .035055924   .2369664
    "6752322005" 2005 0 1  6.897268    .09550228  .09420626
    "20599D2005" 2005 0 1  6.924281    .09471575   .4924374
    "2572872005" 2005 0 1  6.950444    .14731131   .3477181
    "5707592005" 2005 0 1  6.952817   .002251234  .06674628
    "45928H2005" 2005 0 1  6.962398    .04590769  .10544485
    "92922P2005" 2005 0 1  6.970279    .27244768   .4929196
    "9237252005" 2005 0 1  7.013681    .16610733   .4765521
    "6031582005" 2005 0 1  7.052983   .067702845  .08263894
    "3454252005" 2005 0 1   7.07547     .6800271   .4143909
    "82836G2005" 2005 0 1  7.093748    .14815515   .4808239
    "2044482005" 2005 0 1   7.12917    .25524887  .20951724
    "78454L2005" 2005 0 1  7.145785    .18777345   .3345925
    "41752X2005" 2005 0 1  7.176622    .05568136   .3923992
    "55305B2005" 2005 0 1  7.192692    .12140308  .13025305
    "11283W2005" 2005 0 1  7.192849     .2940252  .29530516
    "1672502005" 2005 0 1  7.228257    .03475638 .017704407
    "3873282005" 2005 0 1  7.294534    .09666356  .05148121
    "1270972005" 2005 0 1  7.310129    .15797696   .3788198
    "24790A2005" 2005 0 1  7.316594    .16480374  .52308434
    "74762E2005" 2005 0 1  7.349092   .033604003 .036879394
    "1375132005" 2005 0 1  7.359529    .04736881     .30955
    "42330P2005" 2005 0 1  7.415093    .13702928  .29853705
    "4234522005" 2005 0 1  7.416589     .1292987   .2238044
    "5520742005" 2005 0 1  7.433076    .20836817  .18749633
    "29255W2005" 2005 0 1  7.441734    .09226273   .4704673
    "74022D2005" 2005 0 1   7.44943      .170594   .3777371
    "29084Q2005" 2005 0 1  7.483774    .04246628 .016392032
    "59001A2005" 2005 0 1  7.586477     .2111363   .1405807
    "35039W2005" 2005 0 1  7.604954    .06740832  .14358196
    "75281A2005" 2005 0 1   7.61035    .08785553   .4061855
    "6295792005" 2005 0 1  7.646832   .033810887  .02546399
    "7419302005" 2005 0 1  7.664769    .09170224   .3405239
    "8616422005" 2005 0 1  7.668709    .09961609   .3673323
    "9663872005" 2005 0 1  7.712084     .0877319   .4400401
    "62944T2005" 2005 0 1  7.727354     .5042409   .2198987
    "5732842005" 2005 0 1   7.79701    .11015709  .14591993
    "74733V2005" 2005 0 1   7.86484     .1568162   .2326004
    "36399D2005" 2005 0 1  7.916422   -.12577581   .3639271
    "74386V2005" 2005 0 1   7.93461     .0439474  .14469266
    "G7665A2005" 2005 0 1  7.998061    .11611722  .25655654
    "5762062005" 2005 0 1  8.001828  -.025251037  .05298232
    end
    Based on this thread: https://www.statalist.org/forums/for...with-firm-size

    I use the following code:
    Code:
    preserve
    keep if target == 0
    ds DataYearFiscal industry_nr, not
    rename (`r(varlist)') st0_=
    tempfile state0
    save `state0'
    restore
    keep if target == 1
    ds DataYearFiscal industry_nr, not
    rename (`r(varlist)') st1_=
    tempfile state1
    save `state1'
    joinby DataYearFiscal industry_nr using `state0'
    gen size_diff = abs(st0_size - st1_size)
    by st1_firmidyear DataYearFiscal (size_diff), sort: keep if _n == 1
    However, due to the last line
    Code:
    by st1_firmidyear DataYearFiscal (size_diff), sort: keep if _n == 1
    it only returns the single best match per target. However, I would instead like to return the two or three closest matches.
    So I would like to learn how to adjust the code so that it returns the 2 or 3 closest matches.

    The output looks like this:
    Code:
    *dataex st1_firmidyear DataYearFiscal st1_target st1_size industry_nr st0_firmidyear st0_target st0_size*
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str10 st1_firmidyear int DataYearFiscal float(st1_target st1_size industry_nr) str10 st0_firmidyear float(st0_target st0_size)
    "00686U2005" 2005 1  7.573274 5 "0434362005" 0   7.56569
    "0081902006" 2006 1 8.6129465 7 "18453H2006" 0    8.5982
    "0185812006" 2006 1   8.13271 7 "97651M2006" 0  8.128415
    "0200392006" 2006 1  9.817041 4 "29250N2006" 0   9.81898
    "0205202008" 2008 1  7.788805 2 "48020T2008" 0  7.794617
    "0263752011" 2011 1  7.345665 2 "3434982011" 0  7.348586
    "0346632007" 2007 1  5.769598 7 "8545322007" 0  5.723765
    "0352902018" 2018 1  8.445289 5 "98850P2018" 0  8.435983
    "04650Y2020" 2020 1  7.833962 5 "4492532020" 0   7.83554
    "04878Q2020" 2020 1  6.741937 4 "5535732020" 0  6.746181
    "0543032011" 2011 1  8.953511 2 "0737302011" 0  8.921564
    "05534B2006" 2006 1  10.51751 4 "9078182006" 0  10.50548
    "05548J2010" 2010 1  7.750044 5 "19421W2010" 0  7.726874
    "0677742018" 2018 1  7.441692 5 "83190B2018" 0   7.44537
    "0683232016" 2016 1  6.141551 7 "8256902016" 0  6.218158
    "0865162011" 2011 1  9.680656 5 "29759W2011" 0  9.672914
    "09643P2014" 2014 1  5.660711 3 "7437132014" 0  5.661272
    "1045762006" 2006 1  5.744678 2 "2372662006" 0  5.770836
    "11283W2013" 2013 1  8.114852 1 "9011092013" 0  8.130777
    "1181672007" 2007 1   7.76401 5 "79377W2007" 0  7.771077
    "1182302018" 2018 1  9.143725 4 "0158572018" 0   9.14729
    "12561W2013" 2013 1  8.346467 4 "Y8564M2013" 0  8.347494
    "12662P2011" 2011 1  8.045361 2 "1713402011" 0  8.044819
    "1320112018" 2018 1  7.109412 2 "4989042018" 0  7.112286
    "1501852008" 2008 1  7.689867 7 "7589322008" 0  7.712386
    "1547852006" 2006 1  6.669968 7 "87163F2006" 0  6.664597
    "1638682009" 2009 1  5.441465 2 "74157K2009" 0  5.479509
    "16942J2010" 2010 1  7.013036 3 "74973W2010" 0  7.009277
    "16944W2019" 2019 1  5.873103 8 "74979W2019" 0  5.817391
    "16949D2012" 2012 1  6.625812 4 "29250X2012" 0  6.616467
    "1718712019" 2019 1  7.883748 4 "Y1968P2019" 0  7.894698
    "17887R2017" 2017 1  6.955957 8 "63935N2017" 0  6.984961
    "1795842006" 2006 1  6.995094 5 "0003612006" 0  6.973199
    "1932942011" 2011 1  5.520733 3 "92835K2011" 0  5.547538
    "1938702005" 2005 1  8.868162 5 "6819042005" 0  8.875903
    "19421W2011" 2011 1  7.624228 5 "7837542011" 0  7.629684
    "2033722009" 2009 1   8.27927 3 "3693002009" 0  8.274892
    "2062772015" 2015 1  6.320704 7 "92932M2015" 0  6.264257
    "21871D2020" 2020 1  8.362461 7 "39304D2020" 0  8.322459
    "2191412005" 2005 1  6.235641 8 "29414D2005" 0  6.268748
    "21925D2021" 2021 1  8.670337 3 "0404132021" 0  8.654243
    "22238M2014" 2014 1  5.249458 5 "63888U2014" 0  5.241668
    "22282E2020" 2020 1  8.217709 4 "B385642020" 0  8.212633
    "2296692020" 2020 1   7.75114 3 "50189K2020" 0  7.739808
    "2874562005" 2005 1  6.419293 2 "1320112005" 0  6.417503
    "29084T2010" 2010 1  7.819461 7 "7587662010" 0  7.821082
    "29100P2010" 2010 1  7.466543 4 "0493922010" 0   7.47582
    "2927562012" 2012 1  7.884374 4 "2836772012" 0  7.889478
    "30066A2015" 2015 1  6.958145 8 "8740802015" 0  6.967324
    "30219E2013" 2013 1   7.07553 5 "9888582013" 0  7.079399
    "3070002010" 2010 1  8.000369 5 "55345K2010" 0 8.0034275
    "3406322006" 2006 1  7.240525 4 "40051E2006" 0  7.232391
    "3503922019" 2019 1   7.25259 5 "25754A2019" 0  7.231354
    "35100E2005" 2005 1   6.78015 7 "G8766E2005" 0  6.769372
    "3715592018" 2018 1  8.970617 4 "4990492018" 0  8.976121
    "3737302010" 2010 1  5.807434 3 "5915202010" 0  5.813366
    "3742762007" 2007 1  7.606962 7 "8358982007" 0  7.610904
    "3745112012" 2012 1  6.542135 7 "3030752012" 0  6.542678
    "38239A2006" 2006 1   7.39263 3 "8760302006" 0  7.394198
    "38388F2019" 2019 1  8.277056 2 "12662P2019" 0  8.270013
    "39679B2012" 2012 1  4.891273 7 "87600Y2012" 0  4.939912
    "4130862006" 2006 1  7.764152 3 "2166482006" 0  7.763277
    "4370762005" 2005 1  10.70284 5 "87612E2005" 0  10.46296
    "4421202005" 2005 1  7.767105 1 "5732842005" 0   7.79701
    "4588842006" 2006 1  5.152991 3 "5993462006" 0  5.147291
    "46062R2006" 2006 1  7.736819 7 "9134312006" 0  7.758774
    "4609152005" 2005 1  7.880159 7 "5790642005" 0  7.879528
    "46489B2012" 2012 1  6.145279 7 "6400942012" 0  6.171824
    "4698652005" 2005 1   7.16201 3 "8318652005" 0  7.164488
    "47758P2009" 2009 1  6.908155 5 "8644822009" 0  6.885013
    "48020T2012" 2012 1  7.861535 2 "2561352012" 0   7.86761
    "4880442006" 2006 1  7.322891 2 "7510282006" 0  7.318208
    "51508L2007" 2007 1  7.315207 5 "6907322007" 0  7.323224
    "51508L2008" 2008 1  7.323385 5 "79546E2008" 0  7.331075
    "5297712015" 2015 1  8.271906 3 "F211072015" 0  8.278846
    "53217R2014" 2014 1  7.894176 7 "G3922B2014" 0  7.916639
    "5359192009" 2009 1  7.441002 7 "8919062009" 0  7.444807
    "5525412010" 2010 1 8.2345915 2 "4103452010" 0  8.240122
    "5541532010" 2010 1  6.049929 7 "98156Q2010" 0  6.030034
    "5542732005" 2005 1  6.700407 2 "8905162005" 0  6.701587
    "55616P2006" 2006 1  10.29384 5 "5801352006" 0  10.27587
    "55933J2020" 2020 1  6.348597 3 "5355552020" 0  6.346559
    "5640552006" 2006 1  7.782589 8 "8202802006" 0  7.835632
    "6026752014" 2014 1  7.813269 3 "0024442014" 0  7.807516
    "6194302010" 2010 1  5.307346 5 "86765K2010" 0   5.31117
    "6284642006" 2006 1   6.49524 3 "23325G2006" 0  6.504788
    "64126X2015" 2015 1  7.697234 4 "Y8565N2015" 0  7.682241
    "6501112005" 2005 1 8.4191475 2 "48020T2005" 0  8.428974
    "6501112009" 2009 1 8.0354595 2 "8354952009" 0  8.027013
    "6501112012" 2012 1  7.939635 2 "9682232012" 0  7.939649
    "65440K2010" 2010 1  6.714431 5 "30219E2010" 0  6.760124
    "6556642017" 2017 1   9.00147 5 "0708302017" 0 9.0056505
    "67104A2005" 2005 1  7.597106 5 "05548J2005" 0  7.595814
    "6882392011" 2011 1  8.481959 3 "83175M2011" 0  8.465268
    "6952572009" 2009 1   8.18144 3 "4158642009" 0  8.199531
    "7050152006" 2006 1   9.55587 2 "G169622006" 0  9.571296
    "7132782011" 2011 1  7.398651 5 "0893022011" 0   7.40325
    "71714F2016" 2016 1  7.169735 5 "06777U2016" 0  7.169991
    "7212832013" 2013 1  6.435788 1 "02361E2013" 0  6.404666
    "7281172009" 2009 1  5.282351 4 "02799D2009" 0  5.161753
    end
    Additionally, after using this line of code I am wondering how I should pursue regressing the target firms with the obtained control variables, i.e. how do I sort them back in panel data? Because now they are in longitudinal format, instead of below each other in panel format. Because of this STATA does not recognize it as separate observations that can be used in the regression.

    Please, all help would be highly appreciated as I am stuck now for quite a while. Many thanks in advance!
Working...
X