I want to use -margins- to get the derivative with respect to a variable X and the standard error of that derivative, where X appears in the model as both a linear term and a square root term. I know how to get the derivative, but I don't know how to get the standard error.
I would like to do this in the context of a -heckprobit- model, where the derivative of interest is for the probability in the outcome model with respect to X. To my understanding, the problem in using -margins- would be essentially the same if I had a plain -logit- model and a function other than sqrt(). On that count, I'll hope that people who don't use -heckprobit- will nevertheless take a look at this. I'll stick with -heckprobit- and sqrt() to be precise.
-margins- will give the derivative of the probability w.r.t. to each term involving X, which can then be combined into the overall derivative with respect to X according to conventional rules, and I have code below to show that, using the example data from -help heckprobit-, and using "years" as the "X" variable.
Can someone suggest how -margins- or other built-in means could be used to estimate the standard error of this overall derivative? Worst case, I could use -bootstrap-, but that seems like a hard way to go. As I understand it, the dydx option on -margins- only accepts varlists, not expressions.
Thanks, of course, for whatever thoughts you might have.
I would like to do this in the context of a -heckprobit- model, where the derivative of interest is for the probability in the outcome model with respect to X. To my understanding, the problem in using -margins- would be essentially the same if I had a plain -logit- model and a function other than sqrt(). On that count, I'll hope that people who don't use -heckprobit- will nevertheless take a look at this. I'll stick with -heckprobit- and sqrt() to be precise.
-margins- will give the derivative of the probability w.r.t. to each term involving X, which can then be combined into the overall derivative with respect to X according to conventional rules, and I have code below to show that, using the example data from -help heckprobit-, and using "years" as the "X" variable.
Can someone suggest how -margins- or other built-in means could be used to estimate the standard error of this overall derivative? Worst case, I could use -bootstrap-, but that seems like a hard way to go. As I understand it, the dydx option on -margins- only accepts varlists, not expressions.
Thanks, of course, for whatever thoughts you might have.
Code:
use http://www.stata-press.com/data/r15/school, clear gen years_sqrt = sqrt(years) heckprobit private years years_sqrt, select(vote=years years_sqrt loginc logptax) // // -margins- gives dydx w.r.t. linear and sqrt terms involving -year- local yrval = 9 // Suppose years = 9 is of interest local yrvalrt = sqrt(`yrval') margins, dydx(years) atmeans at(years == `yrval' years_sqrt = `yrvalrt') local d1 = el(r(b), 1, 1) // linear // margins, dydx(years_sqrt) atmeans at(years == `yrval' years_sqrt = `yrvalrt') local d2 = el(r(b), 1, 1) // sqrt term // // Combine derivative terms local dydx_years = `d1' + `d2'/(2 * `yrvalrt') di "dydx w.r.t. years = `dydx_years'"
Comment