Bookmark and Share

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: error with optimize(), d1-d2 evaluators and bhhh technique


From   Christophe Kolodziejczyk <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: error with optimize(), d1-d2 evaluators and bhhh technique
Date   Thu, 5 Dec 2013 16:08:09 +0100

I've tried to estimate a linear regression model by MLE. I have used
Mata and the optimize() routine. Furthermore I have tried to use the
BHHH algorithm, but the program failed, as I got the following error
message

type d1 evaluators are not allowed with technique bhhh
r(111);

I do not understand, why I  got this error message. The documentation
mentions that you cannot use BHHH with a d0, since the hessian is
based on the gradient of the likelihood function, which has to be
computed analytically. Any idea what I am doing wrong or what i am
missing?

I have included the code below. The program works with technique nr
(but strangely not with BFGS, since it does not find an optimum).

Best
Christophe


 Here is the log file of my code
------------------------------------------------------------------------------
      name:  <unnamed>
       log:  C:\Users\CK\Dropbox\Myfiles\Stata\ML_normal.log
  log type:  text
 opened on:   5 Dec 2013, 15:53:44
.
. clear mata
. mata
------------------------------------------------- mata (type end to exit) ----
:
: nobs=100000
: a=.25
: b=0.5
: one=J(nobs,1,1)
:
: rseed(10101)
: x=invnormal(uniform(nobs,1))
: v=invnormal(uniform(nobs,1))
: y=a:+x*b+v
:
: z=one,x
:
: void mylnf(todo, p,x,y,lnf,g,H)
> {
>
>                 nobs=rows(x)
>                 k=cols(x)
>                 beta=p[.,(1..k)]'
>                 lsigma=p[1,k+1]
>                 sigma=exp(lsigma)
>                 u=(y-x*beta)/sigma
>
>
>                 // lnf=-lsigma-0.5*(u'*u)
>                 lnf=colsum(-lsigma:-0.5*u:^2)
>
>                 if (todo>=1) {
>
>                                 // g[1..k]=colsum(u:*x)/sigma
>                                 g[1..k]=((x'*u)/sigma)'
>
>
>                                 // g[k+1]=colsum(-1:+(u:^2))
>                                 g[k+1]=-nobs:+u'*u
>                 }
>
>                 if (todo>=2) {
>
>                                 H[1..k,1..k]=-(x'*x)/(sigma^2)
>                                 H[k+1,k+1]=-2*u'*u
>                                 H[k+1,1..k]=u'*x
>
>                                 _makesymmetric(H)
>
>                 }
>
>
> }
:
: S=optimize_init()
: optimize_init_evaluator(S, &mylnf())
: optimize_init_evaluatortype(S, "d1")
: optimize_init_params(S, runiform(1,3))
: optimize_init_argument(S,1,z)
: optimize_init_argument(S,2,y)
: optimize_init_technique(S,"bhhh")
: p=optimize(S)
type d1 evaluators are not allowed with technique bhhh
r(111);
: optimize_result_params(S)
                 1             2             3
    +-------------------------------------------+
  1 |  .8304800626   .7447444859   .7526524097  |
    +-------------------------------------------+
: optimize_result_V(S)
[symmetric]
       1   2   3
    +-------------+
  1 |  0          |
  2 |  0   0      |
  3 |  0   0   0  |
    +-------------+
:
:
: end
------------------------------------------------------------------------------
.
. log close
      name:  <unnamed>
       log:  C:\Users\CK\Dropbox\Myfiles\Stata\ML_normal.log
  log type:  text
 closed on:   5 Dec 2013, 15:53:44
------------------------------------------------------------------------------

-- 
Christophe Kolodziejczyk
Research Fellow

KORA
Danish Institute of Governmental Research
Købmagergade 22
DK-1150 København K

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


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index