*ssc install dataex*
clear
input byte (id gender at_risk lep)
1 . . 1
2 2 1 1
3 1 2 2
4 2 2 2
5 1 1 2
6 2 2 1
7 1 1 2
8 2 1 1
9 2 2 1
10 1 2 1
11 2 2 2
12 1 1 2
13 2 1 2
14 2 2 1
15 . . .
end

The previous solution really works for the dataset with complete cases. However, if I directly used the code as follows, the result is incorrect. https://www.statalist.org/forums/forum/general-stata-discussion/general/1507388-changing-values-of-yes-no-binary-variables-from-1-2-to-1-0-using-loop Can anybody give me some hints? Thanks!