Giorgio Presidente below you can find a suggestion that uses the locals storing the number of state, free, control, and interaction variables - in prodest I save such locals here and there, you may easily find out their names and use them upfront without re-generating them. As you'll see, I am not an expert in Mata, so probably some Mata nerd might help you further in cleaning the code and making it more efficient.
Best,
Gabriele
loc varnum: word count `state' `free'
loc contrnum: word count `control'
loc interactnum: word count `interactionvars'
mata V = J(1, `varnum', 1) , J(1, `contrnum', 0), J(1, `interactnum', 1)
mata Cc = vec(V)'
Best,
Gabriele
loc varnum: word count `state' `free'
loc contrnum: word count `control'
loc interactnum: word count `interactionvars'
mata V = J(1, `varnum', 1) , J(1, `contrnum', 0), J(1, `interactnum', 1)
mata Cc = vec(V)'
Comment