Announcement

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

  • Marginsplot after LCP - how to edit the main title, delete text information and include asyvars

    Dear Forum members,

    This is an example, based on data from the Stata Manual (concerning Latent Class, actually Latent Profile), but the actual data gives similar results:

    Code:
    use http://www.stata-press.com/data/r15/gsem_lca2
    gsem (glucose insulin sspg <- _cons), lclass(C 2)
    estat lcmean, post
    margins, dydx(*) noesample predict(outcome(1)) predict(outcome(2))
    marginsplot, by(_outcome)
    After the commands above, we get this graph:
    Click image for larger version

Name:	Graph_LCP.png
Views:	1
Size:	33.5 KB
ID:	1419754










    The problem is: I wish to exclude the message "Effects with Respect to". Also, I wish to edit the main title.

    If we use the graph editor, the main title "Average Marginal Effects" is classified as "title" and the message "Effects with Respect to" is classified as "bottom 1".

    However, if I try to edit the main title, I only get the "by" titles instead:

    Code:
    marginsplot, by(_outcome) title("This is not the main title")
    Click image for larger version

Name:	Graph_LCP2.png
Views:	1
Size:	36.3 KB
ID:	1419755









    With regards to the message "Effect with respect to", neither "note" nor "caption" would do the trick.

    The same situation happens if I recast the graph:


    Code:
    marginsplot, by(_outcome) title("This is not the main title") recast(bar)
    Click image for larger version

Name:	Graph_LCP3.png
Views:	1
Size:	32.2 KB
ID:	1419756










    This is my last difficulty with regards to the analysis, since I cannot get different colors for the bars when I use - asyvar - option:

    Code:
     marginsplot, by(_outcome) title("This is not the main title") recast(bar) asyvars
    
      Variables that uniquely identify margins: _deriv _outcome
    option asyvars not allowed
    r(198);
    I know I can do it by using the point-and-click graphic operations, but I wonder whether there is a more elegant solution.


    Thank you very much in advance.

    Edited to correct title: LPA (latent profile analysis) instead of "LCP".
    Last edited by Marcos Almeida; 27 Nov 2017, 04:31.
    Best regards,

    Marcos

  • #2
    Hi Marcos, with regards to the titling, this should do the trick

    Code:
     marginsplot, by(_outcome) xtitle("")

    Comment


    • #3
      Hi Andrew,

      Thank you very much for the reply. Good news: the option xtitle(") took away the unwelcome message "Effect with Respect to". Bad news: the option ytittle change the titile for the Y axis, instead of the main title.


      All in all, thanks to you, the message ("Effect with Respect to") can now be deleted.


      For now, I still wonder how to:

      Edit the main title ("Average Marginal Effecs")

      Apply the option - asyvars - after the command marginsplot recast (I'm starting to suspect it may not be possible).


      Best regards,

      Marcos

      Comment


      • #4
        A bit piecemeal today. For the main title

        Code:
          marginsplot, by(_outcome) byopts(title("This is not the main title")) xtitle("")
        In case no one else does, I will get back to you on the 3rd point if I can.

        Comment


        • #5
          Here is the promised reply:

          asyvars is an option in graph bar, over() and therefore will not work in marginsplot. However, what we are interested in is replicating the behavior. In my opinion, this is not directly possible in marginsplot, by() because by() treats the combined graph as a single plot, and therefore you cannot affect the rendition of a specific subgraph by specifying plot#opt(). Nevertheless, with a little bit of effort, you can get your desired result either by

          1) twice using marginsplot,gr() and saving selected graphs, thereafter combining these using graph combine (here you can specify one color in the by category for one graph and a different color for the other), or

          2) saving the margins output and plotting using twoway (here you can specify different colors for the individual bars).

          The following links may be useful to this end

          https://www.statalist.org/forums/for...in-marginsplot
          https://www.statalist.org/forums/for...nsplot-example

          Last edited by Andrew Musau; 27 Nov 2017, 10:35.

          Comment


          • #6
            Andrew Musau Thank you so much. The command in #4 worked like a charm.

            As I suspected in #3, the use of - recast(bar) - under - marginsplot - command - is something different from, say, - graph bar - command, as you clearly detailed in #5.

            Also, thank you for the links with commands so as to trick margins into a asyvars-like graph. Anyway, my third wish was more a curiosity rather than something crucial to my work. Actually, I believe that changing the bar color (so as to get more contrast with the rcap) did the desired effect.

            All in all, issue solved. I appreciated your help very much!
            Best regards,

            Marcos

            Comment

            Working...
            X