Dear community,
I'm looking for a way to create a designmatrix for a model with categorical variables using Stata's factor notation as input. Basically I want to do what the no longer available xi3 prefix command did: Create dummy variables for every category of each variable and each interaction.
There is the ado desmat which basically does exactly what I want only I can't use it because I'm working on code for my own ado and desmat has to be installed seperately before it can be used.
Here's an example of what I want to do that uses desmat:
The result looks like this:
I also know that there is the prefix xi but it doesn't allow for interactions of more than two variables.
Does anyone have a suggestion? How can I use xi to create results like that (without inputting the variable names by hand)?
Best regards,
Max Hörl
I'm looking for a way to create a designmatrix for a model with categorical variables using Stata's factor notation as input. Basically I want to do what the no longer available xi3 prefix command did: Create dummy variables for every category of each variable and each interaction.
There is the ado desmat which basically does exactly what I want only I can't use it because I'm working on code for my own ado and desmat has to be installed seperately before it can be used.
Here's an example of what I want to do that uses desmat:
Code:
clear input A B C f 1 1 1 23 1 1 2 34 1 2 1 31 1 2 2 49 1 3 1 71 1 3 2 19 2 1 1 78 2 1 2 93 2 2 1 16 2 2 2 48 2 3 1 12 2 3 2 93 end desmat A*B*C list, noobs clean mkmat _x_1-_x_11, mat(design) mat list design
Code:
_x_1 _x_2 _x_3 _x_4 _x_5 _x_6 _x_7 _x_8 _x_9 _x_10 _x_11 r1 0 0 0 0 0 0 0 0 0 0 0 r2 0 0 0 0 0 1 0 0 0 0 0 r3 0 1 0 0 0 0 0 0 0 0 0 r4 0 1 0 0 0 1 0 1 0 0 0 r5 0 0 1 0 0 0 0 0 0 0 0 r6 0 0 1 0 0 1 0 0 1 0 0 r7 1 0 0 0 0 0 0 0 0 0 0 r8 1 0 0 0 0 1 1 0 0 0 0 r9 1 1 0 1 0 0 0 0 0 0 0 r10 1 1 0 1 0 1 1 1 0 1 0 r11 1 0 1 0 1 0 0 0 0 0 0 r12 1 0 1 0 1 1 1 0 1 0 1
Does anyone have a suggestion? How can I use xi to create results like that (without inputting the variable names by hand)?
Best regards,
Max Hörl
Comment