Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Coding when having multiple observations per year.

    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.
    Click image for larger version

Name:	screen.png
Views:	1
Size:	40.3 KB
ID:	1730519

    Last edited by Yun Dong Yeo; 16 Oct 2023, 22:18.

  • #2
    Yun:
    while I'm not clear with what you're after, I would give -group- function from -egen- a shot.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment

    Working...
    X