# Average Structural Function Calculation

EDIT: I have solved this problem myself. The problem with the simulation below is that the omitted variable should not be included in the 'true model'. I have written a blog post with a more detailed analysis here.

I am trying to calculate the Average Structural Function (ASF) for a binary response regression model with an endogenous variable. The ASF is known as the policy relevant result obtained from these models because it shows how the conditional probability of the outcome (one or zero) changes in response to changes in any of the explanatory variables.

To estimate the regression model, I have used a two-step control function approach, wherein the first stage regression residuals ($\textbf{v}_{i}$) are included as a right-hand-side variable in the second stage probit regression à la Rivers and Vuong (1988).

Based on my reading of a paper by Blundell and Powell (2004) (and also these lecture notes) the ASF can be calculated as follows:

$P(y|\bar{\textbf{X}},v)=\widehat{ASF}=\frac{1}{N}\sum^{N}_{i} \Phi(\bar{\textbf{X}}\boldsymbol{\hat{\beta}}+\rho \hat{\textbf{v}_{i}})$

where the $\textbf{X}$ values are held at a constant level (say their mean), and we average over all of the first-stage residuals (multiplied by the second stage coefficient $\rho$). In effect, this formalization will allow one to calculate how the probability of the outcome varies as the one of the x-variables changes, while all of the other values are (typically) held at their means.

Or so you would think. However, I have attempted this calculation on a simple simulation with R and have not been able to replicate the ASF. My R code is below. Basically, this is a simple setup where we want to measure the effect of y1 on y2 (the binary outcome). There is one omitted variable (x1) that renders y1 endogenous the regression equation of interest.

A picture of my attempt is:

When $x_1$ is available, everything should be fine. Just estimate a standard probit of $y_2$ on $x_1$ and $y_1$. The ASF for this is just the normal CDF for changes in $y_1$. When $x_1$ is not observed, it becomes necessary to instrument $y_1$.

From the IV regression I have calculated the ASF as in the above, and plotted this with comparisons to the model where $x_1$ is observed (the blue line in the picture), and also where $x_1$ is not observed and $y_1$ is not instrumented (the green line).

The red line is my attempt to construct the ASF from the method described in the above. It is clear that this line is not matching the blue line as it should. I have gone wrong somewhere here but I am not sure where. Would somebody be able to help me with this please?

rm(list=ls())
x1 <- rnorm(10000)
x2 <- rnorm(10000)
y1 <- 1 + 0.5*x1 + x2 + rnorm(10000)
y2 <- ifelse(0.5 + 0.5*y1 - 1.5*x1 + rnorm(10000) > 0, 1, 0)

# true
data <- data.frame(cbind(seq(-4,6,0.2),mean(x1)))
names(data) <- c("y1","x1")
asf1 <- cbind(data$y1,pnorm(predict(r1,data))) plot(asf1,type="l",col="blue",xlab="y1",ylab="P(y2)") # no endog correction r2 <- glm(y2~y1,binomial(link="probit")) data <- data.frame(cbind(seq(-4,6,0.2))) names(data) <- c("y1") asf2 <- cbind(data$y1,pnorm(predict(r2,data)))
lines(asf2,type="l",col="green")

# control function approach
v1 <- (residuals(lm(y1~x2)))/sd(residuals(lm(y1~x2)))