Title
ivmw -- Moving window prefix command
Syntax
ivmw , window(#) par(string) [saving(filename [, replace]) rolling_options]: iv_cmd
options Description ---------------------------------------------------------------------------------------------- par(string) Parameter from the iv_cmd (ivreg2, ivmsmm, ivlsmm, ivtsps, ivtsri) to collect window(#) number of consecutive data points in each sample saving(filename [, replace]) Save the moving window output to a dataset. Specify replace to overwrite the dataset if it already exists. rolling_options rolling##options
Description
ivmw implements the moving window (a.k.a. sliding / rolling window) approach to the estimator specified after the prefix, as per Burgess et al., 2014. It is implemented as a call to rolling.
Options
Please see rolling##options
Examples
Simulate data with different outcome-exposure relationships; y# outcome, x exposure, g instrumental variable (genotype).
. use https://raw.github.com/remlapmot/ivonesamplemr/main/data/ivmwdata, clear
Plot outcome-exposure relationships
. twoway line y1 x, sort(x) . twoway line y2 y3 y4 x, sort(x) . twoway line y5 x, sort(x)
Example moving window fits.
. ivmw, window(3950) par(x): ivreg2 y1 (x = g) . ivmw, window(3950) par(x): ivreg2 y2 (x = g) . ivmw, window(3950) par(x): ivreg2 y3 (x = g) . ivmw, window(3950) par(x): ivreg2 y4 (x = g) . ivmw, window(3950) par(x): ivreg2 y5 (x = g)
Change window size (e.g. for outcome y2).
. ivmw, window(3750) par(x): ivreg2 y2 (x = g) . ivmw, window(3000) par(x): ivreg2 y2 (x = g) . ivmw, window(2000) par(x): ivreg2 y2 (x = g) . ivmw, window(1000) par(x): ivreg2 y2 (x = g)
Save the moving window dataset.
. ivmw, window(3950) par(x) saving(ivmw): ivreg2 y2 (x = g)
Use different iv commands.
. ivmw, window(3950) par(x): ivregress 2sls y (x = z1 z2 z3) . ivmw, window(3950) par(x): ivregress liml y (x = z1 z2 z3) . ivmw, window(3950) par(x): ivregress gmm y (x = z1 z2 z3) . ivmw, window(3950) par(x): ivlsmm y (x = z1 z2 z3) . ivmw, window(3950) par(x): ivmsmm y (x = z1 z2 z3) . ivmw, window(3950) par(b1): ivtsps y (x = z1 z2 z3) . ivmw, window(3950) par(b1): ivtsps y (x = z1 z2 z3), link(logadd) . ivmw, window(3950) par(b1): ivtsps y (x = z1 z2 z3), link(logmult) . ivmw, window(3950) par(b1): ivtsps y (x = z1 z2 z3), link(logit) . ivmw, window(3950) par(b1): ivtsri y (x = z1 z2 z3) . ivmw, window(3950) par(b1): ivtsri y (x = z1 z2 z3), link(logadd) . ivmw, window(3950) par(b1): ivtsri y (x = z1 z2 z3), link(logmult) . ivmw, window(3950) par(b1): ivtsri y (x = z1 z2 z3), link(logit)
Stored results
Please see rolling##results
References
Burgess S, Davies N, Thompson SG, EPIC-InterAct Consortium. Instrumental variable analysis with a nonlinear exposure-outcome relationship. Epidemiology, 2014, 25, 6, 877-885. DOI
StataCorp. Stata Base Reference Manual. Release 16. rolling - Rolling-window and recursive estimation. 2016. URL
Author
INCLUDE help ivonesamplemr-author