Dear all,

I have a question that I think should be pretty straightforward for some of the power users on this forum. Research shows that in evaluating their performance, firms compare themselves to their closest peers not their entire industry. So, I need to select 5 firms that are closest to the focal firm in size. My data consists of the following columns: firm_code, country_code, industry_code, year, total_assets, net income (among others). I generated a rank for each firm in terms of total assets within each country, industry and year, now I want to compute the performance of peer group (so, 5 closest firms in size). If a firm is ranked 1, it could be firms ranked 2-6, but if a firm is ranked 21, it could be firms ranked above and below (firms closest in size). What would be the Stata command to identify/ compute? Thanks so much for your help in advance!

Best,
Pete