UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata Code Fragment: 
Getting Interactions of Dummy Variables

Say you have 2 categorical variables aids and drug and you want to run a regression, and get an effect for aids and for drug and for the interaction.  How do you do this?

First, you would want to create dummy variables for drug and aids, as well as for the interaction of the two. The easiest way to do that would be with the xi command, for example

. xi i.drug*i.aids

and then this creates the dummy variables

_Idrug_2 & _Idrug_3 (the drug dummies)

_Iaids_2 & _Iaids_3 (the aids dummies)

_IdruXaid_2_2 & _IdruXaid_2_3 & _IdruXaid_3_2 & _IdruXaid_3_3 (the interaction dummies)

You would then include all of these dummies in your tests. To test for the interaction, you would follow the "xtreg" with the test command, e.g.

test _IdruXaid_2_2 _IdruXaid_2_3 _IdruXaid_3_2 _IdruXaid_3_3

and this would test if the interaction is significant.  For a related FAQ, you can see this link.






How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California