Dear list members,
I need help on a probably rather basic issue, being naive in Mata and currently not having alas much time to put myself to practice and read the manual.
I need to run an estimation command for all the permutations of the levels of a categorical variable. Let's assume the categorical variable has levels 1 to 5. I understood the best way to obtain permutations is to use Mata, and more precisely cvpermute(). If there is an equally or more effective and not too code-consuming way with Stata, please enlighten me. I understood I can loop over the permutations of a column vector containing the levels of the categorical variable in the following way:
Now, if I were to code in Stata, my approach within each loop would be to extract as scalars the vector elements to then be able to write something like
so that for every permutation, the first to fifth position are occupied by (sometimes) changing row values, and the resulting recoded variable will differ. However, I understand the latter code will not work within a Mata loop, although I guess there might be ways to make it work that I am unaware of. Immediately after recode, I will then need to call an estimation command, again within the loop. If there is no way to use recode or this other estimation command within the Mata loop, then I am at a loss about how to proceed, and I would need even more general guidance.
Apologies for the lack of data, I guess/hope the question is fairly complete without it.
I need help on a probably rather basic issue, being naive in Mata and currently not having alas much time to put myself to practice and read the manual.
I need to run an estimation command for all the permutations of the levels of a categorical variable. Let's assume the categorical variable has levels 1 to 5. I understood the best way to obtain permutations is to use Mata, and more precisely cvpermute(). If there is an equally or more effective and not too code-consuming way with Stata, please enlighten me. I understood I can loop over the permutations of a column vector containing the levels of the categorical variable in the following way:
Code:
mata: levels = (1\2\3\4\5) info = cvpermutesetup(levels, unique=1) while ((levels=cvpermute(info)) != J(0,1,.)) { for (i=1; i<=6; i++) { // more code here } } end
Code:
recode country (1=`=el`1'') (2=`=el`2'') (3=`=el`3'') (4=`=el`4'') (5=`=el`5'')
Apologies for the lack of data, I guess/hope the question is fairly complete without it.
Comment