Hello Stata users
I have been wrestling with this issue and have came to a conclusion that I need some help.
Basically, I am trying to create a dummy variable (maintain) that holds the value of 1 if in a given year, a firm (panelid2) has a same value of the relationship variable with the immediate preceding year (fyear).
Because my data has multiple observations per year, I am encountering difficulties.
To give you an example, firm with panelid2 1 in year 1985 has two observations where the relationship value is 24 (USA).
Now the same firm has two observations in 1984 that also have the relationship value of 24 (USA).
In such cases, I wish to create a variable (maintain) that holds the value of 1. If there are no observations in the immediate preceding year of the same firm that has the same value for the relationship variable, the maintain variable should hold the value of 0.
In a similar sense, for observations 15 and 16, the maintain variable should also be 1, whereas observation 14 should be zero.
Could anyone provide any guidance in this matter?
My sincerest thanks in advance.
Thank you.

I have been wrestling with this issue and have came to a conclusion that I need some help.
Basically, I am trying to create a dummy variable (maintain) that holds the value of 1 if in a given year, a firm (panelid2) has a same value of the relationship variable with the immediate preceding year (fyear).
Because my data has multiple observations per year, I am encountering difficulties.
To give you an example, firm with panelid2 1 in year 1985 has two observations where the relationship value is 24 (USA).
Now the same firm has two observations in 1984 that also have the relationship value of 24 (USA).
In such cases, I wish to create a variable (maintain) that holds the value of 1. If there are no observations in the immediate preceding year of the same firm that has the same value for the relationship variable, the maintain variable should hold the value of 0.
In a similar sense, for observations 15 and 16, the maintain variable should also be 1, whereas observation 14 should be zero.
Could anyone provide any guidance in this matter?
My sincerest thanks in advance.
Thank you.
Comment