Hi,
I am trying to average certain variables two years before a reference year (yr_treated), which is different for each ID. For example, I have:
ID yr yr_treated var newvar
1 1990 1992 32
1 1991 1992 35
1 1992 1992 38
2 1990 1993 57
2 1991 1993 50
2 1992 1993 46
2 1993 1993 48
So for ID = 1, I want the new var to be an average of var in 1990 and 1991 since the yr_treated is 1992 (so new var would be an average of 32 and 35) and
for ID=2, I want the new var to be an average of var in 1991 and 1992 since the yr_treated is 1993 (so new var for ID = 2 would be an average of 50 and 46).
I've tried using the egen command with mean and then year[_n-1] and year[_n-2] but I'm not sure if this is the right approach.
Any help would be useful, thank you!!
I am trying to average certain variables two years before a reference year (yr_treated), which is different for each ID. For example, I have:
ID yr yr_treated var newvar
1 1990 1992 32
1 1991 1992 35
1 1992 1992 38
2 1990 1993 57
2 1991 1993 50
2 1992 1993 46
2 1993 1993 48
So for ID = 1, I want the new var to be an average of var in 1990 and 1991 since the yr_treated is 1992 (so new var would be an average of 32 and 35) and
for ID=2, I want the new var to be an average of var in 1991 and 1992 since the yr_treated is 1993 (so new var for ID = 2 would be an average of 50 and 46).
I've tried using the egen command with mean and then year[_n-1] and year[_n-2] but I'm not sure if this is the right approach.
Any help would be useful, thank you!!