Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Using ml with hard-coded variables.

From   "Nick B." <>
Subject   st: Using ml with hard-coded variables.
Date   Thu, 17 May 2007 18:54:41 -0400

I'm a beginner here, trying to use Stata's ml to estimate a
probit-like equation with non-linear terms.  However, whenever I try
using hard-coded independent variables, I get the following error:

initial:       log likelihood = -51.292891
alternative:   log likelihood =  -1877.398
rescale:       log likelihood = -48.015768
rescale eq:    log likelihood = -48.015768
could not calculate numerical derivatives
flat or discontinuous region encountered

Even when I simplify my system, I still get these errors, so I must be
doing something wrong.

For instance, using the built-in auto data, I try
sysuse auto
capture program drop probit1

program define probit1
	args lnf theta1
	tempvar p
	quietly gen double `p'=norm(`theta1'*mpg)
	quietly replace `lnf' = $ML_y1*ln(`p')+(1-$ML_y1)*ln(1-`p')

ml model lf probit1 (foreign=) /beta1
ml max
This produces the error, even though it is almost identical to the
textbook example for using ml for probit.  Specifically, replacing the
relevant lines with the non-hard-coded version

quietly gen double `p'=norm(`theta1')
ml model lf probit1 (foreign=mpg)

works fine.  So I assume I am doing something basic wrong in switching
to hard-coded variables.

The reason I need the hard-coded variables is that what I'm really
trying to estimate is closer to
capture program drop probit2

program define probit2
	args lnf theta1 theta2 theta3 theta4
	tempvar p
	quietly gen double
	quietly replace `lnf' = $ML_y1*ln(`p')+(1-$ML_y1)*ln(1-`p')

ml model lf probit2 (foreign=) /beta1 /beta2 /gamma1 /gamma2

ml max
Which of course produces the same error.

Any help would be greatly appreciated.
*   For searches and help try:

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