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

Re: st: -ml- program: v. 4 to v. 8.1 conversion


From   [email protected] (Jeff Pitblado, Stata Corp.)
To   [email protected]
Subject   Re: st: -ml- program: v. 4 to v. 8.1 conversion
Date   Mon, 06 Oct 2003 12:08:51 -0500

Stephen P. Jenkins <[email protected]> asks about using -ml- to optimize
functions:

> I'm thinking about updating my -smfit- and -dagumfit- programs written 
> in Stata version 4 (sic!) to version 8.1, but am unclear about to 
> convert one key aspect of the -ml- program. These programs, fitting 
> parametric functional forms to distributions of data, are a little 
> unusual because they don't have a dependent variable with explanatory 
> variables in the way a regression model usually does, and fitting in 
> version 4 involved a particular "depv(000)" statement, thus:
> ~~~~~ado code extract ~~~~~~~~~~~~~~~~~~~
> ml begin
> ml func sm_ll
> ml method deriv0
> eq p1 :          
> eq p2 :          
> eq p3 :          
> ml model c = p1 p2 p3, depv(000) from(c0)
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> What is the version 8.1 equivalent of the "trick" used here, please?
> The "depv" option no longer exists.
> [Note: the original programs simply fitted 3 parameter functional 
> forms. In the update, I would also like to make each parameter 
> optionally a function of covariates. The original programs are 
> available using -ssc-.]

I've constructed an (admittedly silly) example to illustrate how Stephen may
go about using -ml- in Stata 8 to optimize his "functional forms".

Here is a -d0- "likelihood evaluator" that return the sum of two "upside-down"
parabolas:

***** BEGIN: parab_d0.ado
program parab_d0
	version 8.1
	args todo b lnf
	tempname x y
	mleval `x' = `b', scalar
	mleval `y' = `b', scalar eq(2)
	quietly mlsum `lnf' = 1 - (`x'-15)^2 - (`y'-10)^2
end
***** END: parab_d0.ado

We can now use -ml- to find the values x=15 and y=10, the only requirement is
that we have some data in memory (at least one observation to work with).
Here is a log of -parab_d0- in action:

***** BEGIN:
. clear

. sysuse auto
(1978 Automobile Data)

. keep in 1
(73 observations deleted)

. ml model d0 parab_d0 (x:) (y:)

. ml max

initial:       log likelihood =       -324
alternative:   log likelihood =     -299.5
rescale:       log likelihood =        -36
rescale eq:    log likelihood =         -4
Iteration 0:   log likelihood =         -4  
Iteration 1:   log likelihood =          1  
Iteration 2:   log likelihood =          1  

                                                  Number of obs   =          1
                                                  Wald chi2(0)    =          .
Log likelihood =          1                       Prob > chi2     =          .

------------------------------------------------------------------------------
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
x            |
       _cons |         15   .7071068    21.21   0.000      13.6141     16.3859
-------------+----------------------------------------------------------------
y            |
       _cons |         10   .7071068    14.14   0.000     8.614096     11.3859
------------------------------------------------------------------------------
***** END:

We could also make each parameter optionally a function of covariates.  In the
following example, we include -mpg- in the first equation and -turn- in the
second:

***** BEGIN:
. clear

. sysuse auto
(1978 Automobile Data)

. ml model d0 parab_d0 (x: mpg) (y: turn)

. ml max

initial:       log likelihood =     -23976
alternative:   log likelihood =     -22163
rescale:       log likelihood =      -2664
rescale eq:    log likelihood =       -296
Iteration 0:   log likelihood =       -296  
Iteration 1:   log likelihood =         74  
Iteration 2:   log likelihood =         74  

                                                  Number of obs   =         74
                                                  Wald chi2(1)    =       0.00
Log likelihood =         74                       Prob > chi2     =     1.0000

------------------------------------------------------------------------------
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
x            |
         mpg |  -1.24e-13   .0143048    -0.00   1.000    -.0280369    .0280369
       _cons |         15   .3155484    47.54   0.000     14.38154    15.61846
-------------+----------------------------------------------------------------
y            |
        turn |  -3.16e-13    .018812    -0.00   1.000    -.0368708    .0368708
       _cons |         10   .7503857    13.33   0.000     8.529271    11.47073
------------------------------------------------------------------------------
***** 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