Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

re: st: interactions


From   David Airey <[email protected]>
To   [email protected]
Subject   re: st: interactions
Date   Thu, 26 Jun 2003 09:07:04 -0500

Ernest,

I have not been able to use xi to create continuous*continuous interactions on the fly. I don't think xi does this from the description. It does cat*cont though. Desmat works with its own notation, but I've written with pen and paper the following program and would like some comments. The program is meant to create all two way interactions for a given set of continuous variables (e.g., a b c d):

* all two way interactions
program define atwi
syntax varlist (min 2 numeric)
local t = total number of variables <-- how do I get this?
tokenize `varlist'
for numlist j = 1(1)`t'-1 {
for numlist k = `j'+1(1)`t' {
generate ``j''x``k'' = ``j''*``k''
}
}
end

given a command like:

. atwi a b c d

it should kind of go through the loops to get:

j k generate
1 2 axb
3 axc
4 axd
2 3 bxc
4 bxd
3 4 cxd

and then I could type

atwi a b c d
regress Y a b c d a* b* c*

to get what I want, which is really a general linear test on adding all nway interaction at a certain level.

Any comments welcome before I try it out with a do file.

-Dave




What's the easiest way to generate all:

2 way interactions
3 way interactions
.
.
.
n way interactions

when you have many continuous variables to predict a continuous response?

xi seems to only be nice to me with categorical or dummy variables.


xi can do continuous variables as well, but only twoway. There are two options that I would think of:

1. use desmat (I have no experience with it myself but it seems a good solution and often used around here)
2. create all interaction-variables manually yourself with nested foreach/forvalues loops.

*
*   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/



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