Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: evaluating maximum likelihood function

From   Carlotta Schuster <>
Subject   st: evaluating maximum likelihood function
Date   Wed, 20 Feb 2013 18:07:57 +0100

Hi all,

I am working on a non linear optimization problem using the ml
command. After some indications from statalisters I have created a
program which passes all the tests of ml check. However, when I try to
maximize the model, after hours of running, I get an error message
stating that Stata cannot calculate a numeric derivatives. Also, even
if I specify the iterate(0) in the options, the program still runs for
hours before giving any error.

In order to check whether my likelihood function evaluator is working
properly I would like to evaluate my likelihood function at some
predetermined values introduced by myself before doing any
maximization. I cannot find how to do this, but there should a way.
Any help would be appreciated. I include my code below. The third
piece of code is a program that my lf evaluator makes use of.


Carlotta Schuster

capture program drop nlprobitlf

program nlprobitlf

  version 11

  args lnfj xb b k

  tempvar xnl

global lambda = `k'


quietly generate double `xnl' = w

drop w

quietly replace `lnfj' = lnnormal(`xb'+`b'*`xnl') if ($ML_y1 == 1)

quietly replace `lnfj' = lnnormal(-`xb'-`b'*`xnl') if ($ML_y1 == 0)


local controls9 logincome logincomesq children childrensq
logliquidassets logliquidassetssq retired college highschool age agesq
married financial_sector ///


ml model lf nlprobitlf (istocks = `controls9') /b /k [pweight = hw0010]

capture program drop rmatcalc

program rmatcalc

version 11

*args lambda

tempvar aux_den

set more off

local N = _N

gen `aux_den' = 0

gen w = 0

forvalues i = 1(1)`N' {

local a = age-1 in `i'

forvalues y = 1(1)`a'{

qui replace `aux_den' = `aux_den' + (age-`y')^$lambda in `i'


forvalues z = 1(1)`a'{

qui replace w = w + ((age-`z')^$lambda)*rets`z'/`aux_den' in `i'



*drop w_den

*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index