我是编程新手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
}