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

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


From   Mark Schaffer <[email protected]>
To   [email protected], "Jeff Pitblado, StataCorp LP" <[email protected]>
Subject   Re: st: Interesting (?) -ml- question
Date   Tue, 07 Sep 2004 19:58:05 +0100 (BST)

Jeff,

Thanks for the rapid feedback.  I hope this doesn't look like I'm biting a 
hand that fed me, but can I point out what looks like (to an ML neophyte, 
at any rate) a drawback of your recommended approach?

The issue arises if I want to write a general ML estimator of this form - 
say, something like LIML (which can be solved using eigenvales, but you get 
the idea).  The user specifies the dependent variable, the regressors, and 
the additional variables involved in the likelihood (in the LIML case, 
these are just the instruments).  There could be any number of regressors 
and instruments.

Won't code that handles an arbitrary number of instruments in the style 
you've described get messy?  There could be dozens or even hundreds of 
additional equations, and each gets its own constraint.  What would the
-args- line look like in the program that calculates the value of the 
likelihood?  Would the numerical calculations be affected if I work with 
really big matrices?

This is why I thought my option 1 below (put the names of the instruments 
in a global macro) would probably be the best choice, even though, from the 
point of view of programming aesthetics, it's not very elegant.

But I'm an ML neophyte, and it's not unlikely I'm missing something.

--Mark

Quoting "Jeff Pitblado, StataCorp LP" <[email protected]>:

> 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/
> 



Prof. Mark Schaffer
Director, CERT
Department of Economics
School of Management & Languages
Heriot-Watt University, Edinburgh EH14 4AS
tel +44-131-451-3494 / fax +44-131-451-3008
email: [email protected]
web: http://www.sml.hw.ac.uk/ecomes
________________________________________________________________

DISCLAIMER:

This e-mail and any files transmitted with it are confidential
and intended solely for the use of the individual or entity to
whom it is addressed.  If you are not the intended recipient
you are prohibited from using any of the information contained
in this e-mail.  In such a case, please destroy all copies in
your possession and notify the sender by reply e-mail.  Heriot
Watt University does not accept liability or responsibility
for changes made to this e-mail after it was sent, or for
viruses transmitted through this e-mail.  Opinions, comments,
conclusions and other information in this e-mail that do not
relate to the official business of Heriot Watt University are
not endorsed by it.
________________________________________________________________
*
*   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