marg.ivreg {modmarg}R Documentation

Predicted Margins for 'ivreg' objects from the AER package

Description

Obtains predicted margins and standard errors of those predictions from a fitted ivreg model object.

Usage

## S3 method for class 'ivreg'
marg(mod, var_interest, data, weights = NULL, ...)

Arguments

mod

model object, currently only support those of class glm or ivreg

var_interest

name of the variable of interest, must correspond to a covariate in the model

data

data.frame that margins should run over, defaults changes based on class-specific method

weights

numeric, vector of weights used to generate predicted levels, defaults changes based on class-specific method. Must be equal to the number of rows in data.

...

additional parameters passed to ?marg.

Examples

# From ?AER::ivreg

# data
data("CigarettesSW", package = "AER")
CigarettesSW$rprice <- with(CigarettesSW, price/cpi)
CigarettesSW$rincome <- with(CigarettesSW, income/population/cpi)
CigarettesSW$tdiff <- with(CigarettesSW, (taxs - tax)/cpi)

# model
fm <- AER::ivreg(log(packs) ~ log(rprice) + log(rincome) |
                   log(rincome) + tdiff + I(tax/cpi),
                 data = CigarettesSW, subset = year == "1995")

# Get margins for different levels of price/cpi
rprice_levs <- round(quantile(CigarettesSW$rprice))

marg(fm, data = subset(CigarettesSW, year == "1995"),
     var_interest = 'rprice', at_var_interest = rprice_levs)


[Package modmarg version 0.9.6 Index]