Ivmte
An R package for implementing the method in Mogstad, Santos, and Torgovitsky (2018, Econometrica).
Install / Use
/learn @jkcshea/IvmteREADME
ivmte: An R Package for Marginal Treatment Effect Methods
Joshua Shea and Alexander Torgovitsky
- Introduction
- Scope of this Vignette
- Installation and Requirements
- Usage Demonstration
- Help, Feature Requests and Bug Reports
- References
Introduction
Heckman and Vytlacil (2005) introduced the marginal treatment effect (MTE) to provide a choice-theoretic interpretation for the widely used instrumental variables model of Imbens and Angrist (1994). The MTE can be used to formally extrapolate from the compliers to estimate treatment effects for other subpopulations.
The ivmte package provides a flexible set of methods for conducting this extrapolation. The package uses the moment-based framework developed by Mogstad, Santos, and Torgovitsky (2018), which accommodates both point identification and partial identification (bounds), both parametric and nonparametric models, and allows the user to maintain additional shape constraints.
Scope of this Vignette
This vignette is intended as a guide to using ivmte for users already familiar with MTE methods. The key definitions and concepts from that literature are used without further explanation. We have written a paper (Shea and Torgovitsky 2021) that discusses both the MTE methodology and the usage of ivmte, which should be helpful for users unfamiliar with MTE methods. The survey article by Mogstad and Torgovitsky (2018) provides additional theoretical background on MTE methods, including the moment-based implementation used in this module.
Installation and Requirements
ivmte can be installed from CRAN via
install.packages("ivmte")
If you have the devtools package, you can install the latest version of the module directly from our GitHub repository via
devtools::install_github("jkcshea/ivmte")
Up to four additional packages are also required for ivmte:
- splines2 for specifying models with polynomial splines. This package is available on CRAN.
- A package for solving linear programs. There are four options here:
- Gurobi and the Gurobi R package gurobi, which can be obtained from Gurobi Optimization. This option requires a Gurobi software license, which Gurobi Optimization offers at no cost to academic researchers.
- MOSEK and the package Rmosek, which can be obtained from MOSEK ApS. This option requires a MOSEK software license, which MOSEK ApS offers at no cost to academic researchers.
- CPLEX and the package cplexAPI, which is available on CRAN. CPLEX can be obtained from IBM. This option requires a CPLEX software license, which IBM offers at no cost to academic researchers.
- The lpSolveAPI package, which is free and open-source, and available from CRAN. Note that lpSolveAPI is a wrapper for lp_solve, which is no longer actively developed.
- A package for solving quadratically constrained quadratic programs. gurobi and Rmosek are able to solve such programs. ivmte can still be used if the user only has access to cplexAPI or lpSolveAPI, but features of ivmte involving quadratically constrained quadratic programs will not be available.
- lsei for performing constrained least squares. This package is available on CRAN.
ivmte tries to automatically choose a solver from those available,
with preference being given to Gurobi, MOSEK, and CPLEX. We have
provided the option to use lpSolveAPI because it appears to be the
only interface for solving linear programs that can be installed solely
through install.packages. However, we strongly recommend using
Gurobi, MOSEK, or CPLEX, since these are actively developed, much more
stable, and typically an order of magnitude faster than lpSolveAPI.
A very clear installation guide for Gurobi can be found
here
Usage Demonstration
Data and Background
We will use a subsample of 209133 women from the data used in Angrist and Evans (1998). The data is included with ivmte and has the following structure.
library(ivmte)
knitr::kable(head(AE, n = 10))
| worked | hours | morekids | samesex | yob | black | hisp | other | |-------:|------:|---------:|--------:|----:|------:|-----:|------:| | 0 | 0 | 0 | 0 | 52 | 0 | 0 | 0 | | 0 | 0 | 0 | 0 | 45 | 1 | 0 | 0 | | 1 | 35 | 0 | 1 | 49 | 0 | 0 | 0 | | 0 | 0 | 0 | 0 | 50 | 0 | 0 | 0 | | 0 | 0 | 0 | 0 | 50 | 0 | 0 | 0 | | 0 | 0 | 1 | 1 | 51 | 0 | 0 | 0 | | 1 | 40 | 0 | 0 | 51 | 0 | 0 | 0 | | 1 | 40 | 0 | 1 | 46 | 0 | 0 | 0 | | 0 | 0 | 0 | 1 | 45 | 0 | 0 | 0 | | 1 | 30 | 1 | 0 | 44 | 0 | 0 | 0 |
We will use these variables as follows:
workedis a binary outcome variable that indicates whether the woman was working.hoursis a multivalued outcome variable that measures the number of hours the woman worked per week.morekidsis a binary treatment variable that indicates whether a woman had more than two children or exactly two children.- Note that Angrist and Evans (1998) removed women with fewer than two children when constructing their sample.
- Also note that the treatment variable must be binary.
samesexis an indicator for whether the woman’s first two children had the same sex (male-male or female-female). This is used as an instrument formorekids.yobis the woman’s year of birth (i.e. her age), which will be used as a conditioning variable.
A goal of Angrist and Evans (1998) was to estimate the causal effect of
morekids on either worked or hours. A linear regression of
worked on morekids yields:
lm(data = AE, worked ~ morekids)
#>
#> Call:
#> lm(formula = worked ~ morekids, data = AE)
#>
#> Coefficients:
#> (Intercept) morekids
#> 0.5822 -0.1423
The regression shows that women with three or more children are about 14–15% less likely to be working than women with exactly two children. Is this because children have a negative impact on a woman’s labor supply? Or is it because women with a weaker attachment to the labor market choose to have more children?
Angrist and Evans (1998) address this question by using samesex as an
instrument for morekids. We expect that samesex is randomly
assigned, so that among women with two or more children, those with weak
labor market attachment are just as likely as those with strong labor
market attachment to have to have two boys or two girls for their first
two children. A regression shows that women whose first two children had
the same sex are also more likely to go on to have a third child:
lm(data = AE, morekids ~ samesex)
#>
#> Call:
#> lm(formula = morekids ~ samesex, data = AE)
#>
#> Coefficients:
#> (Intercept) samesex
#> 0.30214 0.05887
Thus, samesex constitutes a potential instrumental variable for
morekids. We can run a simple instrumental variable regression using
the ivreg command from the AER package.
library("AER")
ivreg(data = AE, worked ~ morekids | samesex )
#>
#> Call:
#> ivreg(formula = worked ~ morekids | samesex, data = AE)
#>
#> Coefficients:
#> (Intercept) morekids
#> 0.56315 -0.08484
The coefficient on morekids is smaller in magnitude than it was in the
linear regression of worked on morekids. This suggests that the
linear regression overstates the negative impact that children have on a
woman’s labor supply. The likely explanation is that women who have more
children were less likely to work anyway.
An important caveat to this reasoning, first discussed by Imbens and
Angrist (1994), is that it applies only to the group of compliers who
would have had a third child if and only if their first two children
were same sex. (This interpretation requires the so-called
monotonicity condition.) The first stage regression of morekids on
samesex shows that this group comprises less than 6% of the entire
population. Thus, the complier subpopulation is a small and potentially
unrepresentative group of individuals.
Is the relationship between fertility and labor supply for the compliers the same as for other groups? The answer is important if we want to use an instrumental variable estimator to inform policy questions. The purpose of ivmte is to provide a formal framework for
