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

Re: st: Interesting (?) -ml- question


From   [email protected] (Jeff Pitblado, StataCorp LP)
To   [email protected]
Subject   Re: st: Interesting (?) -ml- question
Date   Tue, 07 Sep 2004 13:02:57 -0500

Mark Schaffer <[email protected]> asks about what appear to be multiple
offset variables with a single equation in -ml-:

> The likelihood function that I want to minimize has the form of, say, one
> dependent variable y and 3 independent variables w, x and z.  However, of
> the independent variables, only x has a coefficient associated with it.
> The other two variables, w and z, are needed for calculating the
> likelihood but don't have coefficients.
>
> My question - what's the best way of passing w and z to the likelihood
> function?
>
> I can think of 3 ways, but all seem pretty hacky:
>
> 1. Save "w z" as a string in a global macro called, say, MyMLvars.  The
> likelihood program mymlprog knows to look in $MyMLvars to find them.
>
> 2. In the ml model command, list w and z as additional endogenous
> variables, e.g.,
>
> ml model d0 mymlprog (y w z = x)
>
> Then mymlprog can find w and z as $ML_y2 and $ML_y3.
>
> 3. The hackiest of all - list w and z as indep vars, but constrain the
> coeffs to be zero:
>
> constraint 1 w=0
> constraint 2 z=0
> ml model d0 mymlprog (y = x w z)
>
> Is there a better way?  Or, if there isn't, which of these is to be
> preferred?

This will depend upon the form of the likelihood, but if the variables -w- and
-z- are part of the likelihood but are not necessarily part of -xb- for the
first equation, I would most definitely use constraints and extra equations.
Here is an overly simple example:

***** BEGIN:
clear
program drop _all
program myll
        version 8.2
        args lnf xb1 xb2 xb3
        quietly replace `lnf' = - ($ML_y1-`xb1')^2 - (`xb2')^2 - (`xb3')^2
end

global xx
sysuse auto
const 1 [eq2]trunk = 1
const 2 [eq3]displacement = 1
ml model lf myll                        ///
        (eq1: mpg = turn)               ///
        (eq2: trunk, noconstant)        ///
        (eq3: displ, noconstant)        ///
        , constr(1 2) max
ml display, first
***** END:

Here are the results from the -ml display-:

***** BEGIN:
initial:       log likelihood =     -36008
alternative:   log likelihood = -34482.631
rescale:       log likelihood = -23753.635
rescale eq:    log likelihood =      -4520
Iteration 0:   log likelihood =   -3516088
Iteration 1:   log likelihood = -3512747.6
Iteration 2:   log likelihood = -3512747.6

. ml display, first

                                                  Number of obs   =         74
                                                  Wald chi2(1)    =    2527.66
Log likelihood = -3512747.6                       Prob > chi2     =     0.0000

 ( 1)  [eq2]trunk = 1
 ( 2)  [eq3]displacement = 1
------------------------------------------------------------------------------
         mpg |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        turn |  -.9457877    .018812   -50.28   0.000    -.9826586   -.9089169
       _cons |    58.7965   .7503857    78.36   0.000     57.32577    60.26723
------------------------------------------------------------------------------
***** END:

--Jeff
[email protected]
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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