Here is a program in Stata to calculate the marginal effects of one variable on another in a semi-parametric way. There are two .ado files and a Stata help file. It relies on the lpoly method, then numerically calculates the derivative of the function. This process is repeated to bootstrap the standard errors. The output of the function is a graph showing the 95% confidence interval around the marginal effects.
To see what the program does, consider the following example. We set
Therefore, the marginal effect of x is
We can then run semipmarginal y x z, ndiff) nbstrap ) graphname ) datname )
to do 100 bootstrap runs of the semi-parametric regression.
We can see that for this example, the program fairly accurately finds the marginal effect, except at the edges of the support of x, which is a typical weakness of non-parametric regression.
Note that the files are still a beta version and there could be bugs. In particular, when the x variable is sparse on the edges of the support, it can fail.