これは答えではありませんが、コメントに簡単に収まりません。私はRコードを試みることさえしません。私ではなく、流暢な R コーダーは、R でデータをどのように保持しているかについて、最低限の明確さを合理的に期待できるように思えます。
ここでの Stata 構文は最新のものとはかけ離れていますが、Stata 7 の時点で廃止されました。forその意味で、ここでは文書化さえされていません。
これは、最小限の、完全な、検証可能な例とは言えません: 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
現在のStataへの1つの翻訳は
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
}
まったく中心的ではありませんが、コードが非常に扱いにくい理由の 1 つは、変数の命名規則が一貫していないことに注意してください。