Hello,
I am trying to learn how to write loops to perform commands on multiple variables at once. In the following code, I try to write a loop that runs Wilcoxon's rank sum test on 14 continuous variables. The loop runs without error, but I can't figure out how to get the results to display. I don't know where they go/how to call them.
My code:
#local continuous gm_csf ifn_g il_2 il_7 il_5 il_10 il_13 il_15 il_17 tnf_a mcp_1
#foreach var of local continuous {
ranksum `var' if `var'!=0, by(sptb_new)
}
I have also tried to apply Matthew McKay's code from looking back in this forum on related topics:

** Program pe:
Print Execute **
#program define pe
# version 12.0
# if `"`0'"' != "" {
# display as text `"`0'"
' # `0' # display("")
# }
#end
One can just prepend pe to each line within the foreach loop.
#sysuse auto
#levelsof rep78, local(levs)
#foreach lev in `levs' {
# pe regress price weight if rep78==`lev'
#}
Applying this, I wrote the following code:
#program define pe version 12.0 if `"`0'"' != ""
{ display as text `"`0'"' `0' display("") } end
#foreach var of local continuous {
pe ranksum `var' if `var'!=0, by(sptb_new)
}
However, I am still not getting anything. The only output I see is:
. foreach var of local continuous {
2. pe ranksum `var' if `var'!=0, by(sptb_new)
3. }
.
end of do-file
Where are the results?
Thank you!
Clare
I am trying to learn how to write loops to perform commands on multiple variables at once. In the following code, I try to write a loop that runs Wilcoxon's rank sum test on 14 continuous variables. The loop runs without error, but I can't figure out how to get the results to display. I don't know where they go/how to call them.
My code:
#local continuous gm_csf ifn_g il_2 il_7 il_5 il_10 il_13 il_15 il_17 tnf_a mcp_1
#foreach var of local continuous {
ranksum `var' if `var'!=0, by(sptb_new)
}
I have also tried to apply Matthew McKay's code from looking back in this forum on related topics:
** Program pe:
Print Execute **
#program define pe
# version 12.0
# if `"`0'"' != "" {
# display as text `"`0'"
' # `0' # display("")
# }
#end
One can just prepend pe to each line within the foreach loop.
#sysuse auto
#levelsof rep78, local(levs)
#foreach lev in `levs' {
# pe regress price weight if rep78==`lev'
#}
Applying this, I wrote the following code:
#program define pe version 12.0 if `"`0'"' != ""
{ display as text `"`0'"' `0' display("") } end
#foreach var of local continuous {
pe ranksum `var' if `var'!=0, by(sptb_new)
}
However, I am still not getting anything. The only output I see is:
. foreach var of local continuous {
2. pe ranksum `var' if `var'!=0, by(sptb_new)
3. }
.
end of do-file
Where are the results?
Thank you!
Clare
Comment