*! version 1.0 Chao Wang 27/09/2018
help geninteract

Title

geninteract -- Generate N-way interaction terms

Syntax

geninteract varlist [, n(integer) separate(string) max(integer)]

Description

geninteract generates N-way interaction terms for variables in varlist.

While this program works for any numerical varlist, it is particularly
useful for polynomials. It has recently been shown that neural networks
(NNs) are essentially polynomial regression models and the latter has advantages
such as fewer turning parameters and convergence issues. While polynomial terms for an
individual variable can be generated fairly easily using fp generate in Stata,
it is less straightforward to generate interaction terms, especially for
large number of predictor variables. This program aims to facilitate this by quickly
generating interactions with desired level of complexity.

Options

n(integer) specifies N-way interactions; the default is 2.
separate(string) specifies separator to serve as punctuation between
original variable names; the default is "_".

max(integer) may only be used for polynomial terms generated by
fp generate, i.e. term_# (term_1, term_2...). It specifies
the maximum of total # in an interaction. This option is useful to restrict the
number of output interaction terms by controlling the degree of the terms (see
the example below. For irregular set of powers one however must be careful to
choose an appropriate value for this option). Specifying this option also removes
those that are not actual interactions in the case of multiple polynomial
variables in varlist (e.g. term_1*term_2). The value of max
must be positive otherwise this option has no effect.

Examples

As a simple illustration, the following generates polynomial terms of degree
three from two predictor variables as described by Cheng et al. (2018) (page 24).

. sysuse auto, clear

. fp generate mpg^(1/3), scale

. fp generate headroom^(1/3), scale

. geninteract mpg_* headroom_*, max(3)

Reference

Cheng, X., Khomtchouk, B., Matloff, N., & Mohanty, P. (2018). Polynomial Regression As an Alternative to Neural Nets. Retrieved from https://arxiv.org/abs/1806.06850v2.

Also see their presentation: http://heather.cs.ucdavis.edu/polygrail.pdf

Author

Chao Wang, BEng MSc DIC PhD, Senior Lecturer in Health & Social Care Statistic, Faculty of Health, Social Care and Education,
Kingston University and St George's, University of London, excelwang@gmail.com.