I am trying to calculate the number of unique values over the previous 5 years but having trouble.
I think ssc rangestat would be the simplest solution, but I don't think it has the capability to count unique values.
This topic is closely related but not exactly what I am trying to do.
For example, if I wanted to calculate the number of unique suppliers for firms over the previous 5 years, is there a simple way to do that?
If rangestat had the capability, the code would look something like:
It seems I probably have to create groups based on years and firms and then do something like:
where yeargroup contains the previous 5 years.
Is there a simple way to create that yeargroup variable?
I think ssc rangestat would be the simplest solution, but I don't think it has the capability to count unique values.
This topic is closely related but not exactly what I am trying to do.
For example, if I wanted to calculate the number of unique suppliers for firms over the previous 5 years, is there a simple way to do that?
Code:
clear input float(firm supplier date) 1 11 1999 1 12 2001 1 13 2002 1 14 2000 1 15 2004 2 16 1980 2 17 1981 2 18 1982 2 19 1985 2 20 1987 3 21 1980 3 22 1981 3 23 1982 3 24 1985 3 25 1987 end
If rangestat had the capability, the code would look something like:
Code:
rangestat distinct (supplier), interval(date -5 -1) by(firm)
It seems I probably have to create groups based on years and firms and then do something like:
Code:
egen ndistinct = total(supplier), by(firm yeargroup)
Is there a simple way to create that yeargroup variable?
Comment