Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Editing Marginsplot Labels

    Hi, I am pretty new to Stata and I am running a logistic regression.

    I have followed some code I found in several sources and I was able to make a plot of the marginal effects of my independent variables on the predicted probability of my dependent variable be 1.

    However, the plot labels for my independent variables are all messed up. Could someone help me please in setting this up? Bellow, I detail the case and attach the plot.

    I have 25 independent variables (predictors). All of them are statistically significant. I wrote the following code (variable names and plot titles are in Portuguese):

    logit NAO_DESISTENTE i.IN_AMOSTRA_ENEM i.PUBLICA i.IN_UNIVERSIDADE i.IN_LICENCIATURA i.IN_NOTURNO FEMININO ///
    c.IDADE_INGRESSO i.PROGRAMA i.ENG_CIV i.ENG_ELE i.ENG_MEC i.ENG_QUI i.ENG_PRO i.ENG_AMB i.ENG_FLO i.ENG_OUT i.ARQUIT i.BIOLOG i.QUIMIC ///
    i.MATEMA i.COMPUT i.TEC_INF i.TEC_IND, or

    margins, dydx(*) asobserved
    marginsplot, horizontal allxlabels recast(scatter) xline(0) title("Não desistência do curso, CTEM") xtitle("Efeito marginal sobre a probabilidade predita" "de não desistir do curso")


    I obtained a good chart with plots for all my 25 predictors. But the labels are too big, are not aligned with the corresponding dots and I only got labels for 4 predictors. How to make the labels for the 25 predictors fit in the chart?

    Click image for larger version

Name:	logit1.png
Views:	1
Size:	21.5 KB
ID:	1435206



    Thank you very much in advance,

    Luiz

  • #2
    marginsplot accepts most twoway_options, so you just need to add the ylabel option with the approprate suboptions to get what you want. Try this:

    Code:
    marginsplot, horizontal allxlabels recast(scatter) xline(0) title("Não desistência do curso, CTEM") xtitle("Efeito marginal sobre a probabilidade predita" "de não desistir do curso") ylabel(#25, labsize(small)) graphregion(col(white))
    Any good? Show us what you get

    Comment


    • #3
      Hi, Cris.
      Thank you very much for your help. Indeed, your code improved my chart. Now labels are aligned with the effects.

      However, for some reason, the correct labels just appear for the first effects (see below). All other labels are numbered in some logic that I cannot understand. Any tips on how to edit the labels?

      Click image for larger version

Name:	Capturar.PNG
Views:	1
Size:	24.7 KB
ID:	1435407


      Thank you once more!

      Comment


      • #4
        You can try manually writing them out? I haven't actually counted all the point estimates on your graph but before you write them all out try changing the #25 to #26 or #24 and see what happens.

        This is how you would write them out:

        Code:
        marginsplot, horizontal allxlabels recast(scatter) xline(0) title("Não desistência do curso, CTEM") xtitle("Efeito marginal sobre a probabilidade predita" "de não desistir do curso") ylabel(1 "First label" 2 "Second label" 3 "Third label", labsize(small)) graphregion(col(white))

        Comment

        Working...
        X