foreach var of varlist index2 prov_ass {
egen rank_`var' = rank(`var') if sodas3cl < .
bysort sodas3cl : egen ranksum_`var' = sum(rank_`var')
by sodas3cl : egen rankmean_`var' = mean(rank_`var')
tabstat rankmean_`var', by(sodas3cl) save
tabstatmat statdes3
mat2txt, matrix(statdes3) saving(statdes3) append
}
My problem is the following:
At the end of the loop, the first time, I should have -replace- and
the subsequent times -append-. I don't know how can I make Stata
understand this difference in a loop.