Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# RE: st: gradient and the inverse of the information matrix

 From Jun Xu To Listserv STATA Subject RE: st: gradient and the inverse of the information matrix Date Fri, 3 May 2013 15:36:05 -0500

```Maarten,

I think you are right. I did look at the gradients from the two models below and they are different. But somehow I still don't quite get why the gradient from

logit foreign z_price z_weight, constraint(1)

would be different from

logit foreign z_price z_weight, from(`b0') iter(0)

So maybe although this second model starts with  z_price= - z_weight= 2.358206 , it is only an initial value, not an explicit constraint imposed that would affect the calculation of gradient for the full model?

Again, thanks a lot for your help.

Jun

> Date: Thu, 2 May 2013 09:44:59 +0200
> Subject: Re: st: gradient and the inverse of the information matrix
> From: maartenlbuis@gmail.com
> To: statalist@hsphsun2.harvard.edu
>
> On Wed, May 1, 2013 at 11:40 PM, Jun Xu wrote:
> > I am working on a single-equation categorical dependent variable model. I estimated the model with constraints imposed. Then if I understand the score test correctly, it would be a simple matrix operation of
> >
> >
> >
> > But the results do not match those from SAS, at least not to the point of having rounding errors. Either e(gradient) does not mean what it's named or the inverse of information matrix != e(V), I couldn't think of other possibilities.
>
> The gradient returned in e(gradient) is what it is supposed to be, but
> not what you want it to be. What e(gradient) gives you is the gradient
> of the constrained model at the estimated parameters of the
> constrained model. What you want is the gradient of the
> _unconstrained_ model at the parameter values of the constrained
> model. Many (but not all) Stata commands allow you to get the gradient
> you are after by first estimating the constrained model, store the
> parameters, use those parameters at starting values for an
> unconstrained model using the -from()- option, and specify that you
> want to get restults after 0 iterations (i.e. just the starting
> values) using the -iter()- option. Here is an example using -logit-.
>
> *------------------ begin example ------------------
> // prepare some data
> sysuse auto, clear
> sum price
> gen z_price = ( price - r(mean) ) / r(sd)
> sum weight
> gen z_weight = ( weight - r(mean) ) / r(sd)
>
> // a logit with a silly constraint
> constraint 1 z_price = -z_weight
> logit foreign z_price z_weight, constraint(1)
> est store c
>
> // store the coefficients
> tempname b0
> matrix `b0' = e(b)
>
> // repeat that model but get the gradient for the
> // unconstrained model at the parameter values of
> // the constrained model
> logit foreign z_price z_weight, from(`b0') iter(0)
>
> // compute the score statistic
> matlist chi
>
> // compare score statistic with Wald and likelihood ratio
> // not surprisingly 74 observations is not quite asymptotia
> logit foreign z_price z_weight
> lrtest . c
>
> test z_price = -z_weight
> *------------------- end example -------------------
> (For more on examples I sent to the Statalist see:
> http://www.maartenbuis.nl/example_faq )
>
> Hope this helps,
> Maarten
>
> ---------------------------------
> Maarten L. Buis
> WZB
> Reichpietschufer 50
> 10785 Berlin
> Germany
>
> http://www.maartenbuis.nl
> ---------------------------------
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/
```