hello everyone
I am working on panel data, I want to match firms(healthy and distressed) based on +-10 percent size(log of asset) if possible or it can be +-20 percent of the size and an exact match on industry and year. I have used following code to do the matching. however, I get every distressed firm matched with a different healthy firm for each year. I want to match all years of one firm with all years of another one firm only. Is there anyway to do this? I am pasting the code which I got from a post in Statalist, and the data example
Any help would be highly appreciated.
I am working on panel data, I want to match firms(healthy and distressed) based on +-10 percent size(log of asset) if possible or it can be +-20 percent of the size and an exact match on industry and year. I have used following code to do the matching. however, I get every distressed firm matched with a different healthy firm for each year. I want to match all years of one firm with all years of another one firm only. Is there anyway to do this? I am pasting the code which I got from a post in Statalist, and the data example
Any help would be highly appreciated.
Code:
//for single control match per case, a brief addition to the code of joinrange match: gen long obs_no = _n gen byte case = (distFirm50==1) preserve keep if case tempfile cases save `cases' restore keep if !case tempfile controls save `controls' // DO THE MATCHING use `cases', clear rangejoin size -0.1 0.1 using `controls', by(Inds_Code year) suffix(_control) drop if missing(ISIN_control) // NOW REDUCE TO ONE CONTROL PER CASE set seed 1234 // OR YOUR FAVORITE RANDOM NUMBER SEED gen double shuffle1 = runiform() gen double shuffle2 = runiform() by ISIN year (shuffle1 shuffle2), sort: keep if _n == 1 drop shuffle*
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str12 ISIN int(id year) byte time int Inds_Code double(size KthMJ2_residuals) byte(distFirm50 distOb) "AT0000A0E9W5" 7 2008 1 1300 7.221807 .07621686 1 1 "AT0000A0E9W5" 7 2009 2 1300 4.87852 .03882546 1 0 "AT0000A0E9W5" 7 2012 3 1300 8.507431 .03257107 1 0 "AU0000XINAK8" 12 2006 1 1100 3.99515 .0031539 1 1 "AU0000XINAK8" 12 2007 2 1100 4.185205 -.09307901 1 1 "AU0000XINAK8" 12 2008 3 1100 4.407938 -.04275685 1 0 "AU0000XINAK8" 12 2009 4 1100 6.802865 -.0184033 1 1 "AU0000XINAK8" 12 2010 5 1100 4.941442 -.00746611 1 1 "AU0000XINAK8" 12 2011 6 1100 7.587871 -.07927038 1 1 "AU0000XINAK8" 12 2012 7 1100 6.861562 -.07053462 1 1 "AU0000XINAK8" 12 2013 8 1100 5.027473 -.05346261 1 1 "AU0000XINAK8" 12 2014 9 1100 6.324653 -.1462374 1 0 "AU0000XINAK8" 12 2015 10 1100 5.348588 .03003502 1 0 "BE0003503118" 23 2006 1 3250 3.397089 -.13498304 1 1 "BE0003503118" 23 2007 2 3250 5.337533 .08512713 1 1 "BE0003503118" 23 2008 3 3250 1.88707 -.00201628 1 1 "BE0003503118" 23 2010 4 3250 4.095128 -.21970985 1 0 "BE0003503118" 23 2011 5 3250 11.09591 .01117146 1 0 "BE0003503118" 23 2012 6 3250 7.088826 -.09959354 1 1 "BE0003503118" 23 2013 7 3250 5.740436 -.00597251 1 1 "BE0003503118" 23 2014 8 3250 2.545061 .00569787 1 1 "BE0003503118" 23 2016 9 3250 3.081313 -.0668931 1 1 "BE0003503118" 23 2017 10 3250 6.166596 .0009217 1 1 "BE0003575835" 28 2012 6 2200 4.209116 -.04638176 1 0 "BE0003575835" 28 2013 7 2200 6.095674 .01369824 1 0 "BE0003575835" 28 2016 8 2200 11.35551 .08903543 1 1 "BE0003575835" 28 2017 9 2200 2.542074 -.07839124 1 1 "BE0003575835" 28 2018 10 2200 7.708375 -.02283064 1 1 "BE0003808251" 52 2011 5 4600 2.674287 -.06321903 1 0 "BE0003808251" 52 2012 6 4600 5.377932 -.02123887 1 0 "BE0003808251" 52 2014 7 4600 11.4247 -.00678408 1 1 "BE0003808251" 52 2017 8 4600 8.048951 .44692277 1 1 "BE0003836534" 62 2006 1 1300 8.659532 .06629891 1 0 "BE0003836534" 62 2007 2 1300 1.281524 -.08136644 1 0 "BE0003836534" 62 2008 3 1300 4.363391 .13494695 1 1 "BE0003836534" 62 2009 4 1300 8.038512 -.03344894 1 1 "BE0003836534" 62 2010 5 1300 6.581414 .03454497 1 1 "BE0003836534" 62 2013 6 1300 4.509716 -.00401043 1 1 "BE0003836534" 62 2014 7 1300 8.746716 -.11395335 1 1 "BE0003836534" 62 2015 8 1300 4.678876 -.08708423 1 1 "BE0003836534" 62 2017 9 1300 7.286726 .04174216 1 1 "BE0003836534" 62 2018 10 1300 8.310661 -.02614016 1 1 "BE0003842599" 66 2006 1 1300 5.347622 .03587965 1 1 "BE0003842599" 66 2008 2 1300 4.58181 .01093506 1 1 "BE0003842599" 66 2009 3 1300 5.048207 .07284538 1 0 "BE0003842599" 66 2010 4 1300 6.151794 -.41255212 1 1 "BE0003842599" 66 2012 5 1300 7.095313 -.01168723 1 1 "BE0003842599" 66 2015 6 1300 3.314949 -.04429593 1 0 "BE0003842599" 66 2016 7 1300 3.234749 -.03988214 1 0 "BE0003880979" 74 2009 1 3300 1.767634 -.08536929 1 1 "BE0003880979" 74 2010 2 3300 7.450254 .01134699 1 1 "BE0003880979" 74 2011 3 3300 5.093523 .06194886 1 1 "BE0003880979" 74 2012 4 3300 6.25308 -.08109841 1 0 "BE0003880979" 74 2014 5 3300 3.944993 -.0004153 1 0 "BE0974311434" 100 2006 1 1300 6.998039 .04681426 1 1 "BE0974311434" 100 2009 2 1300 7.041397 .13981319 1 0 "BE0974311434" 100 2010 3 1300 4.232148 .00432353 1 0 "BMG1965E1030" 112 2006 1 2300 3.993105 -.02984953 1 1 "BMG1965E1030" 112 2007 2 2300 4.947972 -.04190849 1 1 "BMG1965E1030" 112 2008 3 2300 2.6856 .10297616 1 0 "BMG1965E1030" 112 2009 4 2300 7.054832 .00032257 1 0 "BMG4209G2077" 114 2009 3 2100 4.317248 .13529109 1 0 "BMG4209G2077" 114 2010 4 2100 4.419816 -.06402538 1 0 "BMG4209G2077" 114 2012 5 2100 6.626143 .02006364 1 1 "BMG4209G2077" 114 2013 6 2100 8.537981 -.01450279 1 1 "BMG4209G2077" 114 2015 7 2100 6.892337 .03507049 1 1 "BMG4209G2077" 114 2017 8 2100 1.424072 .0632903 1 0 "BMG4209G2077" 114 2018 9 2100 5.061949 .02947732 1 0 "BMG702781094" 116 2006 1 1100 2.486738 -.004375 1 1 "BMG702781094" 116 2007 2 1100 8.527738 -.04832347 1 1 "BMG702781094" 116 2008 3 1100 3.555005 .11594357 1 0 "BMG702781094" 116 2009 4 1100 8.394121 .11413861 1 0 "BMG7300G1096" 117 2008 1 2200 4.350562 -.04569728 1 0 "BMG7300G1096" 117 2009 2 2200 4.670668 -.0125191 1 0 "BMG7300G1096" 117 2011 3 2200 5.819655 .08278646 1 1 "BMG7300G1096" 117 2012 4 2200 4.538304 .10775582 1 1 "BMG7300G1096" 117 2015 5 2200 .7645372 .24054198 1 0 "BMG7300G1096" 117 2016 6 2200 5.365429 .01595965 1 0 "CH0033050961" 131 2009 1 3300 .5959814 .25214871 1 0 "CH0033050961" 131 2015 2 3300 2.572689 .02587815 1 1 "CH0033050961" 131 2016 3 3300 7.542262 -.00043763 1 1 "CH0033050961" 131 2017 4 3300 3.875152 .13733377 1 1 "CH0033050961" 131 2018 5 3300 7.529029 -.0167142 1 1 "CH0308403085" 139 2012 1 2300 3.898995 .17339258 1 1 "CH0308403085" 139 2013 2 2300 5.806844 -.08750672 1 1 "CH0308403085" 139 2014 3 2300 2.436679 .15688426 1 1 "CH0308403085" 139 2016 4 2300 7.004542 .00505757 1 1 "CH0308403085" 139 2018 5 2300 4.484628 -.13198318 1 0 "CY0106002112" 146 2006 1 1100 9.517678 .10480292 1 1 "CY0106002112" 146 2007 2 1100 -1.129484 -.10615185 1 1 "CY0106002112" 146 2008 3 1100 7.952369 .05195113 1 1 "CY0106002112" 146 2009 4 1100 8.039093 -.00566787 1 1 "CY0106002112" 146 2010 5 1100 7.855545 .04086713 1 1 "CY0106002112" 146 2011 6 1100 7.104629 .06293849 1 1 "CY0106002112" 146 2012 7 1100 3.804371 -.13421425 1 1 "CY0106002112" 146 2013 8 1100 6.79205 .07629701 1 1 "CY0106002112" 146 2014 9 1100 5.649284 -.09918534 1 1 "CY0106002112" 146 2015 10 1100 6.79787 -.20053388 1 1 "CY0106002112" 146 2017 11 1100 7.775191 .05008816 1 0 "CY0106002112" 146 2018 12 1100 1.807961 .10037086 1 0 end