Greetings,
I was wondering if someone could help me with this issue. I'm working with a compustat data set that goes from 1984Q1-2014Q4 .
I have a panel with firm id and date (year-quarter) and I need to identify spells of consecutive observations for each firm. I was thinking in doing the following: first create a variable (call it time) that is a one-to-one mapping with the date. For example, if year=1984 and quarter=1, then time=1...... if year=1985 and quarter=2, then time=6........ if year=2014 and quarter=4 then time=124.
then i could do
tsset id time
gen run = .
by id: replace run = cond(L.run == ., 1, L.run + 1)
by id: egen maxrun = max(run)
any suggestion on how to build this variable time? or maybe there's a much easier way to achieve this? My goal is to identify for each firm, the longest spell of consecutive observations and drop all the others.
thank you
Tomás
I was wondering if someone could help me with this issue. I'm working with a compustat data set that goes from 1984Q1-2014Q4 .
I have a panel with firm id and date (year-quarter) and I need to identify spells of consecutive observations for each firm. I was thinking in doing the following: first create a variable (call it time) that is a one-to-one mapping with the date. For example, if year=1984 and quarter=1, then time=1...... if year=1985 and quarter=2, then time=6........ if year=2014 and quarter=4 then time=124.
then i could do
tsset id time
gen run = .
by id: replace run = cond(L.run == ., 1, L.run + 1)
by id: egen maxrun = max(run)
any suggestion on how to build this variable time? or maybe there's a much easier way to achieve this? My goal is to identify for each firm, the longest spell of consecutive observations and drop all the others.
thank you
Tomás
Comment