Hi,
I currently have a foreach loop, and want to run tabulations using each variable in the variable list (most of them are categorical). However, if the variable in the variable list if continuous, I want it to run ranksum instead. Is there an expression I can use to signify whether a variable in a variable list is continuous or not, without creating a separate variable list?
scalar k=5
foreach v of varlist char1 char2 char3 {
if "`v'" != "char2" {
tabulate exposure `v' if cond1!=., chi2 exact row col
putexcel J`=k' = `r(p_exact)'
}
scalar k = k + 1
}
Currently, I have replaced all continuous variables in the variable list with the placeholder variable "char2" and ran the following codes below, for each, after the foreach loop. Incorporating ranksum into the foreach loop would be more efficient than replacing each box individually.
Priscilla
I currently have a foreach loop, and want to run tabulations using each variable in the variable list (most of them are categorical). However, if the variable in the variable list if continuous, I want it to run ranksum instead. Is there an expression I can use to signify whether a variable in a variable list is continuous or not, without creating a separate variable list?
scalar k=5
foreach v of varlist char1 char2 char3 {
if "`v'" != "char2" {
tabulate exposure `v' if cond1!=., chi2 exact row col
putexcel J`=k' = `r(p_exact)'
}
scalar k = k + 1
}
Currently, I have replaced all continuous variables in the variable list with the placeholder variable "char2" and ran the following codes below, for each, after the foreach loop. Incorporating ranksum into the foreach loop would be more efficient than replacing each box individually.
Thank you!
ranksum continuousvar if cond1!=. & exposure !=., by (exposure)
scalar pvalue = 2*normprob(-abs(`r(z)'))
display pvalue // to check that it matches
putexcel F6 = pvalue, nformat(number_d3)
Priscilla
Comment