Statalist


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

Re: st: RE: difficult ML program


From   "Lenny Stoeldraijer" <[email protected]>
To   [email protected]
Subject   Re: st: RE: difficult ML program
Date   Fri, 7 Mar 2008 09:40:18 +0100

Hello Nick, Maarten and other statalisters,

I will try to put my question again. Just forget everything I've written.

Is there a way to to put the following loglikelihood into a ml-code:
D*(b+X)-exp(b)*Y
where b is the parameter to be estimated, D is a dummy variable and X
and Y are vectors.

Hopefully, my problem is more clear this way. I don't know how else to put it.

Every help is much appreciated.

Best,
Lenny

[My program was working al the time, but with a wrong function. And
the constraint I tried to add to make it correct, gave the errors.]

2008/3/4, Nick Cox <[email protected]>:
> My point was not what do you know -- everyone has to learn -- but that
> you need to show
> enough for others to make sense of your problem.
>
> I can't comment on why your program wasn't working before but now is
> working,
> as you don't say what is different. That's history, however.
> Maarten has already responded to the concrete points here.
>
> Nick
> [email protected]
>
> Lenny Stoeldraijer
>
> Hi Nick,
>
> The problem is that I don't have much knowledge of maximum likelihood
> estimating. I've been told that it is a duration model (hazu is then
> the hazard function and survu the survivor function). Someone asked me
> if I could program some TSP programs in Stata for the use of students
> and I succeeded for some simpler programs. This one, however, is
> running okay, but (after more than half an hour) I stop the program,
> because it does not seem to work correctly. First of all, the
> likelihoods are positive and keeps on growing (to me, this looks
> wrong). And well, it keeps on calculating something (I'm using Stata
> 10 by the way). And the last thing why I think it is not calculating
> what it is supposed to be, is that the function ua needs only one
> coefficient to be calculated, whereas my program has two (in theta1
> and in theta2). So I need some 'trick' to let Stata know that it is
> the same coefficient (some kind of constraint maybe). The TSP formula
> looks like this: frml ua  exp(exit*(lu0000a+hazu)-exp(lu0000a)*survu);
> (where it is first defined: frml exit uncc; and the function covu, lu0
> ... lu15, hazu and survu)
>
> Thanks for your comment. Unfortunately, it was not such a simple thing
> as a space.
>
> Best,
>
> Lenny
>
>
> clear
> set memory 300m
> use fi
> gen trt39t52=tr*(t39+t52)
> capture program drop myml
> program define myml
>            args lnf covu lu0 lu1 lu2 lu3 lu4 lu5 lu6 lu7 lu8 lu9 lu10
> lu11 lu12 lu13 lu14 lu15 theta1 theta2
>                tempvar hazu survu ua
>            quietly gen double `hazu' =
> `covu'+`lu0'+dtu1*`lu1'+dtu2*`lu2'+dtu3*`lu3'+dtu4*`lu4'+dtu5*`lu5'+dtu6
> *`lu6'+dtu7*`lu7'+dtu8*`lu8'+dtu9*`lu9'+dtu10*`lu10'+dtu11*`lu11'+dtu12*
> `lu12'+dtu13*`lu13'+dtu14*`lu14'+dtu15*`lu15'
>            quietly gen double `survu' =
> exp(`covu'+`lu0')*(btu0+btu1*exp(`lu1') + btu2*exp(`lu2') +
> btu3*exp(`lu3') +
> btu4*exp(`lu4')+btu5*exp(`lu5')+btu6*exp(`lu6')+btu7*exp(`lu7')+btu8*exp
> (`lu8')+btu9*exp(`lu9')+btu10*exp(`lu10')+btu11*exp(`lu11')+btu12*exp(`l
> u12')+btu13*exp(`lu13')+btu14*exp(`lu14')+btu15*exp(`lu15'))
>                quietly gen double `ua' =
> exp(`theta1'+uncc*`hazu'-`theta2')
>                replace `lnf' = log(`ua')
> end
> ml model lf myml (covu: age married single divorced sfrau f_marr
> f_single f_divor lehre med_educ hi_educ lwage ein_zus bc seasonal
> manuf pnon ten72 y1988 y1989 y1990 y1991 q2 q3 q4, nocons) (lu0: tr
> t39 t52 trt39t52 after0 tr_a0 t39_a0 t52_a0 t39tra0 t52tra0, nocons)
> (lu1: tr t39 t52 trt39t52 after1 tr_a1 t39_a1 t52_a1 t39tra1 t52tra1)
> (lu2: tr t39 t52 trt39t52 after2 tr_a2 t39_a2 t52_a2 t39tra2 t52tra2)
> (lu3: tr t39 t52 trt39t52 after3 tr_a3 t39_a3 t52_a3 t39tra3 t52tra3)
> (lu4: tr t39 t52 trt39t52 after4 tr_a4 t39_a4 t52_a4 t39tra4 t52tra4)
> (lu5: tr t39 t52 trt39t52 after5 tr_a5 t39_a5 t52_a5 t39tra5 t52tra5)
> (lu6: tr t39 t52 trt39t52 after6 tr_a6 t39_a6 t52_a6 t39tra6 t52tra6)
> (lu7: tr t39 t52 trt39t52 after7 tr_a7 t39_a7 t52_a7 t39tra7 t52tra7)
> (lu8: tr t39 t52 trt39t52 after8 tr_a8 t39_a8 t52_a8 t39tra8 t52tra8)
> (lu9: tr t39 t52 trt39t52 after9 tr_a9 t39_a9 t52_a9 t39tra9 t52tra9)
> (lu10: tr t39 t52 trt39t52 after10 tr_a10 t39_a10 t52_a10 t39tra10
> t52tra10) (lu11: tr t39 t52 trt39t52 after11 tr_a11 t39_a11 t52_a11
> t39tra11 t52tra11) (lu12: tr t39 t52 trt39t52 after12 tr_a12 t39_a12
> t52_a12 t39tra12 t52tra12) (lu13: tr t39 t52 trt39t52 after13 tr_a13
> t39_a13 t52_a13 t39tra13 t52tra13) (lu14: tr t39 t52 trt39t52 after14
> tr_a14 t39_a14 t52_a14 t39tra14 t52tra14) (lu15: tr t39 t52 trt39t52
> after15 tr_a15 t39_a15 t52_a15 t39tra15 t52tra15) (theta1: uncc)
> (theta2: `survu'), technique(bhhh)
> ml check
> ml maximize
>
>
> 2008/3/4, Nick Cox <[email protected]>:
> > My guess is that you need to hide less and show and explain more.
> >
> > If you -set trace on- where does the program crash?
> >
> > The error code you cite, 111, is invalid syntax, which by itself is
> > not helpful.
> >
> > replace`lnf' = log(`ua')
> >
> > would very probably not work. There needs to be a space after
> -replace-.
> >
> >
> > Nick
> > [email protected]
> >
> > Lenny Stoeldraijer
> >
> > I'm trying to make my own maximum likelihood model, but I can't get it
> > right. The first part looks okay (I think), but then I have to define
> > the function which is called ua, which looks like:
> > exp(uncc*(b+hazu)-exp(b)*survu), where b is the coefficient to be
> > estimated. This coefficient is thus used twice but once with an
> > exponential. So far, my code looks like this (I've left some parts
> > out):
> >
> > program define myml
> > args lnf covu lu0 lu1 lu2 ... theta1 theta2
> > tempvar hazu survu ua
> > quietly gen double `hazu' = `covu'+`lu0'+dtu1*`lu1'+dtu2*`lu2'+...
> > quietly gen double `survu' =
> > exp(`covu'+`lu0')*(btu0+btu1*exp(`lu1')+btu2*exp(`lu2')+...
> > quietly gen double `ua' = exp(`theta1'+uncc*`hazu'-`theta2')
> > replace`lnf' = log(`ua')
> > end
> > ml model lf myml (covu: ... , nocons) (luo: ... , nocons) (lu1:...)
> > (lu2:...) ... (theta1: uncc) (theta2: `survu'), technique(bhhh)
> >
> > In the code I thus have different estimates for the b (once in theta1
> > and once in theta2). I've tried to include a constraint (e.g.
> > b1=log(b2)), but then I get errors (111 for example).
>
> *
> *   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/
>
*
*   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