This isn't an answer, but won't fit easily into a comment. I don't even attempt R code. It seems to me that fluent R coders, not me, can reasonably expect, as an absolute minimum, some clarity on how you are holding the data in R.
The Stata syntax here is far from current, but was obsolete as of Stata 7. for
in the sense here is not even documented any more.
This doesn't qualify as a minimal, complete, verifiable example: https://stackoverflow.com/help/mcve
for any out temp emp edu married inc age \ var cesd1998 bitemp96 employ94 edu93 married94 inc94 age94 : gen XM2=Y if H0000200==1998
for any out temp emp edu married inc age \ var cesd2000 bitemp98 employ96 edu95 married96 inc96 age96 : replace XM2=Y if H0000200==2000
One translation into current Stata is
local x1list "out temp emp edu married inc age"
local x2list "out temp emp edu married inc age"
local y1list "cesd1998 bitemp96 employ94 edu93 married94 inc94 age94"
local y2list "cesd2000 bitemp98 employ96 edu95 married96 inc96 age96"
local nvars : word count `x1list'
forval j = 1/`nvars' {
local x : word `j' of `x1list'
local y : word `j' of `y1list'
replace `x'M2 = `y' if H0000200==1998
local x : word `j' of `x2list'
local y : word `j' of `y2list'
replace `x'M2 = `y' if H0000200==2000
}
Not at all central, but note in passing that one reason the code is so awkward is that your naming conventions for variables are not consistent.