Learn R Programming

instruments (version 0.1.0)

iv.lm: Estimate linear regression models with an instrumental variable.

Description

This function allows you to estimate a two-stage least squares linear regression in one step.

Usage

iv.lm(model_formula, instrument_formula = NULL, data = NULL, ...)

Arguments

model_formula

The formula of the main regression problem.

instrument_formula

The formula for the first stage of the regression problem. Estimate an endogenous variable from one (or more) instruments. If blank, defaults to ordinary linear regression.

data

(optional) A data frame containing all variables for the regression model.

...

Additional arguments to pass to glm().

Examples

Run this code
# NOT RUN {
# Fake data
N <- 1000
z <- rnorm(N, 1, 1)
error <- rnorm(N, 1, 1)
x <- z + error + rnorm(N, 1, 1)
y <- x + error

# Fit OLS
fit_ols <- lm(y ~ x)

# Fit 2SLS
fit_2sls <- iv.lm(y ~ x, x ~ z)

summary(fit_ols)
summary(fit_2sls)
# }

Run the code above in your browser using DataLab