Program mlogit

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt

bonnieclyde
Posts: 4
Joined: Fri Jan 23, 2009 12:17 pm

Program mlogit

Postby bonnieclyde » Fri Jan 23, 2009 12:50 pm

Hello,

First, sorry for my english (I'm french).
I have a problem with the writing of a mlogit program. When the program is running, the error "dd2 is not define" appear. I don't no why, and I don't know if the program is write correctly.
I have 12 variables :
dependent variable : pa (7 states)
predictor varibales : ges (4 states), infce (3 states), formace (3 states), mo (6 states), eqbat (3 states), eqmat (5 states), stru (4 states), surf (5 states), capt (3 states), mort (4 states).

The program is :

Code: Select all

' Chargement de la base de données "bpm"
load "bpm"
' déclaration du vecteur des paramètres
coef (11) b2
coef (11) b3
coef (11) b4
coef (11) b5
coef (11) b6
coef (11) b7
logl mlogit
mlogit.append @logl logl1
mlogit.append xb2 = b2(1)+b2(2)*ges+b2(3)*infce+b2(4)*formace+b2(5)*mo+b2(6)*eqbat+b2(7)*eqmat+b2(8)*stru+b2(9)*surf+b2(10)*capt+b2(11)*mort
mlogit.append xb3 = b3(1)+b3(2)*ges+b3(3)*infce+b3(4)*formace+b3(5)*mo+b3(6)*eqbat+b3(7)*eqmat+b3(8)*stru+b3(9)*surf+b3(10)*capt+b3(11)*mort
mlogit.append xb4 = b4(1)+b4(2)*ges+b4(3)*infce+b4(4)*formace+b4(5)*mo+b4(6)*eqbat+b4(7)*eqmat+b4(8)*stru+b4(9)*surf+b4(10)*capt+b4(11)*mort
mlogit.append xb5 = b5(1)+b5(2)*ges+b5(3)*infce+b5(4)*formace+b5(5)*mo+b5(6)*eqbat+b5(7)*eqmat+b5(8)*stru+b5(9)*surf+b5(10)*capt+b5(11)*mort
mlogit.append xb6 = b6(1)+b6(2)*ges+b6(3)*infce+b6(4)*formace+b6(5)*mo+b6(6)*eqbat+b6(7)*eqmat+b6(8)*stru+b6(9)*surf+b6(10)*capt+b6(11)*mort
mlogit.append xb7 = b7(1)+b7(2)*ges+b7(3)*infce+b7(4)*formace+b7(5)*mo+b7(6)*eqbat+b7(7)*eqmat+b7(8)*stru+b7(9)*surf+b7(10)*capt+b7(11)*mort
mlogit.append denom = 1+exp(xb2)+exp(xb3)+exp(xb3)+exp(xb4)+exp(xb5)+exp(xb6)+exp(xb7)
mlogit.append pr1 = 1/denom
mlogit.append pr2 = exp(xb2)/denom
mlogit.append pr3 = exp(xb3)/denom
mlogit.append pr4 = exp(xb4)/denom
mlogit.append pr5 = exp(xb5)/denom
mlogit.append pr6 = exp(xb6)/denom
mlogit.append pr7 = exp(xb7)/denom
mlogit.append logl1 = (1-dd2-dd3-dd4-dd5-dd6-dd7)*log(pr1)+dd2*log(pr2)+dd3*log(pr3)+dd4*log(pr4)+dd5*log(pr5)+dd6*log(pr6)+dd7*log(pr7)
' Dérivées analytiques
for !i=2 to 7
mlogit.append @deriv b!i(1) grad !i1 b!i(2) grad !i2 b!i(3) grad !i3 b!i(4) grad !i4 b!i(5) grad !i5 b!i(6) grad !i6 b!i(7) grad !i7 b!i(8) grad !i8 b!i(9) grad !i9 b!i(10) grad !i10 b!i(11) grad !i11
mlogit.append grad !i1 = dd!i-pr!i
mlogit.append grad !i2 = grad !i1*ges
mlogit.append grad !i3 = grad !i1*infce
mlogit.append grad !i4 = grad !i1*formace
mlogit.append grad !i5 = grad !i1*mo
mlogit.append grad !i6 = grad !i1*eqbat
mlogit.append grad !i7 = grad !i1*eqmat
mlogit.append grad !i8 = grad !i1*stru
mlogit.append grad !i9 = grad !i1*surf
mlogit.append grad !i10 = grad !i1*capt
mlogit.append grad !i11 = grad !i1*mort
next
' Calculer les valeurs initiales à partir de Logit Binomiaux
equation eq2.binary(d=1) dd2 c ges infce formace mo eqbat eqmat stru surf capt mort
b2 = eq2.@coefs
equation eq3.binary(d=1) dd3 c ges infce formace mo eqbat eqmat stru surf capt mort
b3 = eq3.@coefs
equation eq4.binary(d=1) dd4 c ges infce formace mo eqbat eqmat stru surf capt mort
b4 = eq4.@coefs
equation eq5.binary(d=1) dd5 c ges infce formace mo eqbat eqmat stru surf capt mort
b5 = eq5.@coefs
equation eq6.binary(d=1) dd6 c ges infce formace mo eqbat eqmat stru surf capt mort
b6 = eq6.@coefs
equation eq2.binary(d=1) dd7 c ges infce formace mo eqbat eqmat stru surf capt mort
b7 = eq7.@coefs
' Estimation Max. de Vraissemblance et affichage résultats
mlogit.ml(d)
show mlogit.output


Is anybody can help me ? I'm inexperienced in programation and i found this program in a book.

Thanks

startz
Non-normality and collinearity are NOT problems!
Posts: 3775
Joined: Wed Sep 17, 2008 2:25 pm

Re: Program mlogit

Postby startz » Fri Jan 23, 2009 1:26 pm

bonnieclyde wrote:Hello,

First, sorry for my english (I'm french).
I have a problem with the writing of a mlogit program. When the program is running, the error "dd2 is not define" appear. I don't no why, and I don't know if the program is write correctly.
I have 12 variables :
dependent variable : pa (7 states)
predictor varibales : ges (4 states), infce (3 states), formace (3 states), mo (6 states), eqbat (3 states), eqmat (5 states), stru (4 states), surf (5 states), capt (3 states), mort (4 states).

The program is :

Code: Select all

' Chargement de la base de données "bpm"
load "bpm"
' déclaration du vecteur des paramètres
coef (11) b2
coef (11) b3
coef (11) b4
coef (11) b5
coef (11) b6
coef (11) b7
logl mlogit
mlogit.append @logl logl1
mlogit.append xb2 = b2(1)+b2(2)*ges+b2(3)*infce+b2(4)*formace+b2(5)*mo+b2(6)*eqbat+b2(7)*eqmat+b2(8)*stru+b2(9)*surf+b2(10)*capt+b2(11)*mort
mlogit.append xb3 = b3(1)+b3(2)*ges+b3(3)*infce+b3(4)*formace+b3(5)*mo+b3(6)*eqbat+b3(7)*eqmat+b3(8)*stru+b3(9)*surf+b3(10)*capt+b3(11)*mort
mlogit.append xb4 = b4(1)+b4(2)*ges+b4(3)*infce+b4(4)*formace+b4(5)*mo+b4(6)*eqbat+b4(7)*eqmat+b4(8)*stru+b4(9)*surf+b4(10)*capt+b4(11)*mort
mlogit.append xb5 = b5(1)+b5(2)*ges+b5(3)*infce+b5(4)*formace+b5(5)*mo+b5(6)*eqbat+b5(7)*eqmat+b5(8)*stru+b5(9)*surf+b5(10)*capt+b5(11)*mort
mlogit.append xb6 = b6(1)+b6(2)*ges+b6(3)*infce+b6(4)*formace+b6(5)*mo+b6(6)*eqbat+b6(7)*eqmat+b6(8)*stru+b6(9)*surf+b6(10)*capt+b6(11)*mort
mlogit.append xb7 = b7(1)+b7(2)*ges+b7(3)*infce+b7(4)*formace+b7(5)*mo+b7(6)*eqbat+b7(7)*eqmat+b7(8)*stru+b7(9)*surf+b7(10)*capt+b7(11)*mort
mlogit.append denom = 1+exp(xb2)+exp(xb3)+exp(xb3)+exp(xb4)+exp(xb5)+exp(xb6)+exp(xb7)
mlogit.append pr1 = 1/denom
mlogit.append pr2 = exp(xb2)/denom
mlogit.append pr3 = exp(xb3)/denom
mlogit.append pr4 = exp(xb4)/denom
mlogit.append pr5 = exp(xb5)/denom
mlogit.append pr6 = exp(xb6)/denom
mlogit.append pr7 = exp(xb7)/denom
mlogit.append logl1 = (1-dd2-dd3-dd4-dd5-dd6-dd7)*log(pr1)+dd2*log(pr2)+dd3*log(pr3)+dd4*log(pr4)+dd5*log(pr5)+dd6*log(pr6)+dd7*log(pr7)
' Dérivées analytiques
for !i=2 to 7
mlogit.append @deriv b!i(1) grad !i1 b!i(2) grad !i2 b!i(3) grad !i3 b!i(4) grad !i4 b!i(5) grad !i5 b!i(6) grad !i6 b!i(7) grad !i7 b!i(8) grad !i8 b!i(9) grad !i9 b!i(10) grad !i10 b!i(11) grad !i11
mlogit.append grad !i1 = dd!i-pr!i
mlogit.append grad !i2 = grad !i1*ges
mlogit.append grad !i3 = grad !i1*infce
mlogit.append grad !i4 = grad !i1*formace
mlogit.append grad !i5 = grad !i1*mo
mlogit.append grad !i6 = grad !i1*eqbat
mlogit.append grad !i7 = grad !i1*eqmat
mlogit.append grad !i8 = grad !i1*stru
mlogit.append grad !i9 = grad !i1*surf
mlogit.append grad !i10 = grad !i1*capt
mlogit.append grad !i11 = grad !i1*mort
next
' Calculer les valeurs initiales à partir de Logit Binomiaux
equation eq2.binary(d=1) dd2 c ges infce formace mo eqbat eqmat stru surf capt mort
b2 = eq2.@coefs
equation eq3.binary(d=1) dd3 c ges infce formace mo eqbat eqmat stru surf capt mort
b3 = eq3.@coefs
equation eq4.binary(d=1) dd4 c ges infce formace mo eqbat eqmat stru surf capt mort
b4 = eq4.@coefs
equation eq5.binary(d=1) dd5 c ges infce formace mo eqbat eqmat stru surf capt mort
b5 = eq5.@coefs
equation eq6.binary(d=1) dd6 c ges infce formace mo eqbat eqmat stru surf capt mort
b6 = eq6.@coefs
equation eq2.binary(d=1) dd7 c ges infce formace mo eqbat eqmat stru surf capt mort
b7 = eq7.@coefs
' Estimation Max. de Vraissemblance et affichage résultats
mlogit.ml(d)
show mlogit.output


Is anybody can help me ? I'm inexperienced in programation and i found this program in a book.

Thanks


This may be an obvious question, but do you have a series named "dd2" in the workfile?
(By the way, your English is pretty good!)

bonnieclyde
Posts: 4
Joined: Fri Jan 23, 2009 12:17 pm

Re: Program mlogit

Postby bonnieclyde » Fri Jan 23, 2009 2:50 pm

No, i haven't a serie named "dd2". I don't know what "dd2" means.
It's seams to be used in order to specify likelihood

startz
Non-normality and collinearity are NOT problems!
Posts: 3775
Joined: Wed Sep 17, 2008 2:25 pm

Re: Program mlogit

Postby startz » Fri Jan 23, 2009 3:53 pm

bonnieclyde wrote:No, i haven't a serie named "dd2". I don't know what "dd2" means.
It's seams to be used in order to specify likelihood

Ah, dd2 is a variable in the workfile for which the example program was written. It doesn't have anything to do with general issue of specifying the log-likelihood.

bonnieclyde
Posts: 4
Joined: Fri Jan 23, 2009 12:17 pm

Re: Program mlogit

Postby bonnieclyde » Fri Jan 23, 2009 4:01 pm

I found the problem. I'm going to explain it, maybe someone will need to know.
Because of mlogit doesn't exist, the program is made on the model of binomial logit. The dependent variable has to be change in binary data. Then, dd2=1 if the individual has the second state of the dependent variable, if not, dd2=0.
I don't know if it's understanding (because of my bad english)....

Thanks startz for your answer

thinhlien
Posts: 7
Joined: Thu Jun 11, 2009 4:04 am

Re: Program mlogit

Postby thinhlien » Thu Jun 11, 2009 4:17 am

Hi bonnieclyde,

First, I am sorry for my bad English too.

I am now learning how to write an eviews program and facing the same problem with mlogit program.

I don't understand d1, d2, d3 and dd2, dd3 in the workfile mlogit of Eviews book.

I read your explanations about dd but still can't understand.

could you pls explain it in details for me?

Thanks alot.

thinhlien.

trubador
Did you use forum search?
Posts: 1518
Joined: Thu Nov 20, 2008 12:04 pm

Re: Program mlogit

Postby trubador » Fri Jun 12, 2009 3:38 am

In order to carry out a multinomial logit analysis, one category of the dependent variable has to be chosen as the comparison (or reference) category. After that, you should define binary variables for the remaining categories (similar to constructing a dummy variable). dd2 and dd3 are these binary variables and created from a dependent variable that has 3 different categories (for details please see the reference book mentioned in the beginning of the sample program).

thinhlien
Posts: 7
Joined: Thu Jun 11, 2009 4:04 am

Re: Program mlogit

Postby thinhlien » Fri Jun 12, 2009 4:08 am

Thank you very much, Trubador!

I will try to read the reference book as you suggested. If I still face difficulties, pls allow me to ask you.

Sincerely thanks,
thinhlien.

thinhlien
Posts: 7
Joined: Thu Jun 11, 2009 4:04 am

Re: Program mlogit

Postby thinhlien » Mon Jun 15, 2009 2:55 am

Dear Trubador,

I already read your suggested reference book and could understand a little bit. Thanks alot.

This is my problem. I would like to investigate how the real output (regressor X1) and inflation rate (regressor X2) affect the mechanism of monetary policy (dependent variable Y). Thus, there are 3 cases: (1) a decrease in interest rate (or an expansionary monetary policy); (2) an increase in interest rate (or a tightened monetary policy) (3) no change in interest rate (or a neutral monetary policy). All my data are time series data (quarterly data, from 1999q1 to 2008q4)

In this case, I determine dd2 for an expansionary monetary policy; dd3 for a tightened monetary policy and dd1 for a neutral policy as follows:
Quarter intrate1 dd2 dd3
1999Q1 12.00 0.00 0.00
1999Q2 9.60 1.00 0.00
1999Q3 8.40 1.00 0.00
1999Q4 6.00 1.00 0.00
2000Q1 6.00 0.00 0.00
2000Q2 5.40 1.00 0.00
2000Q3 5.40 0.00 0.00
2000Q4 6.00 0.00 1.00

for the first period (1999q1) I assume that dd2=dd3=0.

Then dd1 is determined = 1 - dd2 - dd3

Is the above description correct? Could you pls help me with the determination of dd2, dd3 for my program?

Once again, thank you very much.

Best regards,
thinhlien.

trubador
Did you use forum search?
Posts: 1518
Joined: Thu Nov 20, 2008 12:04 pm

Re: Program mlogit

Postby trubador » Mon Jun 15, 2009 3:16 am

Yes, your binary variables seem correct.

thinhlien
Posts: 7
Joined: Thu Jun 11, 2009 4:04 am

Re: Program mlogit

Postby thinhlien » Mon Jun 15, 2009 3:20 am

Thanks alot, dear kind Trubador!!!

I will try to run the program now. I wish to consult you next time also.

Wish you all the best,
thinhlien

thinhlien
Posts: 7
Joined: Thu Jun 11, 2009 4:04 am

Re: Program mlogit

Postby thinhlien » Mon Jun 15, 2009 4:22 am

Dear Trubador,

I have just run the program and got the results. Now I have to study how to read and explain the results. I just know how to read OLS regression result: based on the p-values, the size and sign of coefficients, the Durbin Watson stat,... For LogL maximization, should we base on p-values to conclude? (I got all the p-values which are bigger than 5% even 10%, unfortunately). What are the important bases for us to conclude?

Could you pls consult me how to interpret the results of LogL maximization problem? Or could you pls suggest me any reference book?

Thank you very much for your kindness.
thinhlien.

trubador
Did you use forum search?
Posts: 1518
Joined: Thu Nov 20, 2008 12:04 pm

Re: Program mlogit

Postby trubador » Mon Jun 15, 2009 5:08 am

Any of these Textbooks or Books using EViews might be helpful. You can search the forum as well.

thinhlien
Posts: 7
Joined: Thu Jun 11, 2009 4:04 am

Re: Program mlogit

Postby thinhlien » Mon Jun 15, 2009 5:44 am

Thanks alot, dear Trubador!!!

I study alot from you and this forum! Hope to receive ur help next time!

Best regards,
thinhlien


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 8 guests