Hi, I want to draw a random sample out of my existing data. In my sample are observations which are deals (deal =1) and observations which are peer companies (deal = 0). I want to to have 5 peer companies per acquiring company of the deal (cusip_a as company identifier). The observations drawn from the overall sample with deal = 0 should only match on the Year. I added the code I'm currently using, but I do not know how to include that the year should be the same.
Code:
quietly count if deal == 1 local num_deals = r(N)*5 display `num_deals' sample `num_deals' if deal == 0, count
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str6 cusip_a float(Year deal) "30231G" 2020 0 "084670" 2022 0 "03743Q" 2015 0 "165167" 2015 0 "02376R" 2020 0 "097023" 2020 0 "910047" 2020 0 "165167" 2009 0 "185899" 2014 0 "674599" 2015 0 "247361" 2020 0 "345370" 2006 0 "032511" 2015 0 "76954A" 2022 0 "26875P" 2015 0 "69047Q" 2015 0 "166764" 2016 0 "02376R" 2021 0 "20825C" 2015 0 "42809H" 2017 0 "69047Q" 2020 0 "925550" 2001 0 "53601P" 2015 0 "13057Q" 2015 0 "166764" 2020 0 "24790A" 2015 0 "651290" 2015 0 "844741" 2020 0 "674215" 2020 0 "20825C" 2016 0 "69331C" 2000 0 "549463" 2002 0 "910047" 2021 0 "03743Q" 2020 0 "69047Q" 2012 0 "966387" 2020 0 "25179M" 2009 0 "345370" 2008 0 "268785" 2015 0 "V7780T" 2021 0 "25179M" 2008 0 "92343E" 2001 1 "92343E" 2001 1 "165167" 2016 0 "651639" 2013 0 "166764" 2015 0 "42809H" 2016 0 "92343E" 2000 1 "626717" 2015 0 "V7780T" 2020 0 "903914" 2015 0 "90353T" 2021 0 "20825C" 2020 0 "845467" 2020 0 "25179M" 2020 0 "07134L" 2015 0 "03940R" 2015 0 "152312" 2007 0 "94770V" 2000 0 "565849" 2015 0 "36399D" 2008 0 "03743Q" 2019 0 "526057" 2007 0 "94770V" 2001 0 "02376R" 2002 0 "549498" 2022 0 "G66721" 2021 0 "69367F" 2001 0 "903914" 2012 0 "247361" 2021 0 "23331A" 2008 0 "629377" 2015 0 "42809H" 2020 0 "516806" 2015 0 "35671D" 2016 0 "075896" 2022 0 "42809H" 2015 0 "451100" 2008 0 "858098" 2001 0 "18538Q" 2011 0 "18538Q" 2010 0 "37611X" 2022 0 "858098" 2000 0 "552953" 2020 0 "812350" 2017 0 "477143" 2020 0 "75281A" 2019 0 "03840P" 2002 0 "559663" 2020 0 "723787" 2015 0 "745867" 2007 0 "812350" 2016 0 "G66721" 2020 0 "02376R" 2001 0 "69047Q" 2016 0 "925550" 2002 0 "451100" 2020 0 "69367F" 2000 0 "13057Q" 2020 0 "20605P" 2016 0 end
Comment