Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Derivatives at different parameter values

From   "FEIVESON, ALAN H. (AL) (JSC-SK) (NASA)" <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: Derivatives at different parameter values
Date   Wed, 24 Mar 2004 09:00:49 -0600

John - Let's see if I understand your question. You have some function
f(th_1, th_2,...th_n) and you want Stata to calculate df/dth_k at particular
values of th_1, th_2,..,th_n.

If this is what you want, there is a way you can do it by setting up a fake
regression and using _testnl. Here's an example:

Suppose your function is (th_2)/(th_3) - exp(-th_1), and you want to
evaluate the partial derivatives of f at (th_1, th_2, th_3) = (2,3,6).

Set up a fake dataset and regression as follows:

.set obs 3
.gen temp=_n
.tab temp,gen(dum)
.gen y=2*dum1+3*dum2+6*dum3     
.reg y dum1 dum2 dum3,noc

Then use -testnl- with the "g" option to save the matrix of partial

.testnl _b[dum2]/_b[dum3]-exp(-_b[dum1])=1,g(G)

The result of the test will be undefined (since the regression is a perfect
fit), but the matrix G will contain the partial derivatives you want.

In this example, df/dth_1 = exp(-th_1), df/dth_2 = 1/th_3 and df/dth_3 =
So the G matrix should contain exp(-2), 1/6 and -3/36.

If you want to implement this for ranges of parameter values, you would have
to incorporate this as part of a do-file.

Al Feiveson

-----Original Message-----
From: [email protected]
[mailto:[email protected]]On Behalf Of J Page
Sent: Tuesday, March 23, 2004 2:17 PM
To: [email protected]
Subject: st: Derivatives at different parameter values


How can one implement the numerical derivatives currently implemented in 
Stata's ml maximizer in a setting outside outside of ml?  I would like to 
calculate numerical derivatives at given parameter values. The dydx function

does not appear to do this.

Thanks much.


Get reliable access on MSN 9 Dial-up. 3 months for the price of 1! 
(Limited-time offer)

*   For searches and help try:
*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index