[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: including all interactions among a set of variables |

Date |
Fri, 14 Feb 2003 11:40:45 -0000 |

david huffer > > Is there a command used to include every 2-way interaction > among a set > of variables in a regression-type model? In SAS it is accomplished > quite easily but so far I haven’t run across a means other > than typing > all the possible interactions. A way to think about this is not in terms of a command to do it, but rather in terms of getting Stata to help in cutting down on the typing, especially as an explicit list of terms might _later_ need to be edited down as you simplify from that initial "shotgun" model. Some help might lie in looking at the -selectvars- program recently posted on SSC. Suppose you had categorical variables a b c d and wanted terms of the form i.a*i.b. -selectvars- emits distinct tuples and you can specify limits, so all distinct pairs are gained by . selectvars a b c d, min(2) max(2) There's no output. It is the saved result which its only saving grace: . ret li macros: r(varlist) : ""a b " "a c " "a d " "b c " "b d " "c d " " Then you can take each pair and emit an interaction term . foreach pair in `r(varlist)' { 2. tokenize `pair' 3. local iterms "`iterms' i.`1'*i.`2'" 4. } . di "`iterms'" i.a*i.b i.a*i.c i.a*i.d i.b*i.c i.b*i.d i.c*i.d Of course you could type that just as easily yourself: the example is just a toy example. An alternative which could be as or more practical -- especially if you have interactions of different flavours, given a mix of continuous and categorical variables -- is just to display the r(varlist) in the results window and then copy and paste into -doedit- or any favourite editor. Any editor worthy of the name will remove all the " in one command, for example. Nick n.j.cox@durham.ac.uk * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**st: including all interactions among a set of variables***From:*"david huffer" <dhuffer@crim.umd.edu>

- Prev by Date:
**st: including all interactions among a set of variables** - Next by Date:
**st: variable format** - Previous by thread:
**st: including all interactions among a set of variables** - Next by thread:
**st: -indexplot- updated for Stata 8 on SSC** - Index(es):

© Copyright 1996–2014 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |