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

re: re: st: interactions


From   David Airey <[email protected]>
To   [email protected]
Subject   re: re: st: interactions
Date   Sun, 29 Jun 2003 14:16:34 -0500

I asked what the easiest way was to generate all two way interactions between a set of continuous variables rather than endlessly typing generate commands because xi does not help with continuous by continuous interaction generation on the fly. The context was related to a previous unanswered post about the general linear test and its relation to the Wald test and likelihood ratio tests.

Nick Cox kindly replied:


Program -selectvars- on SSC yields tuples of variable
names from a list. That's one of the parts of doing this
more generally.

One of the trickier parts is getting new varnames which not
only are new but also not too long. David's program doesn't
(really try to) tackle this. (Neither does -selectvars-.)

Anyway, he asked a question:

------------ David's code
* 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
----------------------

This is a step or two further on, without
solving the naming problem:

* all two way interactions
program atwi
        syntax varlist(min=2 numeric)
        local t : word count `varlist'
        tokenize `varlist'
        forval j = 1/`=`t'-1' {
                forval k = `=`j'+1'/`t' {
                        generate ``j''x``k'' = ``j''*``k''
                }
        }
end

The modified code for atwi works fine:

program define atwi
version 8
syntax varlist(min = 2 numeric)
local t : word count `varlist'
tokenize `varlist'
forvalues j = 1/`=`t'-1' {
forvalues k = `=`j'+1'/`t' {
generate ``j''x``k'' = ``j''*``k''
}
}
end

For example, in the context of a model looking at eye weight in mice, there is some evidence to suggest a model without interactions could be improved by adding interaction terms:

. * general liner test for all two way interactions versus no interactions
.
. * full model
. atwi body age brain parity litter sex
. quietly regress eye body* age* brain* parity* litter* sex if no_outliers == 1
. local ssef = e(rss)
. local dff = e(df_r)
.
. * reduced model
. quietly regress eye body age brain parity litter sex if no_outliers == 1
. local sser = e(rss)
. local dfr = e(df_r)
.
. * general linear test statistic
. local F = ((`sser' - `ssef')/(`dfr' - `dff')) / (`ssef'/`dff')
. local Fp = Ftail((`dfr'-`dff'),`dff', `F')

. display `F', `Fp'
2.0784304 .00891656

I guess my question is what the equivalent Wald test is for this problem. I seem to remember the likelihood ratio test was not available for regress.

-Dave



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