Hello!
I have a set of 4 variables and a set of 4 conditions. I would like to run non-parametric tests (ranksum) over pairs of the two conditions for each variable. After some huffig and puffing I managed to create a loop to run pairwise tests for each variable individually:
local treatment "T1 T2 T3 T4"
local var "V1 V2 V3 V4"
forvalues i=1/4 {
forvalues j=`=`i'+1'/4 {
local this_treatment `: word `i' of `treatment''
local other_treatment `: word `j' of `treatment''
di "`this_treatment'" " `other_treatment'"
ranksum V1 if `this_treatment'==1 | `other_treatment'==1 ,by(`this_treatment')
}
}
Now, if I try to plug in the loop over the 4 vars, as in the following code, I get the answer that there are too many variables for the test. Any solution? Thanks in advance!
forvalues i=1/4 {
forvalues j=`=`i'+1'/4 {
foreach x in `var' {
local this_treatment `: word `i' of `treatment''
local other_treatment `: word `j' of `treatment''
di "`var'" " `this_treatment' " " `other_treatment' "
ranksum `var' if `this_treatment'==1 | `other_treatment'==1 ,by(`this_treatment')
}
}
}
Related Posts with Multiple loops in forvalues / foreach
calculating or identifying start/stop dates according to a rule with consecutive observationsHi, this is a snap shot of my data set. Code: Code: * Example generated by -dataex-. To install:…
Pooled panel Heckman MLE vs. pooled panel Heckman Two-stepDear Statalist, I am running a pooled panel Heckman two-step estimation to find determinants of ins…
Weighting data with AIPW and teffectsHello everyone, Actually, I try to understand how to use an IPW estimator. I have 11 treatments var…
Margins and regression outputDear Stata Users, I am analyzing the probability that cohabiting couples will marry or dissolve acc…
Taking Average by idHi Everyone, I have a dataset looking like this: Date id var1 var2 var3 var4... 2010 1 ... ... ... …
Subscribe to:
Post Comments (Atom)
0 Response to Multiple loops in forvalues / foreach
Post a Comment