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 at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: MLE for each day


From   Beatrice Crozza <beatrice.crozza@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: MLE for each day
Date   Thu, 21 Oct 2010 15:45:12 +0100

I defined my program out of loop, so know I receive the results. Thanks Maarten.

However, the results that I receive are not for each day, but for the
whole year, so I think that I missed something as Nick suggested, but
where should I put the reference to each day?

Thanks,
Bea


program define mle
version 10.0
args lnf a d b n g

tempvar ma md mb  mn mg

quietly gen double `ma'=1-`a'
quietly gen double `md'=1-`d'
quietly gen double `mb'=1-`b'
quietly gen double `mn'=1-`n'
quietly gen double `mg'=1-`g'

quietly replace
`lnf'=ln((`a')*(`d')*((((`b')*(`md')*(`g')+(`b')*(`mg')*(`g')*(`n'))^r)*(((`mb')*(`mo')*(`g')+(`mb')*(`mn)*(`ma')*(`n'))^s)*(((`b')*(`md')*(`mg')*(`mn'))^t)*(((`mb')*(`mn')*(`ma')*(`g'))^s)*(((`b')*(`mg')*(`md')+(`mb')*(`b')*(`n'))^t)))

end

levelsof day
foreach day in `r(levels)' {
ml model lf mle (a:) (d:) (b:) (n:) (g:)
ml search
ml maximize, difficult
}

2010/10/21 Nick Cox <n.j.cox@durham.ac.uk>:
> In addition, nowhere in the loop do you refer to each value of `day'.
>
> Nick
> n.j.cox@durham.ac.uk
>
> Maarten Buis
> ============
>
> You still did not tell us what Stata _exactly_ told you when you executed that command. However, I can make a guess what a problem is: You should not define your program inside the loop.
>
> Beatrice Crozza
> ===============
>
> thank you very much for your help.
>
> I tried to follow your instructions, but I receive a break.
> What I am doing wrong?
>
> thanks,
> Bea
>
> Following my code:
>
> levelsof day
> foreach day in `r(levels)' {
> program define mle
> version 10.0
> args lnf a d b n g
>
> tempvar ma md mb  mn mg
>
> quietly gen double `ma'=1-`a'
> quietly gen double `md'=1-`d'
> quietly gen double `mb'=1-`b'
> quietly gen double `mn'=1-`n'
> quietly gen double `mg'=1-`g'
>
> quietly replace
> `lnf'=ln((`a')*(`d')*((((`b')*(`md')*(`g')+(`b')*(`mg')*(`g')*(`n'))^r)*(((`mb')*(`mo')*(`g')+(`mb')*(`mn)*(`ma')*(`n'))^s)*(((`b')*(`md')*(`mg')*(`mn'))^t)*(((`mb')*(`mn')*(`ma')*(`g'))^s)*(((`b')*(`mg')*(`md')+(`mb')*(`b')*(`n'))^t)))
>
> end
>
> ml model lf mle (a:) (d:) (b:) (n:) (g:)
> ml search
> ml maximize, difficult
> }
>
> 2010/10/21 Nick Cox <n.j.cox@durham.ac.uk>:
>
>> I strongly support Maarten's stance here. People who post unanswerable questions are, in the first instance, wasting their own time and delaying the receipt of good advice.
>>
>> On a matter of detail, note that -levels- leaves in its wake r(levels), not r(varlist). Thus the recipe should be
>>
>> levelsof day
>> foreach day in `r(levels)' {
>>    ml model lf my_prog_lf (y=x) (x2) ... if day == `day', maximize
>> }
>
> Maarten buis
>
>> --- On Thu, 21/10/10, Beatrice Crozza wrote:
>>> I wrote a maximum likelihood with the lf method.
>>>
>>> Now, I want to tell Stata to do the maximum likelihood for
>>> each day in my sample (each day is divided in time intervals).
>>>
>>> How can I do this?
>>>
>>> I tried foreach at the beginning of the program but doesn'
>>> t work.
>>
>> Doesn't work is not informative enough, we need to know
>> exactly what you typed, what you expected Stata to return,
>> and what Stata actually did return.
>>
>> Given what you told us I can only give you this pseudo-code
>> that you might or might not be able to adjust to your
>> problem
>>
>> levelsof day
>> foreach day in `r(varlist)' {
>>    ml model lf my_prog_lf (y=x) (x2) ... if day == `day', maximize
>> }
>>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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