[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Nick Winter <nwinter@virginia.edu> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: RE: Creating interaction terms of 30 continuous variables |

Date |
Thu, 10 Sep 2009 15:53:25 -0400 |

Leaving aside whether this is wise, I'd do something like this: unab vars : var1-var30 local nvar : word count `vars' forval i = 1/`nvar' { forval j = 1/`=`i'-1' { local x : word `i' of `vars' local y : word `j' of `vars' generate `x'X`y' = `x' * `y' } }

regress myvar c.(var1-var30)#c.(var1-var30) - Nick Winter

-----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Jean-Gael Collomb Sent: Wednesday, September 09, 2009 8:13 AM To: statalist@hsphsun2.harvard.edu Subject: st: Creating interaction terms of 30 continuous variables Hello,I am trying to explore all possible interaction terms in my datasetand I am not sure how to do this efficiently using stata. I have about30 continuous variables. It seems that xi is limited to noncontinuous variables and xi3 does not seem to work for 30 variables,unless I am doing something wrong. I came up with a solution using"foreach" to generate all the interactions terms and then try them ina regression model:foreach x of varlist var1-var30 { foreach y of varlist var1-var30 { generate `x'X`y'=`x'*`y' } }The first problem I have is that this created duplicates (i.e.var1Xvar2 is the same as var2Xvar1). Furthermore, I feel it is acumbersome way to do it, and I wonder if there is a more efficient wayto generate all possible pair interaction terms or better yet to havean exploratory regression models testing all these pairs out andselecting the best model. I saw someone someone doing somethingsimilar very quickly in NCSS and I was hoping I could do the same inSTATA.Thanks for your feedback. Jean-Gael "JG" E. Collomb PhD candidateSchool of Natural Resources and Environment / School of ForestResources and ConservationUniversity of Florida jgcollomb@gmail.com jg@ufl.edu +1 (352) 870 6696 * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

-- -------------------------------------------------------------- Nicholas Winter 434.924.6994 t Assistant Professor 434.924.3359 f Department of Politics nwinter@virginia.edu e University of Virginia faculty.virginia.edu/nwinter w PO Box 400787, 100 Cabell Hall Charlottesville, VA 22904 * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**st: Creating interaction terms of 30 continuous variables***From:*Jean-Gael Collomb <jg@ufl.edu>

**st: RE: Creating interaction terms of 30 continuous variables***From:*"Lachenbruch, Peter" <Peter.Lachenbruch@oregonstate.edu>

- Prev by Date:
**Re: st: Help with mathematical operation** - Next by Date:
**st: graph export - TIF -** - Previous by thread:
**Re: st: RE: Creating interaction terms of 30 continuous variables** - Next by thread:
**Re: st: Creating interaction terms of 30 continuous variables** - Index(es):

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