Dear Statalist,

I would like to randomly pair one sample of firms with another sample of firms drawn from the first sample firms' industry in the year of deal announcement. And then I want to bootstrap the process 500 times with replacements for each deal and report the average ownership for these simulated pairings. What I want to examine is whether two firms are more likely to merge together in the presence of higher ownership. The following is my trial codes but I'm not sure if I am on the right track. Can anyone help me with that, please?

Code:
use "data1.dta", clear

keep id fyear
duplicates drop
save "holding.dta"

forvalues i = 1/500 {

    use "target1.dta", clear
    keep id fyear dateanno
    save "working_data.dta"

  
    use "holding.dta", clear
    bsample
   merge 1:m id fyear using "working_data.dta", assert (match using) keep(match)
gen Target = 1
replace Target = 0 if dateanno ==.
 save "MA_bootstrap`i'.dta", replace
}
I tried to use -bootstrap- but don't know how to program it for randomly pairing datasets...

Here is my sample data: For missing observations in dataanno, they are no deals announced on that year.


----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input long id double fyear long dateanno double ownership float industry
1004 1999     . .11129193007946014 50
1004 2000     .                  0 50
1004 2013     .                  0 50
1004 2014     .                  0 50
1004 2015     .                  0 50
1004 2016     .                  0 50
1009 1992     .  .6800046563148499 34
1009 1993     .  .6899944543838501 34
1009 1994     .  .6399991512298584 34
1013 2003     .  .4449999928474426 36
1013 2004     .  .4630001187324524 36
1013 2005     .  .4267875552177429 36
1013 2006     .   .439971923828125 36
1013 2007     .  .4560580849647522 36
1013 2008     . .42502060532569885 36
1013 2009 18456  .3802548348903656 36
1013 2010     . .38561299443244934 36
1050 2008     .                  0 35
1055 1990     .                  0 35
1055 1991     .                  0 35
1056 1998     . .15499617159366608 36
1056 2001     . .10799886286258698 36
1056 2002     . .10799767076969147 36
1072 2013     .                  0 36
1072 2014     .                  0 36
1072 2015     .                  0 36
1072 2016     .                  0 36
1072 2017     .                  0 36
1073 1990     .  .6103059649467468 73
1073 1991     .  .7399349808692932 73
1073 1992     .  .6599476933479309 73
1073 1995     .  .5800233483314514 73
1082 1989     .  .4799616038799286 15
1082 1990     .    .66282719373703 15
1082 1991     .  .7242097854614258 15
1082 1996     .  .5123208165168762 15
1094 2003     .                  0 51
1094 2011     .                  0 51
1094 2012     .                  0 51
1094 2013     .                  0 51
1094 2014     .                  0 51
1094 2015     . .13000068068504334 51
1094 2016     .  .1399993598461151 51
1094 2017     . .22999978065490723 51
1109 1995     .                  0 20
1109 1996     .                  0 39
1109 2005     .   .360088586807251 39
1109 2006     . .34005647897720337 39
1109 2007     . .23000000417232513 39
1109 2008     .  .2499537467956543 39
1111 1989     . .18999235332012177 73
1111 1994     . .14999139308929443 73
1111 1995     . .13999967277050018 73
1111 2001     . .28000059723854065 73
1111 2002     .  .1600005030632019 73
1111 2003     . .19999979436397552 73
1111 2004     . .22999991476535797 73
1111 2005     .  .3199999928474426 73
1111 2006     .  .2200002372264862 73
1121 1990     .  .4368971586227417 51
1121 1991     .  .4887270927429199 51
1121 1992     . .12298694998025894 51
1121 1993     .                  0 51
1121 1997     .   .268926739692688 51
1121 1998     . .16158509254455566 51
1121 1999     . .14140990376472473 51
1121 2000     . .14753295481204987 51
1121 2003     .  .1027916967868805 51
1121 2006     .  .4178103506565094 51
1121 2007     .  .6908037066459656 51
1121 2008     .  .5660001635551453 51
1121 2009     .  .7279999256134033 51
1121 2010     .  .9790001511573792 51
1121 2011     .  .5829998254776001 51
1121 2012     .  .5490002036094666 51
1121 2013     .   .624000072479248 51
1121 2014     .  .3430001735687256 51
1121 2015     .   .382000207901001 51
1121 2016     .  .6119995713233948 51
1121 2017     .  .6139993667602539 51
1121 2018     . .41399991512298584 51
1121 2019     . .48699983954429626 51
1137 1990     .  .1469968557357788 36
1137 1991     .                  0 36
1137 1992     . .10199470818042755 36
1137 1993     .    .25900799036026 36
1137 1994     .  .1749972105026245 36
1151 1989     .                  0 38
1151 1990     .                  0 38
1151 1991     .                  0 38
1151 1992     .                  0 38
1151 1993     .                  0 38
1151 1994     .                  0 38
1151 1995 13402                  0 38
1161 1990     .                  0 36
1161 1996     . .12999975681304932 36
1161 1997     . .11999957263469696 36
1161 1998     . .12000003457069397 36
1161 2004     .                  0 36
1161 2005     .  .2659221291542053 36
end
format %d dateanno
------------------ copy up to and including the previous line ------------------

Listed 100 out of 39343 observations
Use the count() option to list more

.