Dear statalisters,
I've encountered a problem related to generating duration variable.
I already search answers of similar questions in statlist, but I can not solve this problem.
I want to make a 'peaceyear' variable like below Table.
Of course, I attemped the code in statalist.
The code is
gen peaceyear = .
bysort dyad(year): replace peaceyear = cond(dispute==0, cond(_n>1, peaceyear[_n-1]+1, 1),1)
However, I can not make the variable correctly.
This is my result.
Please notice what's wrong my state code.
If it is difficult, I will use excel and make peaceyear variable.
Please help me.
Thank you.
regards,
Youngsang Lee
Yonsei univ.
I've encountered a problem related to generating duration variable.
I already search answers of similar questions in statlist, but I can not solve this problem.
I want to make a 'peaceyear' variable like below Table.
dyad | year | dispute | peaceyear |
2020 | 1950 | 0 | 1 |
2020 | 1951 | 0 | 2 |
2020 | 1952 | 0 | 3 |
2020 | 1953 | 1 | 4 |
2020 | 1954 | 0 | 0 |
2020 | 1955 | 0 | 1 |
2020 | 1956 | 0 | 2 |
Of course, I attemped the code in statalist.
The code is
gen peaceyear = .
bysort dyad(year): replace peaceyear = cond(dispute==0, cond(_n>1, peaceyear[_n-1]+1, 1),1)
However, I can not make the variable correctly.
This is my result.
dyad | year | dispute | peaceyear |
2020 | 1950 | 0 | 1 |
2020 | 1951 | 0 | 2 |
2020 | 1952 | 0 | 3 |
2020 | 1954 | 1 | 1 |
2020 | 1955 | 0 | 2 |
2020 | 1956 | 0 | 3 |
If it is difficult, I will use excel and make peaceyear variable.
Please help me.
Thank you.
regards,
Youngsang Lee
Yonsei univ.
Comment