## Load data
data("Engel95", package = "npiv")
## Sort on logexp (the regressor) for plotting purposes
Engel95 <- Engel95[order(Engel95$logexp),]
attach(Engel95)
logexp.eval <- seq(4.5,6.5,length=100)
## Estimate the Engel curve for food using logwages as an instrument
food_engel <- npiv(food, logexp, logwages, X.eval = logexp.eval)
## Plot the estimated function and uniform confidence bands
plot(food_engel, showdata = TRUE)
Run the code above in your browser using DataLab