I am new to programming in Stata. My question is to run several pairs of regressions in a loop, like the following:
reg outcome1 outcome2 covariates
reg outcome2 outcome1 covariates
I tried the following ways, but the first two came with the error "ambiguous abbreviation" and the second the error "too few variables specified". Can anyone help me to fix it?
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
}