Hi Stata folks
Here is an example of my data.
"high" is a variable that I have constructed which consists of only observations above an absolute threshold that I have picked.
I want to count the number of incidences of high. This is fairly easy to do by:
However, what I want to do is to count the number of incidences of high every block of five available years. (available because there are some year gaps and I want to think of the next available year as the next year; also there could be less than 5 years available after any given block like for firm number 1005, in which case I want to count for the remaining firms).
So instead of having a value of 8 for firm number 1007 from 1974-1984, I want to have 4 for 1974-1978 and then 4 for 1979 - 1984
How do I do this? Please help.
This will also help me in doing similar things for five year blocks.
Here is an example of my data.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int(firm_id year) float high 1005 1974 . 1005 1975 49.5 1005 1976 . 1005 1977 58.8 1005 1979 43 1005 1980 . 1005 1981 . 1007 1974 . 1007 1975 -249.6 1007 1976 -43.6 1007 1977 -186.6 1007 1978 -498.9 1007 1979 101.9 1007 1980 -175.7 1007 1981 -59.1 1007 1984 -213.1 end
"high" is a variable that I have constructed which consists of only observations above an absolute threshold that I have picked.
I want to count the number of incidences of high. This is fairly easy to do by:
Code:
bysort firm_id: egen highfreq = count(high) if high != .
So instead of having a value of 8 for firm number 1007 from 1974-1984, I want to have 4 for 1974-1978 and then 4 for 1979 - 1984
How do I do this? Please help.
This will also help me in doing similar things for five year blocks.
Comment