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
3SLS with Instrument VariablesIs it possible to run a 3SLS specification using instrument variables in Stata? I have the followin…
Trying to do Rolling Standard Deviation give me this error. Can someone help ?Here is the command: tsset GVKEY_n Year rolling sd_NIBE=r(sd), window (4) clear : su NetIncome And…
Panel data mapHi, I want to map my panel data neatly. I've id & t. I've 5 agricultural crop variables. I've …
Can I cite the name of the do file?In the do file, I want to save the data using the name of the do flle, how to cite it using macros? …
Counting dummy for a group of multiple variablesHi all, I am trying to accomplish a simple count, but I still am not able to get what I want after …
Subscribe to:
Post Comments (Atom)
0 Response to Multiple loops in forvalues / foreach
Post a Comment