Hi, I have the following data structure (although more data points). How can I instruct Stata to replace x with 1 for wave 2, if the data has the same id? Can I do it with foreach?
-
Login or Register
- Log in with
replace x = 1 if (wave == 2) & (some other condition involving "same id")
replace x = 1 if (wave == 2) & (some other condition involving "same id")
sort id wave replace x=1 if (wave==2 & id==id[_n-1] & wave[_n-1]==1)
sort id wave replace x=x[_n-1] if (wave==2 & id==id[_n-1] & wave[_n-1]==1)
sort id wave replace x=1 if (wave==2 & id==id[_n-1] & wave[_n-1]==1)
sort id wave replace x=x[_n-1] if (wave==2 & id==id[_n-1] & wave[_n-1]==1)
sort id wave replace x=1 if (wave==2 & id==id[_n-1] & x[_n-1]==1)
Comment