Dear all,

I have a sample of panel data which contains data on a main firm: cik, a given year: year and the corresponding number of peer firms to a main firm:peercik (for each cik).

I would like to generate summary statistics (mean, median, minimum, maximum, st dev and N) for each year (my sample goes from 2006-2016).

However, I have to rearrange my data to find data I need: the mean, median, min, max, st dev, number of peers per cik per year.

I've tried the following:

sort year cik peercik
replace peercik=1
by year cik: egen npeer_cik=sum(peercik) if _n==1

However this does not work. Can anyone help me to find the average peercik statistics per year?

Best regards,
Patrick