我是Stata
中編程的新手。我的問題是在一個循環中運行幾雙迴歸,如下所示:通過在Stata循環中串聯一個字符串來定義一個變量
reg outcome1 outcome2 covariates
reg outcome2 outcome1 covariates
我嘗試以下方法,但前兩個附帶的錯誤「含糊的縮寫」,第二個錯誤「太少指定的變量「。任何人都可以幫我解決它嗎?
foreach dv in x y z {
local outcome1 = `dv' + "1"
local outcome2 = `dv' + "2"
reg `outcome1' `outcome2' covariates
reg `outcome2' `outcome1' covariates
}
foreach dv in nduration nsleep nwaso nlatency nfragmentation npctsleep {
gen outcome1 = `dv' + "1"
gen outcome2 = `dv' + "2"
reg `outcome1' `outcome2' covariates
reg `outcome2' `outcome1' covariates
}
foreach dv in x y z {
reg `dv'1 `dv'2 covariates
reg `dv'2 `dv'1 covariates
}
你的其他問題表明你已經安裝了R.你試圖做的事情需要在R中進行一些爭論,但是在Stata中它非常簡單(Nick在下面有完整的答案)。歡迎來到Stata :) –
謝謝!我很高興能夠學習Stata編程。 – Randel