Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: evaluating maximum likelihood function
From
Carlotta Schuster <[email protected]>
To
[email protected]
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.
Thanks.
Carlotta Schuster
capture program drop nlprobitlf
program nlprobitlf
version 11
args lnfj xb b k
tempvar xnl
global lambda = `k'
rmatcalc
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)
end
local controls9 logincome logincomesq children childrensq
logliquidassets logliquidassetssq retired college highschool age agesq
married financial_sector ///
SMC_pc GPD_pc GDP_pc INF UNEMP PENS
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
end
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/