Announcement

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

  • Help with combomarginsplot

    Dear Statalisters

    Following multilevel logistic regression, I want to create a plot of predicted margins of the outcome (mmdied) for three different age cohorts on the same chart. The age ranges do not overlap (they are: 20-35; 40-55; 60-75) and I'd like the plot to have separate lines for each. When I use combomarginsplot, it plots age and predictions but joins up the three age lines. Is there anyway to instruct it not to do this? When the age ranges do overlap the combomarginsplot does produce three separate lines and does not attempt to join them. I am using Stata 13, syntax as follows:

    melogit mmdied i.cohort mm1 sex##c.age1##c.age1##c.age1 || origpc: || idno:, or
    margins if cohort==1, at (age1=(60(1)75)) predict(mu fixedonly) vsquish ///
    saving(null_1930, replace)
    melogit mmdied i.cohort mm1 sex##c.age1##c.age1##c.age1 || origpc: || idno:, or
    margins if cohort==2, at (age1=(40(1)55)) predict(mu fixedonly) vsquish ///
    saving(null_1950, replace)
    melogit mmdied i.cohort mm1 sex##c.age1##c.age1##c.age1 || origpc: || idno:, or
    margins if cohort==3, at (age1=(20(1)35)) predict(mu fixedonly) vsquish ///
    saving(null_1970, replace)
    combomarginsplot null_1970 null_1950 null_1930, labels ("1970s" "1950s" "1930s") noci ///

  • #2
    Welcome to Statalist!

    Since the combomarginsplot command is a user-submitted command from the Stata Journal, rather than a part of the official Stata distribution, perhaps the author will be willing to advise you if you write to him at the address given in the output of help combomarginsplot.

    I suggest this because I can imagine that your problem may in fact be considered a useful feature by others and thus be part of the program design, or else is a result of the techniques used to combine the separate graphs.

    For future reference, the Statalist FAQ linked to from the top of each page, and from the Advice on Posting link in the instructions that appear when creating a new topic, has advice about submitting problems to Statalist. It recommends identifying the source of user-written commands and providing reproducible examples using, perhaps, one of the datasets included in the Stata distribution. In this case, it seems likely that the problem could be reproduced combining margins commands after two simple logit regressions. Providing a reproducible example increases the likelihood that someone, perhaps not familiar with combomarginsplot but having experience with the underlying graphics commands, will attempt to find underlying options that resolve your issue.

    But in this case, I think contacting the author is a good first step.

    Comment


    • #3
      You can get this to work, in this case at least, with margin's plotdim() option with the variable that defines the different files. This tells marginsplot to create a separate plot for each value of file variable; i.e., for each file. Here's an example using the auto dataset:

      Code:
      clear *
      sysuse auto
      recode rep78 (1/3=1) (4=2) (5=3), gen(rep2)
      ta rep2
      logit foreign i.rep2 c.mpg##c.mpg##c.mpg
      
      margins if rep2==1, at(mpg==(10/15)) saving(f1, replace)
      margins if rep2==2, at(mpg==(20/25)) saving(f2, replace)
      margins if rep2==3, at(mpg==(30/35)) saving(f3, replace)
      
      combomarginsplot f1 f2 f3 , noci name(bad, replace)
      
      combomarginsplot f3 f2 f1 , noci plotdim(_filenumber) ///
           label("First" "Second" "Third") name(fixed, replace)

      Comment


      • #4
        combomarginsplot is from SSC, not the Stata Journal.

        Comment


        • #5
          This worked perfectly; thank you.

          Comment


          • #6
            Can we edit the positioning of legends and edit labels of legends using combomarginsplot?
            Right now, I can do just one with a code not both, either editing the label or changing the positon of the label not both. The following code gives an error "option labels() not allowed"

            combomarginsplot file1 file2 file3, legend(pos(3) col(1) labels("Satisfaction" "Assertiveness" "Decision Making"))

            Comment


            • #7
              I don't think "labels()" is a valid suboption for legend(). I get that error in this example as well:

              Code:
              sysuse auto
              scatter mpg price weight, legend(labels("first" "second"))
              Perhaps more helpfully, if you are trying to change the legending, I you will be happier doing it indirectly. If those labels refer to the contenst of the three margins files, then you want the labels() option not as a sub-option of legend():

              Code:
              combomarginsplot file1 file2 file3, legend(pos(3) col(1)) labels("Satisfaction" "Assertiveness" "Decision Making")
              If they are labelling something else, you can change the relevant variable label upstream.

              Comment


              • #8
                I am trying to use -combomarginsplot- in combination with -mimrgns-. I keep getting an error on the saving() option before I even get to the -combomarginsplot- command line.

                My code is as follows:
                Code:
                mi estimate: svy: logit perform i.race edu sex age
                mimrgns i.race, predict(pr) saving(file1, replace)

                However, I get an error message with says:
                option saving() not allowed
                r(198)

                Are my parentheses wrong? Do I need the -at- option? The x variable that I am using to plot is categorical and works fine without the saving option, so I am not clear on where the syntax mistake is. Simple but haven't been able to correct. I saw in another forum where the saving option is undocumented so that may be where I am going wrong.

                Comment


                • #9
                  neither margins (upon which mimrgns is built) nor mimrgns have a saving option - that is why you get the message - is there some reason you need to save at that point? after all, what mimrgns is doing is adding a new variable to your data set so you can always save afterwards

                  Comment


                  • #10
                    I am trying to create a marginsplot that combines three different plots. I installed the -combomarginsplot- package. The code in the help file is as follows:
                    Code:
                    sysuse auto
                    oprobit rep78 i.foreign mpg price weight
                    margins foreign, at(mpg=(10(5)50)) predict(outcome(3)) saving(file1, replace)
                    oprobit rep78 i.foreign mpg
                    margins foreign, at(mpg=(10(5)50)) predict(outcome(3)) saving(file2, replace)
                    oprobit rep78 i.foreign mpg gear
                    margins foreign, at(mpg=(10(5)50)) predict(outcome(3)) saving(file3, replace)
                    combomarginsplot file1 file2 file3, labels("Full model" "Restricted model" "Gear Model") noci

                    Comment


                    • #11
                      Originally posted by Rich Goldstein View Post
                      neither margins (upon which mimrgns is built) nor mimrgns have a saving option - that is why you get the message - is there some reason you need to save at that point? after all, what mimrgns is doing is adding a new variable to your data set so you can always save afterwards
                      Thank you. Any idea regarding a workaround?

                      Comment


                      • #12
                        try the "post" option - start with
                        Code:
                        help margins

                        Comment

                        Working...
                        X