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

From |
"Karfakis, Panagiotis (ESAF)" <Panagiotis.Karfakis@fao.org> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
st: writing a likelihood function: spike model |

Date |
Thu, 21 Aug 2008 17:06:21 +0200 |

Title:

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

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

- Prev by Date:
**RE: st: RE: SUR with panel data** - Next by Date:
**st: selection model with endogenous regressor** - Previous by thread:
**st: RE: SUR with panel data** - Next by thread:
**st: selection model with endogenous regressor** - Index(es):

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