Hi
I am doing some coding were I am looking if an ID for an individual change between two years or not (1 for a change and 0 if the values are the same). I have one variable for each ID and year. Now I want to create new variables identifying the differences for each year, stretching over a time period of 20 years. I know how to do this manually but I want to this more efficient in a loop. Any experts that help me?
My code for each individual year.
Differences in the year 1975
gen Different_ID1975 = 0
replace Different_ID1975= 1 if ID1975!=ID1974
replace Different_ID1975 = . if ID1975== . | ID1974==.
Year 1976
....
I am doing some coding were I am looking if an ID for an individual change between two years or not (1 for a change and 0 if the values are the same). I have one variable for each ID and year. Now I want to create new variables identifying the differences for each year, stretching over a time period of 20 years. I know how to do this manually but I want to this more efficient in a loop. Any experts that help me?
My code for each individual year.
Differences in the year 1975
gen Different_ID1975 = 0
replace Different_ID1975= 1 if ID1975!=ID1974
replace Different_ID1975 = . if ID1975== . | ID1974==.
Year 1976
....
Comment