help interactplot

Title

interactplot -- Generate plots for interaction terms of multiplicative regressions

Syntax

interactplot
[, options]

Main
fysize(relativesize) relative size of subplot

level(cilevel) specify confidence interval

name(name[, replace]) specify name for graph

reverse interchange xvar1 and xvar2

term(#) specify which interaction term is used

General Appearance
intersteps(#) enter number of steps for calculation of margins

scheme(scheme) set scheme for graph

yline(#) include horizontal line for y-axis

xlabnum(#) enter number of major ticks for x-axis in margins plot and subplot

ylabnum(#) enter number of major ticks for y-axis in margins plot

Graph of an interaction containing at least one factor variable

byplot show separate plots for factors/indicators

Graph of an interaction of two continuous variables

addscatter(string) add scatterplot to marginsplot; predicted values (predict) or observed values (observed)

cme estimate conditional marginal effect of moderator variable

subplot(string) specify type of subplot (hist or kdens)

Histogram appearance
bars(#) enter number of bars

Kernel density plot appearance
kernel(function) enter kernel function

kdarea recast kernel density plot line as area

fintensity(#) specify filling intensity of area

Description

interactplot is a tool for generating plots of predicted values or marginal effects for polynomials or interaction terms after a multiplicative regression.
The program detects multiplicative terms within the last estimated regression model, automatically calculates statistics calculated from predictions and automatically generates a combined graph.
That combined graph contains 1) a adjusted predictions or conditional marginal effect plot and 2) a subplot with the frequency/density of the predictor variable.
By default, the first variable in the multiplicative term is treated as the main variable and the second variable is treated as the moderator variable.
Since both variables are mathematically indistinguishable, this distinction is a theoretical one and has to be carried out by the researcher (Brambor et al. 2005; Lohmann 2015).

Since Stata can distinguish between factor variables and continuous variables, four possible combinations of effect variable and moderator variable can be realised. The default plots and their characteristics are listed below:

1. Factor # factor

Default: predicted values (main) with stacked bar plot (subplot)

Byplot: separate plots for each category of the moderator variable

2. Factor # continuous

Default: predicted values (main) over range of continuous variable with overlaid density plots (subplot)

Byplot: separate plots over range of continuous variable for each category of the factor variable

3. Continuous # factor

Default: predicted values (main) for categories of factor variable with stacked bar plot (subplot)

Byplot: separate plots for categories of factor variable

cme: conditional marginal effects plot of effect variable with derivatives of the response with respect to moderator variable

4. Continuous # continuous

Default: predicted values (main) of effect variable with density plot (subplot)

cme: conditional marginal effects plot of effect variable with derivatives of the response with respect to moderator variable

Options

Main

byplot show separate plots for factor/indicator variables. This option can exclusively be applied to interactions containing at least one factor variable.

fysize(relativesize) specifies the relative size of the subplot to the marginsplot in percent. The default value is 25.

level(cilevel) specifies the confidence interval. The default value is set in Stata and can be changed with set level.

name(name[, replace])} specify name for combined graph and optionally replace it.

reverse interchange the order of the variables within the specified interaction term. The second variable is treated as effect variable and the first variable is treated as moderator variable.

term(#) specify which interaction term should be used. By default, the first interaction term that occurs in the last estimated model is used.

General appearance

intersteps(#) enter number of steps for calculation of margins. Change this option if you want the lines and curves in the plots to be more rough or fine-grained. The default value is 30.

scheme(scheme) set scheme for graph. You can permanently change your graph style with set scheme.

yline(#)} include horizontal line for y-axis to easier identfiy the treshold at which an effect gets significant. In conditional marginal effect plots, this is usually the value of zero.

xlabnum(#) enter number of major ticks for abscissa (x-axis) in margins plot and subplot. Changing this parameter helps with loosing empty areas within in the plot area. The default value is 5.

ylabnum(#) enter number of major ticks for ordinate (y-axis) in margins plot. Changing this parameter helps with loosing empty areas within in the plot area. The default value is 5.

One/two factor variables

byplot show separate plots for factors/indicators. The corresponding number of subgraphs will be drawn, depending on much categories a variable has.

Two continuous variables

addscatter(string) add scatterplot to marginsplot. Additional plot can either display predicted values (predict) or observed values (observed) of the dependent variable.

cme estimate conditional marginal effect of moderator variable. This is identical to use the dydx()-option for the moderator variable in the margins command.

subplot(string) specify if the subplot is a histogram (hist) or a kdensity (kdens) plot.

bars(#) if a histogram is specified, enter the number of bars it should contain. The default value is 100.

kernel(function) enter kernel function for kernel density plot. For possible inputs, see kdensity. The default kernel function being used is epanechnikov.

kdarea recast kernel density plot line as an area plot.

fintensity(#) specify filling intensity of area plot in percent. The default value is 90.

Remarks

For interactplot to properly work, the package catplot has to be installed.
This can be done with ssc install catplot.
interactplot does not work properly if you use prefixes other than i. or c., i.e. the capitalized variants I. or C., and other coding-related prefixes.
The program can handle simple time-series operators (l., L., d., D., L1., L2., etc.), however, more complex constructs (e.g. DL(1/4).xvar) can lead to erroneous output.
In such cases it is therefore necessary to generate the lagged or differenced instances of the variables beforehand and run the regression model with the newly generated variables in a second step before executing interactplot.

Examples

1st example: Factor x factor (i.xvar1#i.xvar2)

Load dataset
. sysuse auto, clear

Estimate model
. regress mpg i.foreign i.rep78 price weight i.foreign#i.rep78

Overlaid plot
. interactplot

By-plot
. interactplot, byplot

2nd example: Factor x Continuous (i.xvar1#c.xvar2)

Load dataset
. sysuse auto, clear

Estimate model
. regress mpg i.foreign i.rep78 price weight i.foreign#c.price

Overlaid plot
. interactplot

By-plot
. interactplot, byplot

3rd example: Continuous x factor (c.xvar1#i.xvar2)

Load dataset
. sysuse auto, clear

Estimate model
. regress mpg i.foreign i.rep78 price weight c.price#i.foreign

Overlaid plot
. interactplot

Conditional marginal effect plot
. interactplot, cme

Conditional marginal effect plot and by-plot
. interactplot, cme byplot

4th example: Continuous x continuous (c.xvar1#c.var2)

Load dataset
. sysuse auto, clear

Estimate model
. regress price c.mpg c.weight c.mpg#c.weight

Plot conditional marginal effect
. interactplot, cme

Plot conditional marginal effect with interchanged moderator variable
. interactplot, cme reverse

Plot linear prediction with observed values
. interactplot, addscatter(observed)

Plot linear prediction with predicted values
. interactplot, addscatter(predict)

Additional examples

A1: Estimate model with multiple interaction terms

Load dataset
. sysuse auto, clear

Estimate model
. regress price c.weight i.foreign c.weight#c.weight i.foreign#c.weight

Plots for interaction terms
. interactplot, term(1) name(term1, replace)

. interactplot, term(2) name(term2, replace)

A2: Estimate model with 3rd order polynomial and interaction with factor variable

Load dataset
. sysuse auto, clear

Estimate model
. regress length c.turn i.foreign c.turn#c.turn c.turn#c.turn#c.turn i.foreign#c.turn

Plot cubic prediction for categories
. interactplot, term(3)

A3: Estimate model with variable prefixes and regression command options

Load dataset
. webuse grunfeld, clear

Estimate model
. xtpcse D1.invest c.D1.mvalue c.D1.kstock c.D1.mvalue#c.D1.kstock, corr(ar1)

Plot conditional marginal effects
. interactplot, cme

References

Brambor, T., Clark, W. R., & Golder, M. (2006). Understanding interaction models: Improving empirical analyses. Political analysis, 14(1), 63–82. doi:10.1093/pan/mpi014

Lohmann, H. (2015). Non-linear and non-additive effects in linear regression. In: Best, H., & Wolf, C. (eds.). The SAGE Handbook of Regression Analysis and Causal Inference. 1st edition, Sage. Part II, Chapter 6, pp. 111–132.

Author

Jan Helmdag, Department of Political Science, University of Greifswald, Germany