Moving window estimator

Read in simulated data with different outcome-exposure relationships; y# outcome, x exposure, g instrumental variable (genotype).

use ../data/ivmwdata, clear

Plot outcome-exposure relationships

twoway line y1 x, sort(x)
qui gr export ./img/ivmw-plot-01.svg, replace

Plot of relationship between y1 and x.

twoway line y2 y3 y4 x, sort(x) legend(pos(6) rows(1))
qui gr export ./img/ivmw-plot-02.svg, replace

Plot of relationships between y2, y3, y4, and x.

twoway line y5 x, sort(x)
qui gr export ./img/ivmw-plot-03.svg, replace

Plot of relationship between y5 and x.

Example moving window fits.

ivmw, window(3950) par(x): ivreg2 y1 (x = g)
qui gr export ./img/ivmw-plot-04.svg, replace
Time variable: res_order, 1 to 4000
        Delta: 1 unit
(running ivreg2 on estimation sample)

Rolling replications (51): .........10.........20.........30.........40.........50. done
file /var/folders/kt/7xskrb1n4_x2jkd9lt0rhybh0000gp/T//S_56858.000001 saved as .dta format
(rolling: ivreg2)

Plot of estimated causal effect versus the median of the exposure in the moving window.

ivmw, window(3950) par(x): ivreg2 y2 (x = g)
qui gr export ./img/ivmw-plot-05.svg, replace
Time variable: res_order, 1 to 4000
        Delta: 1 unit
(running ivreg2 on estimation sample)

Rolling replications (51): .........10.........20.........30.........40.........50. done
file /var/folders/kt/7xskrb1n4_x2jkd9lt0rhybh0000gp/T//S_56866.000001 saved as .dta format
(rolling: ivreg2)

Plot of estimated causal effect versus the median of the exposure in the moving window.

ivmw, window(3950) par(x): ivreg2 y3 (x = g)
qui gr export ./img/ivmw-plot-06.svg, replace
Time variable: res_order, 1 to 4000
        Delta: 1 unit
(running ivreg2 on estimation sample)

Rolling replications (51): .........10.........20.........30.........40.........50. done
file /var/folders/kt/7xskrb1n4_x2jkd9lt0rhybh0000gp/T//S_56877.000001 saved as .dta format
(rolling: ivreg2)

Plot of estimated causal effect versus the median of the exposure in the moving window.

ivmw, window(3950) par(x): ivreg2 y4 (x = g)
qui gr export ./img/ivmw-plot-07.svg, replace
Time variable: res_order, 1 to 4000
        Delta: 1 unit
(running ivreg2 on estimation sample)

Rolling replications (51): .........10.........20.........30.........40.........50. done
file /var/folders/kt/7xskrb1n4_x2jkd9lt0rhybh0000gp/T//S_56882.000001 saved as .dta format
(rolling: ivreg2)

Plot of estimated causal effect versus the median of the exposure in the moving window.

ivmw, window(3950) par(x): ivreg2 y5 (x = g)
qui gr export ./img/ivmw-plot-08.svg, replace
Time variable: res_order, 1 to 4000
        Delta: 1 unit
(running ivreg2 on estimation sample)

Rolling replications (51): .........10.........20.........30.........40.........50. done
file /var/folders/kt/7xskrb1n4_x2jkd9lt0rhybh0000gp/T//S_56896.000001 saved as .dta format
(rolling: ivreg2)

Plot of estimated causal effect versus the median of the exposure in the moving window.

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)