Hello.

I am currently trying to run balance tests in a dataset with respondents from 8 countries. The country variables are binary depending on whether the respondent is treated or not. I use the command below in a loop to run the balance tests one by one, and it works as it should. However, I was curious if it is possible to make a loop for the 8 countries at once and not for country_1, country_2 etc., separately. Do you know if that is possible?

Thank you in advance!

Code:
    loc covar co1 co2 co3 co4
    loc x country_1

    capture mat drop A
    loc i = 1
    foreach var of varlist `covar' {
    ttest `var', by(`x') unequal
        if `i' == 1 mat A =  `r(mu_1)',  `r(mu_2)',  `r(mu_2)'-`r(mu_1)',`r(p)' 
        else mat A =  A \ `r(mu_1)',  `r(mu_2)', `r(mu_2)'-`r(mu_1)', `r(p)'
        loc i = `i' + 1
        loc name  `name'  `var'
        }
    mat rownames A = `name'

    levelsof `x', local(VL)
    loc fff
    foreach num of loc VL {
    loc ddd : label (`x') `num'
    loc fff `fff' "`ddd'" 
    }
    mat colnames A = `fff' "Difference"  "p-value"
    mat list A
    estout matrix(A,fmt(3)) , mlabels(none)