Hello everybody,
I hope you all are doing well,
I am working on financial distress as a dummy variable that equals one if the firms face financial distress and zero otherwise. I have unbalanced panel data from 1978-2016.
So, I want to generate a variable that counts how many years the firms has spent in financial distress.plesae, could anyone help me to do that?
I tried to use the following commands:
gen year_in_distress=0
gen dissyear=year* fdistress
sort id year
by id: egen minyear= min(dissyear) if dissyear>1
by id: replace year_in_distress=year-minyear+1 if dissyear>1
drop dissyear minyear
These commands gave me these results:
id year fdistress year_in_distress
1006 1978 0 0
1006 1979 1 1
1006 1980 1 2
1006 1981 0 0
1006 1982 1 4
I hope you all are doing well,
I am working on financial distress as a dummy variable that equals one if the firms face financial distress and zero otherwise. I have unbalanced panel data from 1978-2016.
So, I want to generate a variable that counts how many years the firms has spent in financial distress.plesae, could anyone help me to do that?
I tried to use the following commands:
gen year_in_distress=0
gen dissyear=year* fdistress
sort id year
by id: egen minyear= min(dissyear) if dissyear>1
by id: replace year_in_distress=year-minyear+1 if dissyear>1
drop dissyear minyear
These commands gave me these results:
id year fdistress year_in_distress
1006 1978 0 0
1006 1979 1 1
1006 1980 1 2
1006 1981 0 0
1006 1982 1 4
Comment