magnifiedIV: Magnified Instrumental Variables

Description Usage Arguments Details Examples

View source: R/magnifiedIV.R

Description

This command runs the magnified instrumental variables estimator, of either the group-based or weighted variety.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
magnifiedIV(
  formula,
  data,
  ngroups = 4,
  grouping = "groupCF",
  groupformula,
  est = "group",
  p = 1/4,
  ivsubset = NULL,
  ivna.action = NULL,
  ivweights = NULL,
  ivcontrasts = NULL,
  silent = FALSE,
  ...
)

Arguments

formula

A formula of the form y ~ x1 + x2 | x1 + z2 + z3 where x1 is an exogenous variable included in the first and second stage, x2 is an endogenous variable being instrumented for, and z2 and z3 are instruments included only in the first stage.

data

A data.frame.

ngroups

Number of groups to split the data into.

grouping

A string variable indicating either the name of a variable in data to be used as a grouping (or a vector of names if there's more than one excluded instrument), or 'groupCF' or 'groupSearch' to indicate that causal forest or GroupSearch should be used to create groups, respectively.

groupformula

If using grouping = 'groupCF' or grouping = 'groupSearch', the formula to pass to those functions as their formula argument. If there are multiple instruments, instead pass a list of functions, to be used in the same order the excluded instruments are listed in formula.

est

A string variable equal to 'group', 'weight', or 'both' to indicate whether the grouped, weighted, or group-and-weighted version of Magnified IV should be used. Note that weighted versions can only be used with one endogenous variable so there is a defined "first stage".

p

If using est = 'weight' or est = 'both' with grouping = 'groupCF' or grouping = 'groupSearch', weights will be constructed by taking the group effects, generating a first-stage F statistic for each observation as though every observation in the sample had that first-stage effect, and raising that F statistic to the power p. Set p = 1/4 to get a similar weighting scheme as est = 'group' does, or p = -1/4 to recover the average treatment effect among compliers (under monotonicity and very good estimates of first-stage treatment effect heterogeneity).

ivsubset, ivna.action, ivweights, ivcontrasts

Additional options to be passed to AER::ivreg, corresponding to subset, subset, na.action, etc.. These are all preceded by 'iv' to avoid overlap with same-named options being passed in .... Note that ivweights will be ignored if est = 'weight' or est = 'both'. ivweights with est = 'groups' can be used to implement weighting schemes other than the power-of-an-F-statistic suggested in Huntington-Klein (2019).

silent

Set to TRUE to suppress any messages related to group-creation slow times.

...

Additional options to be passed to groupSearch or groupCF, as appropriate.

Details

This function will:

1. Use groupSearch(), groupCF or a supplied grouping variable, as requested, to find appropriate groupings over which the effects of the instruments vary.

2. If the weighted version of Magnified IV is requested, uses factorPull() to estimate effects within each group, and calculates sample weights for each observation, which are the first-stage F statistic that would be achieved if all observations in the sample had the same instrument effect as that observation, to the power p, then runs AER::ivreg() with those weights.

3. If the grouped version of Magnified IV is requested, runs AER::ivreg() with those groups included as controls and interacted with the instrument.

You can get more control over the estimation process (say, using a different command than AER::ivreg()) by making use of the constituent parts to get groups or weights and then setting the interaction or weights yourself.

One instance in which you may want to get more control over the estimation process is if you have multiple endogenous variables. With multiple endogenous variables and multiple instruments, there are lots of different ways to determine groupings. The magnifiedIV function will only allow one grouping per instrument, and if you want groupSearch or groupCF to determine that grouping for you, you must be able to specify a single formula like x1 ~ z1 | w1 + w2 to create that grouping. Can't do x1 + x2 ~ z1 + z2 | w1 + w2, that doesn't work. So with multiple excluded instruments that are each "for" multiple endogenous variables, you will want to do something by hand.

It is recommended that you read Huntington-Klein (2019) before using this command to understand which versions appear to work well, and what the Super-Local Average Treatment Effect (SLATE) is.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# This repeats the Stock-Watson textbook cigarette tax IV model
# from the AER::ivreg() help file.
# ... but it's magnified!

# Get data
data(CigarettesSW, package = 'AER')

CigarettesSW$rprice <- CigarettesSW$price/CigarettesSW$cpi
CigarettesSW$rincome <- CigarettesSW$income/CigarettesSW$population/CigarettesSW$cpi
CigarettesSW$tdiff <- (CigarettesSW$taxs - CigarettesSW$tax)/CigarettesSW$cpi

Cig95 <- CigarettesSW[CigarettesSW$year == "1995",]

# Run magnified IV, using causal forest to create effect quantiles
magIV <- magnifiedIV(log(packs) ~ log(rprice) + log(rincome) | log(rincome) + tdiff + I(tax/cpi),
                     data = Cig95,
                     ngroups = 5,
                     grouping = 'groupCF',
                     groupformula = list(log(rprice) ~ tdiff | I(tax/cpi) + population + taxs,
                                         log(rprice) ~ I(tax/cpi) | tdiff + population + taxs))
summary(magIV)
summary(magIV, vcov = sandwich, df = Inf, diagnostics = TRUE)

NickCH-K/MagnifiedIV documentation built on Jan. 21, 2020, 11:38 a.m.