Search code examples
stata

creating lagged variables according to exposure of each observation


I have grouped cross-section data and I want to generate some variables that reflect the level of exposure of each observation according to a certain date. I have individuals who were born at different times and lived in different cities. I also have another database that represents the level of exposure to my variable (conflict) across time for each city.

enter image description here

So, what I want to do is create a variable that indicates the exposure of each individual to conflict the year before birth and the year after (taking into account that individuals were only interviewed once).


Solution

  • I solved this the long way. I generated different lagged variables for each individual and later generated a variable corresponding to conflict on the year before birth based on several conditions. For example:

        gen conflict_birth= conflict-1 if year==yearofbirth+1
    

    and so on for the rest of individuals.