Statalist


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

st: RE: writing a likelihood function: spike model


From   "Karfakis, Panagiotis (ESAF)" <[email protected]>
To   [email protected]
Subject   st: RE: writing a likelihood function: spike model
Date   Fri, 22 Aug 2008 14:03:02 +0200

Title: Message
Dear statalist users,
 
I managed to resolve the problem with the likelihood function in stata!
But any hint on how to predict marginal effects, linear predictions of coefficients and how to include heteroskedastic variance in the program below would be very-very much appreciated!!!
 
best regards
P Karfakis
 
***********************************
clear
webuse auto.dta
gen foreign1=foreign==1
gen turn1=turn<40
gen ri=1
global DDhat "ri"
global RRhat "price gear_ratio displacement weight trunk"
** 2nd *********************************
capture program drop spike2
program spike2
        args lnf Dhat Rhat sigmaD sigmaR
        quietly replace `lnf' = -`Dhat' - ln(1+exp(-`Dhat')) 
                           if $ML_y1 == 0
        quietly replace `lnf' = -ln(1+exp(-`Dhat')) + ln(1-normal(`Rhat'))              i
f $ML_y1 == 1 & $ML_y2 == 0
        quietly replace `lnf' = -ln(1+exp(-`Dhat')) + ln( normal(`Rhat'))               if $ML_y1 == 1 & $ML_y2 == 1
end
ml model lf spike2 (Dhat: turn1= $DDhat) (Rhat: foreign1 = $RRhat)
ml maximize
***********************************
 
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Karfakis, Panagiotis (ESAF)
Sent: 21 August 2008 17:06
To: [email protected]
Subject: st: writing a likelihood function: spike model

Dear statalist users,

I am trying to write a likelihood function that jointly estimates a logit and a probit since in the model a sequential decision process is considered. In particular the story is about the participation on an insurance project and then the willingness to pay a prespecified bid for the contract (2 discrete choice decisions and dependent variables). The joint estimation tries to account for the effect of excess negative responses in the participation, on the estimated willingness to pay (called spike model by some authors).

I provide below 2 alternatives of the same likelihood function I have written so far (applying them to the auto.dta).

1) In the 1st one while the optimization starts, in the 2nd iteration the log likelihood turns positive and increasing which is obviously wrong for discrete choice models.

In the 2nd the optimization just stops, reporting that "could not find feasible values"
Even if I use 2 probits I get the same problems.

2) If I want to estimate a heteroskedastic version of the model, how I could include the standard deviations (sigmaD sigmaR) in the code?

Anyhow I am a newbie to writing likelihood functions in stata and for sure I am doing something wrong!

I would like to request your help on how I could resolve the problem of writing the likelihood function properly and including a function for the variances.

thank you in advance!
Panagiotis Karfakis

PS: I use stata10

***********************************
clear
webuse auto.dta

gen foreign1=foreign==1
gen turn1=turn<40
gen ri=1

global DDhat "ri"
global RRhat "price gear_ratio displacement weight trunk"

** 1st *********************************

capture program drop spike1
program spike1
        args lnf Dhat Rhat sigmaD sigmaR
        tempvar p w
        quietly gen double `p' = 1/(1+exp(-`Dhat'))
        quietly gen double `w' = normal(`Rhat')
        quietly replace `lnf' =(1-$ML_y1)*ln(`p')+($ML_y1)*ln(1-`p')*(1-$ML_y2) *ln(1-`w')+($ML_y1)*ln(1-`p')*($ML_y2) *ln(`w')

end
ml model lf spike1 (Dhat: turn1= $DDhat ) (Rhat: foreign1 = $RRhat)
ml maximize

** 2nd *********************************

capture program drop spike2
program spike2
        args lnf Dhat Rhat sigmaD sigmaR
        quietly replace `lnf' = ln(    1/(1+exp(-`Dhat')))                                      if $ML_y1 == 0
        quietly replace `lnf' = ln((1-(1/(1+exp(-`Dhat'))))+ln(1-normal(`Rhat')))       if $ML_y1 == 1 & $ML_y2 == 0
        quietly replace `lnf' = ln((1-(1/(1+exp(-`Dhat'))))+ln(  normal(`Rhat')))       if $ML_y1 == 1 & $ML_y2 == 1
end
ml model lf spike2 (Dhat: turn1= $DDhat) (Rhat: foreign1 = $RRhat)
ml maximize

***********************************




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index