Hello everyone,
I have a problem using marginsplot in a multinomial logit model.
I have already clustered electrical load curves to determine an optimal number of consumption groups. The optimal number of clusters is 3 and the affiliation of each household (household id = variable "i") to its cluster is indicated in the variable "c3" (if "c3" is equal to 1 I am in cluster 1 etc...).
Now I'd like to explain the composition of each cluster with data such as the type of heating used (variable "heat") or whether or not the household uses its own electricity (variable "auto").
To do this, I use a multinomial logit model with cluster membership as the explained variable and the type of heating and self-consumption as the explanatory variables. These two variables are categorical. The type of heating has three possible values, self-consumption is binary.
As shown in the code below, I use version 18 of Stata, the "mlogit" command. Then I use the "margins" command to find the marginal effect. Then I use "marginsplot" to plot all this.
For the "heat" variable, there's no problem (see graph below), the graph looks OK to me.
However, for the binary variable "auto", the graph does not come out correctly (see graph below). The value of the coefficients is correct and corresponds to the results of the multinomial model, but the points should all be in the same place on the X axis, i.e. at the level of " Auto consumption ". The legend also seems to indicate that Stata hasn't understood what I want to do (or that I've done it wrong ;-))
The same phenomenon appears with other variables: everything is OK for variables with more than 2 possibilities but with binary variables it gives the same result.
Would anyone be able to help me? Despite my research, I haven't found a question on precisely the same subject.
Thank you in advance for your help.
Valentin


Code:
Sample of the Data:
I have a problem using marginsplot in a multinomial logit model.
I have already clustered electrical load curves to determine an optimal number of consumption groups. The optimal number of clusters is 3 and the affiliation of each household (household id = variable "i") to its cluster is indicated in the variable "c3" (if "c3" is equal to 1 I am in cluster 1 etc...).
Now I'd like to explain the composition of each cluster with data such as the type of heating used (variable "heat") or whether or not the household uses its own electricity (variable "auto").
To do this, I use a multinomial logit model with cluster membership as the explained variable and the type of heating and self-consumption as the explanatory variables. These two variables are categorical. The type of heating has three possible values, self-consumption is binary.
As shown in the code below, I use version 18 of Stata, the "mlogit" command. Then I use the "margins" command to find the marginal effect. Then I use "marginsplot" to plot all this.
For the "heat" variable, there's no problem (see graph below), the graph looks OK to me.
However, for the binary variable "auto", the graph does not come out correctly (see graph below). The value of the coefficients is correct and corresponds to the results of the multinomial model, but the points should all be in the same place on the X axis, i.e. at the level of " Auto consumption ". The legend also seems to indicate that Stata hasn't understood what I want to do (or that I've done it wrong ;-))
The same phenomenon appears with other variables: everything is OK for variables with more than 2 possibilities but with binary variables it gives the same result.
Would anyone be able to help me? Despite my research, I haven't found a question on precisely the same subject.
Thank you in advance for your help.
Valentin
Code:
Code:
mlogit c3 i.type_object i.heat i.auto i.unique i.mix i.npa, baseoutcome(1) estimates store mymodel estimates table mymodel local SD type_object heat auto unique mix npa foreach var of local SD { levelsof `var', local(labs) local xlabs "" local i = 0 foreach l of local labs { local ++i local lab: label (`var') `l' local xlabs `" `xlabs' `i' "`lab'" "' } margins, dydx(`var') atmeans marginsplot, name(dydx_`var', replace) yline(0) title("Average marginal effect of "`var'" with 95% CIs") legend(on order(1 "Cluster 1" 2 "Cluster 2" 3 "Cluster 3")) xlabel(`xlabs') recast(scatter) *graph export ".\figures\mlogit\average_marginal_effect\ame_`var'.png", replace }
Sample of the Data:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input double i byte(c2 c3 c4 type_object heat auto renew) int tariff float npa str72 description float(unique mix) byte _est_mymodel 13101000 2 2 3 6 1 0 0 50 2333 "APPART POUR PERSONNEL ET ENTREPOT " 1 1 1 13101200 1 1 1 6 1 0 0 50 2333 "1ER ETAGE " 1 1 1 13101210 1 1 4 6 1 0 0 50 2333 "REZ-DE-CHAUSSEE " 1 1 1 13101410 2 2 3 6 1 0 0 52 2333 "APPART REZ-DE-CHAUSSEE " 0 1 1 13101610 1 1 4 6 1 0 0 50 2333 "REZ-DE-CHAUSSEE " 1 1 1 13102000 2 2 3 1 1 0 0 50 2333 "ANCIEN BUFFET DE GARE " 1 1 1 13102610 2 2 3 6 1 0 0 50 2333 "DEPENDANCES + REZ +1ER ET 2EME ETAGE " 1 1 1 13102800 2 2 3 6 1 0 0 50 2333 "1ER ETAGE " 1 1 1 13103210 2 2 3 3 2 0 0 50 2333 "APPART " 1 1 1 13103400 1 1 4 1 1 0 0 50 2333 "IMMEUBLE " 1 1 1 13103600 2 2 3 1 1 0 0 50 2333 "CURE " 1 1 1 13103800 2 2 2 1 1 0 0 50 2333 " " 1 1 1 13104000 2 1 1 6 1 0 0 50 2333 "1ER ETAGE OUEST " 1 1 1 13104010 1 1 1 6 1 0 0 50 2333 "2EME ETAGE OUEST " 1 1 1 13104020 1 1 1 6 1 0 0 50 2333 "1ER ETAGE EST " 1 1 1 13104030 1 1 1 6 1 0 0 50 2333 "2EME ETAGE EST " 1 1 1 13104040 2 3 2 6 1 0 0 50 2333 "REZ-DE-CHAUSSEE EST " 1 1 1 13104050 2 2 3 6 1 0 0 50 2333 "REZ-DE-CHAUSSEE OUEST " 1 1 1 13104060 1 1 1 6 1 0 0 50 2333 "3EME ETAGE OUEST " 1 1 1 13104610 1 1 1 1 1 0 0 50 2333 "MAISON FAMILIALE " 1 1 1 13104620 1 1 1 1 1 0 0 50 2333 "MAISON FAMILIALE " 1 1 1 13104630 2 2 3 1 1 0 0 50 2333 "MAISON FAMILIALE / L'OREADE " 1 1 1 13104660 2 2 3 1 1 0 0 50 2333 "MAISON FAMILIALE " 1 1 1 13104670 2 2 3 1 1 0 0 50 2333 "MAISON FAMILIALE " 1 1 1 13105000 1 1 1 6 1 0 0 50 2333 "2EME ETAGE EST " 1 1 1 13105010 2 2 3 6 1 0 0 50 2333 "1ER ETAGE EST " 1 1 1 13105050 2 1 1 6 1 0 0 50 2333 "2EME ETAGE OUEST " 1 1 1 13105070 1 1 4 6 1 0 0 50 2333 "3EME ETAGE " 1 1 1 13105100 2 2 3 6 1 0 0 50 2333 "DUPLEX OUEST " 1 1 1 13105110 2 2 3 3 1 0 0 50 2333 "STUDIO REZ INFERIEUR EST " 1 1 1 13105200 2 2 3 1 1 0 0 50 2333 "IMMEUBLE " 1 1 1 13105400 1 1 4 1 1 0 0 50 2333 "IMMEUBLE " 1 1 1 13105600 1 3 4 3 1 0 0 50 2333 "IMMEUBLE " 1 1 1 13105610 2 3 4 3 1 0 0 50 2333 "SOUS-SOL ET BUREAU " 1 1 1 13105800 2 2 3 1 1 0 0 50 2333 "IMMEUBLE " 1 1 1 13106200 1 3 4 3 1 0 0 50 2333 "IMMEUBLE " 1 1 1 13106400 2 2 2 1 1 0 0 50 2333 "IMMEUBLE " 1 1 1 13106600 2 2 2 1 1 0 0 50 2333 "LE CHALET " 1 1 1 13107000 2 2 3 1 1 0 0 50 2333 "MAISON FAMILIALE " 1 1 1 13107200 2 2 3 1 1 0 0 50 2333 "MAISON FAMILIALE " 1 1 1 13107500 2 2 3 1 1 0 0 50 2333 "MAISON FAMILIALE " 1 1 1 13107550 2 2 3 1 1 0 0 60 2333 "MAISON FAMILIALE " 1 2 1 13107600 2 2 3 1 1 0 0 50 2333 "MAISON FAMILIALE " 1 1 1 13107800 2 2 3 1 1 0 0 50 2333 "MAISON FAMILIALE " 1 1 1 13108000 2 2 3 1 1 0 0 52 2333 "MAISON FAMILIALE " 0 1 1 13108600 2 3 4 1 1 0 0 50 2333 "MAISON FAMILIALE " 1 1 1 13108710 2 2 3 1 4 0 0 50 2333 "MAISON FAMILIALE " 1 1 1 13108715 2 2 3 1 4 0 0 50 2333 "MAISON FAMILIALE " 1 1 1 13108720 2 2 3 1 4 0 0 52 2333 "MAISON - POMPE A CHALEUR " 0 1 1 13108735 2 2 3 1 4 0 0 50 2333 "MAISON FAMILIALE + PAC " 1 1 1 13108740 2 2 3 1 1 2 1 43 2333 "MAISON FAMILIALE + SOLAIRE " 1 1 1 13108745 2 2 3 1 4 0 0 50 2333 "HABITATION + PAC " 1 1 1 13108750 2 2 3 1 4 0 0 50 2333 "HABITATION + PAC " 1 1 1 13108800 2 3 3 1 4 0 0 50 2333 "MAISON FAMILIALE " 1 1 1 13108830 2 2 3 1 4 0 0 50 2333 "MAISON FAMILIALE " 1 1 1 13108840 2 3 4 1 1 0 0 50 2333 "MAISON FAMILIALE " 1 1 1 13108850 2 2 3 1 4 0 0 50 2333 "MAISON FAMILIALE + PAC " 1 1 1 13108870 2 2 3 1 1 2 1 43 2333 "MAISON FAMILIALE ET SOLAIRE RU " 1 1 1 13108950 2 2 3 1 4 0 0 50 2333 "MAISON FAMILIALE + POMPE A CHALEUR " 1 1 1 13108970 2 2 3 1 1 0 0 61 2333 "MAISON FAMILIALE " 1 3 1 13109300 2 2 3 1 4 0 0 50 2333 "MAISON FAMILIALE " 1 1 1 13109400 2 2 3 1 1 0 0 50 2333 "MAISON FAMILIALE " 1 1 1 13109600 1 3 4 1 1 0 0 50 2333 "MAISON FAMILIALE " 1 1 1 13109700 2 2 3 1 1 0 0 50 2333 "MAISON FAMILIALE " 1 1 1 13110600 2 2 3 6 1 0 0 50 2333 "1ER ETAGE " 1 1 1 13110610 2 3 2 6 1 0 0 50 2333 "REZ-DE-CHAUSSEE " 1 1 1 13110800 1 1 1 6 1 0 0 50 2333 "REZ-DE-CHAUSSEE " 1 1 1 13110820 1 3 4 6 1 0 0 61 2333 "1ER ETAGE " 1 3 1 13111000 2 2 3 6 1 0 0 50 2333 "2EME ETAGE " 1 1 1 13111800 2 2 3 1 1 0 0 50 2333 "APPART OUEST " 1 1 1 13111810 2 2 3 6 1 0 0 50 2333 "APPART EST " 1 1 1 13112200 1 1 1 6 1 0 0 50 2333 "3EME ETAGE " 1 1 1 13112210 1 3 2 6 1 0 0 50 2333 "2EME ETAGE " 1 1 1 13112220 2 2 3 6 1 0 0 50 2333 "1ER ETAGE " 1 1 1 13112230 1 1 1 6 1 0 0 50 2333 "REZ-DE-CHAUSSEE " 1 1 1 13112410 1 1 1 6 1 0 0 50 2333 "1ER ETAGE " 1 1 1 13112610 1 1 3 6 1 0 0 50 2333 "2EME ETAGE " 1 1 1 13112620 1 3 4 6 1 0 0 50 2333 "1ER ETAGE " 1 1 1 13115000 1 3 2 3 1 0 0 50 2333 "APPART " 1 1 1 13115010 1 1 1 3 1 0 0 50 2333 "STUDIO OUEST " 1 1 1 13115300 1 2 4 1 1 0 0 50 2333 "MAISON " 1 1 1 13115510 1 3 2 3 1 0 0 50 2333 "APPART " 1 1 1 13115600 2 2 3 6 1 0 0 50 2333 "APPART 1ER OUEST " 1 1 1 13115610 1 1 1 6 1 0 0 50 2333 "APPART REZ EST " 1 1 1 13115630 1 1 1 3 1 0 0 50 2333 "REZ-DE-CHAUSSE OUEST " 1 1 1 13115640 1 1 1 3 1 0 0 50 2333 "APPART 1ER EST " 1 1 1 13115650 2 2 3 3 1 0 0 50 2333 "DEPENDANCES " 1 1 1 13116000 1 3 4 1 1 0 0 50 2333 "MAISON " 1 1 1 13116100 2 2 3 1 1 0 0 50 2333 " " 1 1 1 13118500 1 3 4 6 1 0 0 50 2333 "REZ-DE-CHAUSSEE " 1 1 1 13118520 1 1 1 6 1 0 0 50 2333 "1ER ETAGE " 1 1 1 13118530 1 1 1 6 1 0 0 50 2333 "2EME ETAGE " 1 1 1 13120110 2 2 3 6 1 0 0 50 2333 "REZ-DE-CHAUSSEE " 1 1 1 13120120 2 2 3 6 1 0 0 50 2333 "1ER ETAGE " 1 1 1 13120130 2 2 3 6 1 0 0 50 2333 "2EME ETAGE " 1 1 1 13120140 2 2 3 6 1 0 0 50 2333 "3EME ETAGE " 1 1 1 13120150 2 2 3 6 1 0 0 50 2333 "4EME ETAGE " 1 1 1 13120200 1 1 1 6 1 0 0 50 2333 "REZ-DE-CHAUSSEE " 1 1 1 13120240 2 1 1 6 1 0 0 50 2333 "3EME ETAGE " 1 1 1 13120250 1 1 1 6 1 0 0 50 2333 "4EME ETAGE " 1 1 1 end label values type_object id_type_objetlab label def id_type_objetlab 1 "Maison familiale", modify label def id_type_objetlab 3 " App. maison", modify label def id_type_objetlab 6 "App. locatif", modify label values heat heat_lab label def heat_lab 1 "Autres", modify label def heat_lab 2 "Accumulation", modify label def heat_lab 4 "Pompe à chaleur", modify label values auto auto_lab label def auto_lab 0 "Consommation", modify label def auto_lab 2 "Autoconsommation", modify label values renew ren_lab label def ren_lab 0 "Aucun", modify label def ren_lab 1 "Solaire", modify label values tariff id_tarif_energie_lab label def id_tarif_energie_lab 43 "Unique auto BLUE", modify label def id_tarif_energie_lab 50 "Unique BLUE", modify label def id_tarif_energie_lab 52 "Double BLUE", modify label def id_tarif_energie_lab 60 "Unique GREEN", modify label def id_tarif_energie_lab 61 "Unique Grey", modify label values unique unique_lab label def unique_lab 0 "Double", modify label def unique_lab 1 "Unique", modify label values mix mix_lab label def mix_lab 1 "Blue", modify label def mix_lab 2 "Green", modify label def mix_lab 3 "Grey", modify
Comment