全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
3751 11
2012-04-20
[size=+1]Dear  Members of this Blog,

I just found this blog and thought that some of you might help me out with a question i have concerning the ml-environment in Stata 10.0 i´m currently using:
For a recent project, I try to perform a panel-data probit likelihood estimation to unravel the preference parameters of investors on individual level. The whole approach I try to perform is based on a loose adaption of Harrison`s (2008) “Maximum Likelihood Estimation of Utility Functions Using Stata”, in which I implemented a trading model, which I want to calibrate now using ML.  The original dataset is similar to the structure in Gould, Pitblado and Sribney (2006) “Maximum Likelihood Estimation with Stata”, p. 110. It looks more or less like this (I hope it is not too scrambled):Obs. No.         Investor _ID        Security_ID         Date           Choice             Charact. Of Sec.        L.L.1                      1                          1                         t_0           1                                .2                1                          1                         t_1           1                                   .3                1                          1                         t_2           0                                   ln(L1)4                1                          2                         t_0           1                                   .5                1                          2                         t_1     1                                   .6                1                          2                         t_2           1                                   .7                1                          2                         t_3     0                                   ln(L2)8                2                          1                         t_0           1                                   .…and so on....As I’m interested which characteristics of the securities might also have an impact on the hold (=1) or sell (=0) decision of the respective investor, I inted to generate “sub”-log-likelihood functions at the end of each observation of “Choice” for each security and aggregate the sum of these log-likelihoods at investor-level.A sketch of my attempts looks like this (I´m using a stata 10.0 version and did already the "update query".):.....program define ML_My_problematic_model_1 // define maximum likelihood program for the panel datasetargs todo b lnf  //define variables and coefficient vector btempvar alpha lambda gamma  last lj **some more variables** utility_diff mleval `alpha' = `b', eq(1) mleval `lambda' = `b', eq(2) mleval `gamma' = `b', eq(3) //Variables of interest are alpha, lambda and gammaquietly {        **contains more or less specifications of the model** // define likelihood function per security_ID:by security_ID: gen double `utility_diff'=`utility_alternative_2' -`utility_alternative_1' //here I tried to generate the sub-likelihood functions for each security_ID (in line with Harrison (2008) as mentioned above)        by security_ID: gen byte `last'=_n==_N //construct likelihood for utility difference under iid assumption:        gen double `lj'=.        by security_ID: replace `lj' =(normal(`utility_diff')) if $ML_y1==0        by security_ID: replace `lj' =(normal(-`utility_diff')) if $ML_y1==1mlsum `lnf' = ln(`lj') if `last'==1 //sum the added likelihood functions at the end of each security_IDif (`todo'==0 | `lnf'>=.) exit}end.....It is the indented middle part that worries me: My problem is now, that I try to generate a sub-ln-likelihood function at the last observation of the group, here “security_ID” for the “Choice” variable. Trying to sum them up with mlsum returns only a likelihood function of 0 or an algorithm that generates an error message, stating that numerical derivatives are flat or not obtainable- no matter what I do. Furthermore, mlsum seems to add the whole column of my dataset such that it seems the "by security_ID : ..." is fairly ignored..   The ml check works fine and indicates no serious issues. I obtained the results (if not interrupted after 300 iterations) using:statsby [alpha]_cons [lambda]_cons [gamma]_cons, by(person_ID) clear: ml model d0 ML_My_problematic_model_1 (alpha: Choice  **a lot of other variables** = ) (lambda: ) (gamma: ), maximize technique(dfp nr)To check the results  I got with this program, I created a “test”-sample to play around, for which I wrote the likelihood-program for this particular investors aswell but in which the securities are listed side by side. This program surprisingly works quite fine but would be (obviously) messy to apply for all investors (if it helps I can also post it here). I can´t see a large difference to the code shown in Gould, Pitblado and Sribney (2006), p. 111 which confuses me. I hope the information is sufficient to make a first statement about this problem and to give me an indication where my flaws are..Thank you very much in advance !

Teddy

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2012-4-20 20:32:52
楼主你思路能不能清晰些
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-4-20 20:35:04
hi, sorry.. here is a clearer version of it (it seems its too scrambled)

http://www.stata.com/statalist/archive/2012-04/msg00712.html

Hope it works..
Teddy
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-4-20 20:40:24
ok i have a try- hope its not too scrambled...

this is my program

program define ML_My_problematic_model_1 // define maximum likelihood program

args todo b lnf  //define variables and coefficient vector b

tempvar alpha lambda gamma  last lj **some more variables** utility_diff

mleval `alpha' = `b', eq(1)

mleval `lambda' = `b', eq(2)

mleval `gamma' = `b', eq(3) //Variables of interest are alpha, lambda and gamma


quietly {        **contains more or less specifications of the model** // define likelihood function per security_ID:


by security_ID: gen double `utility_diff'=`utility_alternative_2' -`utility_alternative_1' //here I tried to generate the sub-likelihood functions for each security_ID

by security_ID: gen byte `last'=_n==_N //construct sub- likelihood

        gen double `lj'=.

        by security_ID: replace `lj' =(normal(`utility_diff')) if $ML_y1==0

        by security_ID: replace `lj' =(normal(-`utility_diff')) if $ML_y1==1

mlsum `lnf' = ln(`lj') if `last'==1 //sum the added likelihood functions at the end of each security_ID

if (`todo'==0 | `lnf'>=.) exit

}

end
.....

My problem is that the middle part (by Security_ID:...) doesn´t really generate the sub-likelihood functions..

mlsum here forms the likelihood across all Security_ID´s and not just adds the sub-likelihoods for each security. I think there´s some flaw in the part of the program where the "by security_ID: " shows up..

Thank you for your help
Teddy
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-4-21 10:22:00
My problem is that the middle part (by Security_ID:...) doesn´t really generate the sub-likelihood functions..
by without the sort option requires that the data be sorted

cap pr drop ML_My_problematic_model_1
pr ML_My_problematic_model_1
args todo b lnf
tempvar alpha lambda gamma last lj utility_diff
mleval `alpha' = `b', eq(1)
mleval `lambda' = `b', eq(2)
mleval `gamma' = `b', eq(3)
qui{
sort security_ID
by security_ID: g double `utility_diff'=`utility_alternative_2' -`utility_alternative_1'
by security_ID: g byte `last'=_n==_N
g double `lj'=.
by security_ID: replace `lj' =normal(`utility_diff'*(-1)^$ML_y1)
mlsum `lnf' = ln(`lj') if `last'
if (!`todo'|`lnf'>=.) exit
}
end

(1) It seems that the first macro after "args" stands for the general term in the cumulative sum.
(2) "**  **" cannot be used as "in-line" comment delimiters.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-4-21 20:29:52
sungmoo 发表于 2012-4-21 10:22
by without the sort option requires that the data be sorted

cap pr drop ML_My_problematic_model ...
Hi,

thank you for your reply.

I sorted the data by security_ID one line before. Alternatively i used "bysort security_ID" and tried also a foreach loop using levelsof security_ID, local(security) to enerate the varlist. Unfortunately still without results.. :-(
I can also post the results if it helps to identify the problem..

Thanks again.
Regards,
Teddy
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群