Dear Statalist,

I would like to make a table that shows the frequency of the 2 highest sales in the countries by year and month. As an example this is the data:
year month country sales
2019 dic ECU 1500
2018 dic ARG 100
2018 nov BRA 6000
2018 dic COL 1000
2018 dic PER 150
2019 nov COL 25
2019 nov PAR 43
2018 nov ECU 25
2018 nov ARG 50
2019 nov MEX 45
2019 dic USA 10000
2018 nov MEX 700
2019 nov ECU 43
2018 dic BRA 80000
2018 nov ARG 25000
2019 nov PAR 45000
2018 nov BRA 10000
2019 dic BRA 1450
2019 dic BRA 64000
The table I would like to obtain is this:
2018 sales (sum)
dic
BRA 80000
COL 1000
nov
ARG 25050
BRA 16000
2019
dic
BRA 65450
USA 10000
nov
PAR 45043
MEX 45

I have tried to make the table through the following command:

bysort year month: tabstat sales, by (country) stat(sum) col(stat) long

But it shows the results in several tables and not only in one. It also does not show only the two highest sales.


Thanks in advance.

Best