Stata-style conditional replace, preserving the existing value on NA
Source: R/utils-panel.R
stata_replace.RdReproduces Stata's replace x = value if cond: rows where cond is
FALSE or NA keep their current value of x unchanged; only rows
where cond is definitely TRUE get value. This differs from
dplyr::if_else(), which returns NA when cond is NA — correct for a
fresh gen-style computation (there is no "existing value" to fall back
to), but wrong for a replace, where an unresolved condition must leave
the row exactly as it was. Used throughout the sequential-overwrite
classification rules (tech_grad, ind_a38, type, FOLLOW/LEAD, ...)
documented in Pseudocode/*.md as "later rule overwrites earlier" chains.