*! version 1.1 February 25, 2017 @ 18:24:26
help interflex

Title

interflex --
Multiplicative interaction models diagnostics and
visualization

Syntax

interflex
outcome
treat
moderator
[covar]
[if] [in]
[weight]
[, options]

Main
fe(varlist) specify fixed effects variables

type(string) specify the estimation strategy, including binning (default), linear, and kernal

vce(vcetype) specify the variance–covariance estimator; vcetype can be homoscedastic (default), robust, cluster, bootstrap, or off

cluster(varname) specify the clustering variable for clustered standard errors in linear and binning estimtions and for the block bootstrap procedure in the kernel estimation

nbins(integer) set the number of bins; default is 3; type(binning) is required; ignored if cutoffs is supplied

cutoffs(numlist) set the cutoff points (in ascending order) to determine bins of the moderator in binning estimations

saving(string) specify a filename with which the graph will be stored; if no suffix is provided, the graph will be saved as a ".pdf"

Advanced
reps(integer) specify the number of bootstrap runs; the default is 50

seed(integer) set the random seed for cross validation or bootstrapping

bw(real) set the bandwidth for kernel estimations

grid(integer) set the number of candidates in a grid search to determine the optimal bandwidth; default is 20; type(kernel) is required; ignored if bw is supplied

neval(integer) set the number of evaluation points in the kernel estimation; default is 50; type(kernel) is required

title(string) set the title of the graph

xrange(numlist) set the range of values to be shown on the x-axis

yrange(numlist) set the range of values to be shown on the y-axis

ylabel(string) set the label for the outcome variable

dlabel(string) set the label for the treatment variable

xlabel(string) set the label for the moderating variable

xdistr(string) specify how the distribution of the moderator should be visualized; either histogram (default) or density

Description

interflex performs diagnostics and visualizations of
multiplicative interaction models. Besides conventional linear
interaction models, it provides two additional estimation
strategies--linear regression based on pre-specified bins and locally
linear regressions based on Gaussian kernel reweighting--to estimate the
conditional marginal effect of a treatment variable on an outcome
variable across different values of a moderating variable. These
approaches relax the linear interaction effect assumption and
safeguard against excessive extrapolation.

Options

Main

fe(varlist) specifies fixed effects variables in linear
fixed effect models. We use a new STATA command that implements a fast
routine of high dimensional linear fixed effects models reghdfe developed by Sergio Correia. Install via ssc install reghdfe.

type(string) specifies the type of estimation
strategy. The default is type(binning), which plots the linear
marginal effects superimposed by the binning estimates (at low,
medium, and high levels of the moderator if there are 3 bins, for
instance). type(linear) plots the conventional linear margianl
effects (Brambor, Clark, and Golder 2006). type(kernel) plots the
marginal effects based on a kernel smoothing estimator. It produces
the marginal effect estimates of the treatment on the outcome at a
series of values of the moderator using a kernel-weighted locally
linear regressions.

vce(string) specifies the variance–covariance
estimator. vcetype can be homoscedastic (default), robust, cluster, bootstrap, or off. vce(off) only applies to the kernel estimator. When supplied, uncertainty estimates will not be produced and hence confidence
intervals will not appear in the graph.

cluster(varname) specifies the clustering variable for
clustered standard errors when vce(cluster) is chosen and for the blocking variable in bootstrap procedure when vce(bootstrap) is chosen. The current algorithm only allows one
way clustering.

nbins(integer) sets the number of bins for
type(binning) estimaion; the default is 3. When
cutoffs(numlist) are not specified, the binning estimates are positioned
at the median value of the moderator within each bin. nbins will be automatically
subtracted by 1 if more than one multiples of the percentile have
the same value (for example, if the moderator has over 70% zeros,
both the 33 and 66 percentiles are zero). Ignored
when cutoffs is supplied.

cutoffs(numlist) sets the cutoff points for moderator bins in type(binning)
estimation. When supplied, nbins will be ignored. The smallest number of the first interval and the
largest number of the last interval do not need to be specified. Numbers smaller than the minimum or larger than the
maximum of X will be ignored. The number of bins equals to the length of numlist plus 1. Ignored if the treatment is dichotomous.

saving(filename) specifies a filename with which the graph will be stored; if no suffix is provided, the graph will be saved as a ".pdf".

Advanced

reps(integer) specifies the number of bootstrap runs; the default is 50;

seed(integer) sets the random seed for cross-validation and/or boostrapping in kernel estimations, the default is seed(12345678).

bw(real) sets the bandwidth for the kernel estimation; If bw is not specified, the optimal bandwidth
will be selected via a least-squares cross-validation procedure.

grid(integer) sets the number of candidates in a grid
search to determine the optimal bandwidth using cross-validation. Ignored when bw is supplied. The default is 20.

neval(integer) sets the number of evaluation points in kernel estimations.

title(string) sets the title of the graph.

xrange(numlist) sets the range of values to be shown on the x-axis. Only the first two numbers (in ascending order) will be considered.

yrange(numlist) sets the range of values to be shown on the y-axis. Only the first two numbers (in ascending order) will be considered.

ylabel(string) sets the label for the outcome variable.

dlabel(string) sets the label for the treatment variable.

xlabel(string) sets the label for the moderating variable.

xdistr(string) specifies the way in which the distribution of the moderator is visualized; either histogram (default) or density.

Examples

We provide four simulated datasets to illustrate how interflex works.

Dichotomous or countinuous treatment with linear marginal effects

Load sample dataset 1 (dichotomous treatment, linear)

. use interflex_s1.dta, clear

Plot the raw data

. twoway (sc Y X) (lowess Y X), by(D)

Estimate a linear interaction model

. interflex Y D X Z1, type(linear)

Linear interaction model with robust standard errors

. interflex Y D X Z1, type(linear) vce(robust)

Linear interaction model with bootstrap standard errors

. interflex Y D X Z1, type(linear) vce(boot)

Superimpose three binning estimates (by default) with robust standard errors

. interflex Y D X Z1, vce(r)

When the linear interaction model is correct, the binning estimates are consistent with the linear marginal effects.

Estimate potentially nonlinear marginel effects based on the kernel estimator with specified bandwidth

. interflex Y D X Z1, type(kernel) bw(5.5)

Optimal bandwidth selected via cross-validation (THIS's GONNA TAKE A WHILE)

. interflex Y D X Z1, type(kernel)

Results are similar to what we got from the lienar
interaction model, as they should be. The optimal bandwithd is
relatively large.

Similar for the case of continuous treatment; first, plot the raw data

. use interflex_s2.dta, clear

. egen Xbin = cut(X), group(3)

. twoway (sc Y D) (lowess Y D), by(Xbin)

Kernel estimates

. interflex Y D X Z1, type(kernel) bw(5.0)

Nonlinear marginal effects

Plot the raw data

. use interflex_s3.dta, clear

. twoway (sc Y X) (lowess Y X), by(D)

Apply the binning estimator

. interflex Y D X Z1, vce(r)

When the linear interaction model is incorrect, the binning estimates diagree with the marginal effect estimates from the conventional linear model.

Apply the kernel estimator (bandwidth selected via cross-validation)

. interflex Y D X Z1, type(kernel) bw(0.345)

Marginal effect estimates using the kernel estimator are consistent with the true DGP.

Nonlinear marginal effects with additive two-way fixed effects

Load sample4

. use interflex_s4.dta, clear

The two fixed effect indicators are "group" and "year".

Plot the raw data

. twoway (sc Y X) (lowess Y X), by(D)

With fixed effects affecting the outcome, we cannot observe a clear pattern of marginal effects in the raw plot as before.

. interflex Y D X Z1, cl(group)

The binning estimates have wide confidence intervals if fixed effects are not controlled for.

Controlling for fixed effects with the binning estimator

. interflex Y D X Z1, fe(group year) cl(group)

Controlling for fixed effects with the kernel estimator (bandwith is selected via cross-validation)

. interflex Y D X Z1, type(kernel) fe(group year) cl(group) bw(0.60)

Saved results

interflex returns the estimated marginal effect of treatment variable on dependent variable (as well as its standard error and the 95% confidence interval) at each evaluation point of moderating variable.

Matrices

r(margeff) estimated marginal effects

r(estBin) binning estimates

r(bandwidth) specified or cross-validated bandwith if type(kernel)

r(CVout) mean squared prediction errors in cross-validation

Reference

Brambor, Thomas, William Roberts
Clark and Matt Golder (2006). "Understanding Interaction Models:
Improving Empirical Analyses." Political Analysis 14:63–82.

Hainmueller, Jens, Mummolo, Jonathan, and Xu, Yiqing
(2016). "How Much Should We Trust Estimates from Multiplicative
Interaction Models? Simple Tools to Improve Empirical Practice."
Available at SSRN: https://papers.ssrn.com/abstract_id=2739221.

Authors

Yiqing Xu (Maintainer), yiqingxu@ucsd.edu
Univeristy of California, San Diego

Jens Hainmueller, jhain@stanford.edu
Stanford University

Jonathan Mummolo, jmummolo@stanford.edu
Stanford University

Licheng Liu, liulch.16@sem.tsinghua.edu.cn
Tsinghua University