Multinomial Logistic Regression (MLR)
Moderators: EViews Gareth, EViews Moderator
Multinomial Logistic Regression (MLR)
Hi,
I am trying to adapt the example MLR in the help guide but keep getting errors.
Basically, I will have 7 categories of dependant variable (1-7), and 5 regressors (2 of which are dummy variables). However, when I try to run the below code I get the error message "B7 is not defined or is an illegal command".
I think I may be getting things very mixed up here!
Any help would be apprciated. Thanks
' declare parameter vector
coef (7) b2
coef (7) b3
coef (7) b4
coef (7) b5
coef (7) b6
coef (7) b7
mlogit.append xb2 = b2(1)+b2(2)*x1+b2(3)+b2(4)+b2(5)+b2(6)+b2(7)*x7
mlogit.append xb3 = b3(1)+b3(2)*x1+b3(3)+b3(4)+b3(5)+b3(6)+b3(7)*x7
mlogit.append xb4 = b4(1)+b4(2)*x1+b4(3)+b4(4)+b4(5)+b4(6)+b4(7)*x7
mlogit.append xb5 = b5(1)+b5(2)*x1+b5(3)+b5(4)+b5(5)+b5(6)+b5(7)*x7
mlogit.append xb6 = b6(1)+b6(2)*x1+b6(3)+b6(4)+b6(5)+b6(6)+b6(7)*x7
mlogit.append xb7 = b7(1)+b7(2)*x1+b7(3)+b7(4)+b7(5)+b7(6)+b7(7)*x7
' define prob for each choice
mlogit.append denom = 1+exp(xb2)+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
' specify likelihood
mlogit.append logl1 = (1-dd2-dd3-dd4-dd5-dd6)*log(pr1)+dd2*log(pr2)+dd3*log(pr3)+dd4*log(pr4) +dd5*log(pr5)+dd6*log(pr6)+dd7*log(pr7)
' specify analytic derivatives
for!i = 2 to 7
mlogit.append @deriv b{!i}(1) grad{!i}1 b{!i}(2) grad{!i}2 b{!i}(3) grad{!i}3 b{!i}(4) grad{!i}4 b{!i}(5) grad{!i}5 b{!i}(6) grad{!i}6 b{!i}(7) grad{!i}7
mlogit.append grad{!i}1 = dd{!i}-pr{!i}
mlogit.append grad{!i}2 = grad{!i}1*x1
mlogit.append grad{!i}3 = grad{!i}1*x2
mlogit.append grad{!i}4 = grad{!i}1*x3
mlogit.append grad{!i}5 = grad{!i}1*x4
mlogit.append grad{!i}6 = grad{!i}1*x5
mlogit.append grad{!i}7 = grad{!i}1*x6
next
' get starting values from binomial logit
equation eq2.binary(d=l) dd2 c x1 x2 x3 x4 x5 x6
b2 = eq2.@coefs
equation eq3.binary(d=l) dd3 c x1 x2 x3 x4 x5 x6
b3 = eq3.@coefs
equation eq4.binary(d=l) dd4 c x1 x2 x3 x4 x5 x6
b4 = eq4.@coefs
equation eq5.binary(d=l) dd5 c x1 x2 x3 x4 x5 x6
b5 = eq5.@coefs
equation eq6.binary(d=l) dd6 c x1 x2 x3 x4 x5 x6
b6 = eq6.@coefs
equation eq7.binary(d=l) dd7 c x1 x2 x3 x4 x5 x6
b7 = eq7.@coefs
I am trying to adapt the example MLR in the help guide but keep getting errors.
Basically, I will have 7 categories of dependant variable (1-7), and 5 regressors (2 of which are dummy variables). However, when I try to run the below code I get the error message "B7 is not defined or is an illegal command".
I think I may be getting things very mixed up here!
Any help would be apprciated. Thanks
' declare parameter vector
coef (7) b2
coef (7) b3
coef (7) b4
coef (7) b5
coef (7) b6
coef (7) b7
mlogit.append xb2 = b2(1)+b2(2)*x1+b2(3)+b2(4)+b2(5)+b2(6)+b2(7)*x7
mlogit.append xb3 = b3(1)+b3(2)*x1+b3(3)+b3(4)+b3(5)+b3(6)+b3(7)*x7
mlogit.append xb4 = b4(1)+b4(2)*x1+b4(3)+b4(4)+b4(5)+b4(6)+b4(7)*x7
mlogit.append xb5 = b5(1)+b5(2)*x1+b5(3)+b5(4)+b5(5)+b5(6)+b5(7)*x7
mlogit.append xb6 = b6(1)+b6(2)*x1+b6(3)+b6(4)+b6(5)+b6(6)+b6(7)*x7
mlogit.append xb7 = b7(1)+b7(2)*x1+b7(3)+b7(4)+b7(5)+b7(6)+b7(7)*x7
' define prob for each choice
mlogit.append denom = 1+exp(xb2)+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
' specify likelihood
mlogit.append logl1 = (1-dd2-dd3-dd4-dd5-dd6)*log(pr1)+dd2*log(pr2)+dd3*log(pr3)+dd4*log(pr4) +dd5*log(pr5)+dd6*log(pr6)+dd7*log(pr7)
' specify analytic derivatives
for!i = 2 to 7
mlogit.append @deriv b{!i}(1) grad{!i}1 b{!i}(2) grad{!i}2 b{!i}(3) grad{!i}3 b{!i}(4) grad{!i}4 b{!i}(5) grad{!i}5 b{!i}(6) grad{!i}6 b{!i}(7) grad{!i}7
mlogit.append grad{!i}1 = dd{!i}-pr{!i}
mlogit.append grad{!i}2 = grad{!i}1*x1
mlogit.append grad{!i}3 = grad{!i}1*x2
mlogit.append grad{!i}4 = grad{!i}1*x3
mlogit.append grad{!i}5 = grad{!i}1*x4
mlogit.append grad{!i}6 = grad{!i}1*x5
mlogit.append grad{!i}7 = grad{!i}1*x6
next
' get starting values from binomial logit
equation eq2.binary(d=l) dd2 c x1 x2 x3 x4 x5 x6
b2 = eq2.@coefs
equation eq3.binary(d=l) dd3 c x1 x2 x3 x4 x5 x6
b3 = eq3.@coefs
equation eq4.binary(d=l) dd4 c x1 x2 x3 x4 x5 x6
b4 = eq4.@coefs
equation eq5.binary(d=l) dd5 c x1 x2 x3 x4 x5 x6
b5 = eq5.@coefs
equation eq6.binary(d=l) dd6 c x1 x2 x3 x4 x5 x6
b6 = eq6.@coefs
equation eq7.binary(d=l) dd7 c x1 x2 x3 x4 x5 x6
b7 = eq7.@coefs
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Multinomial Logistic Regression (MLR)
The first obviously thing you've got wrong is that you've written:
When you should have:
Other than that, without seeing the rest of the program, it is hard to debug.
Code: Select all
coef (7) b2
Code: Select all
coef(7) b2
-
rohanarora78
- Posts: 1
- Joined: Sun Jul 17, 2011 12:30 pm
Re: Multinomial Logistic Regression (MLR)
hi,
i am doing a dissertation on " analysis of determinants of banking crisis " and my instructor told me to use logit model, i don`t know even the basic of it, he told me that put value =1 for crisis and 0 for no crisis and then study the data to predict the banking crisis by studying the past data, can anyone plzz help me on that ???
i am doing a dissertation on " analysis of determinants of banking crisis " and my instructor told me to use logit model, i don`t know even the basic of it, he told me that put value =1 for crisis and 0 for no crisis and then study the data to predict the banking crisis by studying the past data, can anyone plzz help me on that ???
-
startz
- Non-normality and collinearity are NOT problems!
- Posts: 3798
- Joined: Wed Sep 17, 2008 2:25 pm
Re: Multinomial Logistic Regression (MLR)
Most econometrics text books have a section on logit. The Wikipedia entry for "logistic regression" isn't bad either.
Re: Multinomial Logistic Regression (MLR)
Hello!!!
I am totally new on eviews (I am using eviews7) and I am working on MLR. However, i always get an error message stating that I have a "missing values in @LOGL series in the current coefficients..." I am using a panel data. is this message have a connection with the type of data I am using? how to modify the program in case i am using a panel work file??
Please please advise
I am totally new on eviews (I am using eviews7) and I am working on MLR. However, i always get an error message stating that I have a "missing values in @LOGL series in the current coefficients..." I am using a panel data. is this message have a connection with the type of data I am using? how to modify the program in case i am using a panel work file??
Please please advise
-
EViews Glenn
- EViews Developer
- Posts: 2682
- Joined: Wed Oct 15, 2008 9:17 am
Re: Multinomial Logistic Regression (MLR)
Probably your starting values. Look at the series specified in the @LOGL to see which observations are missing. Then trace back to see where the problems are in the series that are used to construct the @LOGL series.
A search of the forum for starting values should point to other useful tips.
A search of the forum for starting values should point to other useful tips.
Re: Multinomial Logistic Regression (MLR)
thank you so much for fast reply, however, I reviewed my data and I am still getting the same statement. I think there is a missing point I did not understand in the example on Eviews manual and example file concerning the definition of the dd2 and dd3. they post the dummies of d1, d2, and d3 why they did not use these dummies when estimating the @LOGL function and how they estimate the new dummies anyway?? sorry for these silly questions but this example is crucial for me to understand and base my work on it!!
many thanks.
many thanks.
-
EViews Glenn
- EViews Developer
- Posts: 2682
- Joined: Wed Oct 15, 2008 9:17 am
Re: Multinomial Logistic Regression (MLR)
The DD variables are the indicators for the dependent variable. Dummy variables, if you will for which of the multinomial responses is observed.
Re: Multinomial Logistic Regression (MLR)
I am still getting this error statement. May you please take a fast check on this codes. I still dont understand why I am always getting the error message concerning my estimations!! I will upload the WF.
thank you so much!!
load Onepanel
series dummy2 = @recode(emp2=1, 1, 0)
series dummy3 = @recode(emp3=2, 1, 0)
' declare parameter vector
coef(3) b2
coef(3) b3
coef(3) b4
coef(3) b5
coef(3) b6
coef(3) b7
coef(3) b8
coef(3) b9
' true values are
' b2(1) -0.4 b2(2) 1 b2(3) -0.2
' b3(1) -0.4 b3(2) 0.3 b3(3) 0.5
' setup the loglikelihood
logl Onepanel
Onepanel.append @logl logl1
' define index for each choice
Onepanel.append xb2 = b2(1)+b2(2)*dc+b2(3)*dcg +b2(4)*gdp+b2(5)*lvix +b2(6)*vix+b2(7)*ov +b2(8)*std_res+b2(9)*p_c
Onepanel.append xb3 =b3(1)+b3(2)*dc+b3(3)*dcg +b3(4)*gdp+b3(5)*lvix +b3(6)*vix+b3(7)*ov +b3(8)*std_res+b3(9)*p_c
' define prob for each choice
Onepanel.append denom = 1+exp(xb2)+exp(xb3)
Onepanel.append pr1 = 1/denom
Onepanel.append pr2 = exp(xb2)/denom
Onepanel.append pr3 = exp(xb3)/denom
' specify likelihood
Onepanel.append logl1 = (1-dummy2-dummy3)*log(pr1)+dummy2*log(pr2)+dummy3*log(pr3)
' specify analytic derivatives
for !i=2 to 3
Onepanel.append @deriv b{!i}(1) grad{!i}1 b{!i}(2) grad{!i}2 b{!i}(3) grad{!i}3
Onepanel.append grad{!i}1 = dummy{!i}-pr{!i}
Onepanel.append grad{!i}2 = grad{!i}1*gdp
Onepanel.append grad{!i}3 = grad{!i}1*lvix
Onepanel.append grad{!i}4 = grad{!i}1*vix
Onepanel.append grad{!i}5 = grad{!i}1*ov
Onepanel.append grad{!i}6 = grad{!i}1*std_res
Onepanel.append grad{!i}7 = grad{!i}1*p_c
Onepanel.append grad{!i}8 = grad{!i}1*cab
Onepanel.append grad{!i}9 = grad{!i}1*dc
Onepanel.append grad{!i}10 = grad{!i}1*dcg
next
' get starting values from binomial logit
equation eq2.binary(d=l) dummy2 c dc dcg gdp lvix vix ov std_res p_c
b2 = eq2.@coefs
equation eq3.binary(d=l) dummy3 c dc dcg gdp lvix vix ov std_res p_c
b3 = eq3.@coefs
' do MLE and display results
Onepanel.ml(showopts,m=3888, c=1e-5)
show Onepanel.output
thank you so much!!
load Onepanel
series dummy2 = @recode(emp2=1, 1, 0)
series dummy3 = @recode(emp3=2, 1, 0)
' declare parameter vector
coef(3) b2
coef(3) b3
coef(3) b4
coef(3) b5
coef(3) b6
coef(3) b7
coef(3) b8
coef(3) b9
' true values are
' b2(1) -0.4 b2(2) 1 b2(3) -0.2
' b3(1) -0.4 b3(2) 0.3 b3(3) 0.5
' setup the loglikelihood
logl Onepanel
Onepanel.append @logl logl1
' define index for each choice
Onepanel.append xb2 = b2(1)+b2(2)*dc+b2(3)*dcg +b2(4)*gdp+b2(5)*lvix +b2(6)*vix+b2(7)*ov +b2(8)*std_res+b2(9)*p_c
Onepanel.append xb3 =b3(1)+b3(2)*dc+b3(3)*dcg +b3(4)*gdp+b3(5)*lvix +b3(6)*vix+b3(7)*ov +b3(8)*std_res+b3(9)*p_c
' define prob for each choice
Onepanel.append denom = 1+exp(xb2)+exp(xb3)
Onepanel.append pr1 = 1/denom
Onepanel.append pr2 = exp(xb2)/denom
Onepanel.append pr3 = exp(xb3)/denom
' specify likelihood
Onepanel.append logl1 = (1-dummy2-dummy3)*log(pr1)+dummy2*log(pr2)+dummy3*log(pr3)
' specify analytic derivatives
for !i=2 to 3
Onepanel.append @deriv b{!i}(1) grad{!i}1 b{!i}(2) grad{!i}2 b{!i}(3) grad{!i}3
Onepanel.append grad{!i}1 = dummy{!i}-pr{!i}
Onepanel.append grad{!i}2 = grad{!i}1*gdp
Onepanel.append grad{!i}3 = grad{!i}1*lvix
Onepanel.append grad{!i}4 = grad{!i}1*vix
Onepanel.append grad{!i}5 = grad{!i}1*ov
Onepanel.append grad{!i}6 = grad{!i}1*std_res
Onepanel.append grad{!i}7 = grad{!i}1*p_c
Onepanel.append grad{!i}8 = grad{!i}1*cab
Onepanel.append grad{!i}9 = grad{!i}1*dc
Onepanel.append grad{!i}10 = grad{!i}1*dcg
next
' get starting values from binomial logit
equation eq2.binary(d=l) dummy2 c dc dcg gdp lvix vix ov std_res p_c
b2 = eq2.@coefs
equation eq3.binary(d=l) dummy3 c dc dcg gdp lvix vix ov std_res p_c
b3 = eq3.@coefs
' do MLE and display results
Onepanel.ml(showopts,m=3888, c=1e-5)
show Onepanel.output
Last edited by Nas1 on Sun Sep 09, 2012 4:04 pm, edited 3 times in total.
Re: Multinomial Logistic Regression (MLR)
please advice, is the panel data have any relation with the failed estimation? the betas are not estimated!!! Any help would be appreciated. Thanks
Last edited by Nas1 on Tue Sep 11, 2012 5:11 am, edited 1 time in total.
-
EViews Glenn
- EViews Developer
- Posts: 2682
- Joined: Wed Oct 15, 2008 9:17 am
Re: Multinomial Logistic Regression (MLR)
Here is the data; many thanks!!!
-
EViews Glenn
- EViews Developer
- Posts: 2682
- Joined: Wed Oct 15, 2008 9:17 am
Re: Multinomial Logistic Regression (MLR)
The series EMP2 does not exist. Neither does EMP3.
Re: Multinomial Logistic Regression (MLR)
I uploaded the wrong file, sorry for this mistake!!!Please recheck this attached file for the failed estimation.
Best regards,
Best regards,
Last edited by Nas1 on Fri Apr 08, 2016 6:05 am, edited 1 time in total.
Re: Multinomial Logistic Regression (MLR)
please advise!!!
Who is online
Users browsing this forum: No registered users and 1 guest
