Dear Statalist Community,
I am having difficulty with the commands for a foreach loop to run multiple t-tests. I keep getting an error that variable var is not found.
Here is my code:
global myvars1 balance_ind fullness_ind tif_ind gan_ind earthy_ind sweet_ind ///
sour_ind bitter_ind mouthfeel_ind others_ind aftertaste_ind balance_grp ///
fullness_grp tif_grp gan_grp earthy_grp sweet_grp sour_grp bitter_grp ///
mouthfeel_grp others_grp aftertaste_grp aftertaste5_grp aftertaste10_grp ///
aftertaste15_grp aftertaste20_grp gan5_grp gan10_grp gan15_grp gan20_grp ///
aftertaste3_grp aftertaste8_grp aftertaste13_grp aftertaste18_grp aftertaste23_grp ///
gan3_grp gan8_grp gan13_grp gan18_grp gan23_grp mf3_grp mf8_grp mf13_grp mf18_grp mf23_grp
display "$myvars1"
foreach var in $myvars1 {
ttest var, by(spring)
matrix means=nullmat(means), r(table)
}
I have also run the same command with "" around $myvars1 ("$myvars1"), which resulted in the same error. [variable var not found
r(111)] I was wondering if anyone had any advice? Thank you!
Best,
Hannah
I am having difficulty with the commands for a foreach loop to run multiple t-tests. I keep getting an error that variable var is not found.
Here is my code:
global myvars1 balance_ind fullness_ind tif_ind gan_ind earthy_ind sweet_ind ///
sour_ind bitter_ind mouthfeel_ind others_ind aftertaste_ind balance_grp ///
fullness_grp tif_grp gan_grp earthy_grp sweet_grp sour_grp bitter_grp ///
mouthfeel_grp others_grp aftertaste_grp aftertaste5_grp aftertaste10_grp ///
aftertaste15_grp aftertaste20_grp gan5_grp gan10_grp gan15_grp gan20_grp ///
aftertaste3_grp aftertaste8_grp aftertaste13_grp aftertaste18_grp aftertaste23_grp ///
gan3_grp gan8_grp gan13_grp gan18_grp gan23_grp mf3_grp mf8_grp mf13_grp mf18_grp mf23_grp
display "$myvars1"
foreach var in $myvars1 {
ttest var, by(spring)
matrix means=nullmat(means), r(table)
}
I have also run the same command with "" around $myvars1 ("$myvars1"), which resulted in the same error. [variable var not found
r(111)] I was wondering if anyone had any advice? Thank you!
Best,
Hannah
Comment