Hello,
I would like to assign values for a macro based on an if condition that contains a normal string variable. Then the for loop will loop through and replace the macro depending on the name the loop is on.
local cov2 = "lntrig bmi"
foreach cov of local cov2 {
if "`cov'"==var local r2 = r2_m1
di "`cov'"
di "`r2'" _newline
}
I would like the above to display
lntrig
.4124405
bmi
.3975436
However, it displays the following instead. 0.28059... seems to be the value for ages.
lntrig
.28059121966362
bmi
.28059121966362
I would like to assign values for a macro based on an if condition that contains a normal string variable. Then the for loop will loop through and replace the macro depending on the name the loop is on.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str20 var float r2_m1 "ages" .28059122 "bmi" .3975436 "dbp" .4121804 "hdl" .3830052 "lncreat" .3973525 "lncrp" .4424658 "lntrig" .4124405 "sbp" .3837971 "tchol" .3834501 end
local cov2 = "lntrig bmi"
foreach cov of local cov2 {
if "`cov'"==var local r2 = r2_m1
di "`cov'"
di "`r2'" _newline
}
I would like the above to display
lntrig
.4124405
bmi
.3975436
However, it displays the following instead. 0.28059... seems to be the value for ages.
lntrig
.28059121966362
bmi
.28059121966362
Comment