I am currently working on a panel dataset (15 EU countries for 15 years) that comprises of approximately 7000 data. Based on the dataex provided below, I would like to form a peer group for each ISINyear (company id) variable based on the variable WM which contains a score that varies for each company identifier for every year. I want to form a peer group in a size of 4 for each ISINyear (company) that should satisfy these conditions:
1. peer group in size of four, is formed based on four other company closest/nearest WM score with the target company.
2. peer could not belong to the same country as the target firm, yet still within the same year of observation.
Each variable that has been selected should be able to get picked again for another company. Should there are five companies with the same score, the peer could be chosen randomly. Lastly, after four companies are defined as the peers for the target firm, I would like to obtain the mean of the defined peer group PB variable, presumably in a newly generated variable.
----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str16 ISINyear str3 CurrentISOCountryCodeIncor float(WM PB) int year "FR00000525162006" "FRA" 90.26172 3.0738685 2006 "FR00000525162007" "FRA" 90.26172 3.502112 2007 "DE00070740072008" "DEU" 88.95918 8.301935 2008 "GRS2841830012008" "GRC" 88.95918 .4692065 2008 "FR00000525162008" "FRA" 88.95918 2.175335 2008 "FR00000525162009" "FRA" 95.29973 2.449753 2009 "DE00070740072009" "DEU" 95.29973 10.180838 2009 "GRS2841830012009" "GRC" 95.29973 .4450149 2009 "GRS2841830012010" "GRC" 104.36723 .55562204 2010 "FR00000525162010" "FRA" 104.36723 2.1385944 2010 "DE000A0M6M792010" "DEU" 104.36723 1.9217272 2010 "DE00070740072010" "DEU" 104.36723 10.33614 2010 "DE00070740072011" "DEU" 100.76558 11.0161 2011 "FR00000525162011" "FRA" 100.76558 1.9883522 2011 "GRS2841830012011" "GRC" 100.76558 .29267552 2011 "DE00070740072012" "DEU" 52.92004 15.959933 2012 "FR00000525162012" "FRA" 52.92004 2.3490067 2012 "GRS2841830012012" "GRC" 52.92004 .4214217 2012 "FR00000525162013" "FRA" 61.94163 2.2705362 2013 "DE00070740072013" "DEU" 61.94163 13.59248 2013 "GRS2841830012013" "GRC" 61.94163 .4789082 2013 "FR00000525162014" "FRA" 56.32935 1.820148 2014 "DE00070740072014" "DEU" 56.32935 14.16732 2014 "GRS2841830012014" "GRC" 56.32935 .6914167 2014 "DE00070740072015" "DEU" 47.15211 12.891316 2015 "GRS2841830012015" "GRC" 47.15211 2.0456204 2015 "FR00000525162015" "FRA" 47.15211 1.2696 2015 "GRS2841830012016" "GRC" . 3.483192 2016 "FR00000525162016" "FRA" . 1.2957324 2016 "DE00070740072016" "DEU" . 12.624042 2016 "GRS2010030192002" "GRC" . .1711396 2002 "GRS2010030192003" "GRC" . .21721806 2003 "GRS2010030192004" "GRC" . .3559328 2004 "FR00001317572003" "FRA" 30.296736 1.428482 2003 "FR00001317572005" "FRA" 33.633835 1.895018 2005 "FR00001317572008" "FRA" 36.465347 1.5608405 2008 "AT00000ATEC92008" "AUT" 36.465347 .5215496 2008 "AT00000ATEC92009" "AUT" 36.465347 .6974818 2009 "GRS3935030082009" "GRC" 36.465347 .8028448 2009 "FR00001317572009" "FRA" 36.465347 2.7713785 2009 "FR00001317572010" "FRA" 31.74601 2.3749483 2010 "GRS3935030082010" "GRC" 31.74601 .8398629 2010 "FR00001317572011" "FRA" 20.858995 .9285181 2011 "GRS3935030082011" "GRC" 20.858995 .399087 2011 "FR00001317572012" "FRA" 11.381454 .7312967 2012 "GRS3935030082012" "GRC" 11.381454 .5881699 2012 "FR00001317572013" "FRA" -2.7084286 .9373043 2013 "GRS3935030082013" "GRC" -2.7084286 .9195927 2013 "GRS3935030082014" "GRC" -6.021147 .6953707 2014 "FR00001317572014" "FRA" -6.021147 .9602507 2014 "FR00001317572015" "FRA" . .43921465 2015 "GRS3935030082015" "GRC" . .4231185 2015 "FR00001317572016" "FRA" . .7215712 2016 "FR00103977602016" "FRA" . 1.5449473 2016 "GRS3935030082016" "GRC" . .8319205 2016 "FR00131818642002" "FRA" .6516934 .31987685 2002 "FR00131818642003" "FRA" .6516934 .9698271 2003 "FR00131818642005" "FRA" -1.4012986 2.428733 2005 "IT00052521402005" "ITA" -1.4012986 4.1117234 2005 "AT00007430592006" "AUT" -1.4012986 2.0502448 2006 "IT00052521402006" "ITA" -1.4012986 4.7146993 2006 "FR00131818642006" "FRA" -1.4012986 2.605061 2006 "AT00007430592007" "AUT" 20.08488 1.558389 2007 "IT00052521402007" "ITA" 20.08488 3.83814 2007 "FR00131818642007" "FRA" 20.08488 1.5033473 2007 "AT00007430592013" "AUT" 3.691945 .9262624 2013 "IT00052521402013" "ITA" 3.691945 1.3275653 2013 "AT00007430592014" "AUT" 3.691945 .7292546 2014 "IT00052521402014" "ITA" 3.691945 .797046 2014 "FR00103771272014" "FRA" 3.691945 .9565661 2014 "IT00052521402015" "ITA" 70.40891 .27470592 2015 "FR00103771272015" "FRA" 70.40891 .9916122 2015 "AT00007430592015" "AUT" 70.40891 .69217 2015 "FR00103771272016" "FRA" . 1.5045315 2016 "AT00007430592016" "AUT" . 1.1086997 2016 "IT00052521402016" "ITA" . .09065073 2016 "GRS3720030042013" "GRC" . 1.63674 2013 "GRS1450030002004" "GRC" -158.87476 .8783258 2004 "DE00060700062006" "DEU" -167.8827 2.807499 2006 "GRS1450030002006" "GRC" -167.8827 2.483208 2006 "DE00060700062007" "DEU" -167.8827 1.6575663 2007 "FI00098006432007" "FIN" -167.8827 3.0247865 2007 "GRS1450030002007" "GRC" -167.8827 1.3069142 2007 "FI00098006432008" "FIN" -172.6998 .8926127 2008 "GRS1450030002008" "GRC" -172.6998 .6546887 2008 "DE00060700062008" "DEU" -172.6998 1.0139452 2008 "NL00092691092008" "NLD" -172.6998 .11335886 2008 "GRS1450030002009" "GRC" -177.02313 .8130502 2009 "NL00092691092009" "NLD" -177.02313 .631114 2009 "FI00098006432009" "FIN" -177.02313 2.818069 2009 "DE00060700062009" "DEU" -177.02313 1.9107054 2009 "FI00098006432010" "FIN" -177.3542 3.105407 2010 "GRS1450030002010" "GRC" -177.3542 .4651518 2010 "NL00092691092010" "NLD" -177.3542 .8515041 2010 "DE00060700062010" "DEU" -177.3542 1.895007 2010 "DE00060700062011" "DEU" -182.0614 1.3275746 2011 "NL00092691092011" "NLD" -182.0614 .3881037 2011 "GRS1450030002011" "GRC" -182.0614 .179876 2011 "FI00098006432011" "FIN" -182.0614 2.2997575 2011 "FI00098006432012" "FIN" -196.83437 2.0626721 2012 end
Listed 100 out of 7318 observations
Use the count() option to list more
To be honest, I am entirely new to Stata, and I have no clue on how to solve this type of situation. Therefore, your suggestions and inputs are highly appreciated
Thank you in advance.
Best,
Kevin
0 Response to Creating peer group based on a score with an if conditions, and calculate the mean.
Post a Comment