I was suprised to see that the last two commands ("replace new_var = 0 [...] and replace new_var = 2 [...]) add new cases to the variabel new_var.
For me, this was counterintuitive. Do the results imply that the code...

Code:
if old_var1 == old_var2 == old_var3
...is interpretated as a TRUE/FALSE statement with at least one value 1 necessary for the statement to be defined as TRUE?

Code:
gen new_var = .
// My original code, brackets added after "if" for clarity
replace new_var = old_var1 if (old_var1 == old_var2 == old_var3)
tab new_var // see Table 1 below

// Question: Why do each of these lines add cases to new_var?
replace new_var = 0 if old_var1==0 & old_var2==0 & old_var3==0
tab new_var // see Table 2 below

replace new_var = 2 if old_var1==2 & old_var2==2 & old_var3==2
tab new_var // see Table 3 below

Table 1

new_var | Freq. Percent Cum.
------------+-----------------------------------
0 | 1 2.56 2.56
1 | 38 97.44 100.00
------------+-----------------------------------
Total | 39 100.00



Table 2

new_var | Freq. Percent Cum.
------------+-----------------------------------
0 | 6 13.64 13.64
1 | 38 86.36 100.00
------------+-----------------------------------
Total | 44 100.00



Table 3

new_var | Freq. Percent Cum.
------------+-----------------------------------
0 | 6 11.32 11.32
1 | 38 71.70 83.02
2 | 9 16.98 100.00
------------+-----------------------------------
Total | 53 100.00