Hi Everyone,
I'm running a lot of ttests and I keep getting this error whenever there aren't enough observations to test. I'm wondering if there's something I can add to my code to tell stata to simply skip that test if there aren't enough observations. This is my code:
foreach region in list {
bysort ethnicity: ttest meanscore, by(survey)
bysort personofcolor: ttest meanscore, by(survey)
bysort gender: ttest meanscore, by(survey)
bysort cgp: ttest meanscore, by(survey)
bysort economicbackground: ttest meanscore, by(survey)
}
I have 52 regions and several options for each of the demographics I'm testing, but the demographic breakdowns aren't the same for every region. So for some regions, there are observations for both survey years, but for other regions, there aren't so my code stops and I get the "1 group found, 2 required r(420); Error" error.
Is there an easy fix for this? I've thought about using the egen command to create a new variable that has a value of 1 for each combination of region ethnicity in the current survey that also appears in the previous survey and then use an if in my test command that is newvariable==1, but that would mean a lot of extra coding...
Thanks in advance for your help!
Eva
I'm running a lot of ttests and I keep getting this error whenever there aren't enough observations to test. I'm wondering if there's something I can add to my code to tell stata to simply skip that test if there aren't enough observations. This is my code:
foreach region in list {
bysort ethnicity: ttest meanscore, by(survey)
bysort personofcolor: ttest meanscore, by(survey)
bysort gender: ttest meanscore, by(survey)
bysort cgp: ttest meanscore, by(survey)
bysort economicbackground: ttest meanscore, by(survey)
}
I have 52 regions and several options for each of the demographics I'm testing, but the demographic breakdowns aren't the same for every region. So for some regions, there are observations for both survey years, but for other regions, there aren't so my code stops and I get the "1 group found, 2 required r(420); Error" error.
Is there an easy fix for this? I've thought about using the egen command to create a new variable that has a value of 1 for each combination of region ethnicity in the current survey that also appears in the previous survey and then use an if in my test command that is newvariable==1, but that would mean a lot of extra coding...
Thanks in advance for your help!
Eva
Comment