Announcement

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

  • Marginsplot

    Hello,

    I have a quick question on the command "marginsplot"

    I have the following codes:

    regress y x z c.x#c.z

    sum z
    return list
    global effa = round(r(mean) + r(sd),0.1)
    global eff = round(r(mean),0.1)
    global effb = round(r(mean) - r(sd),0.1)

    margins, at(x = 0(0.1)1) z = ($effa, $eff $effb))
    marginsplot

    All codes work fine until when i run marginsplot

    I get the following error message: ") required" r(100);

    My understanding per https://stats.idre.ucla.edu/stata/se...ions-stata/#s3 is that i can run margins command and then immediately follow up with marginsplot for a graph. However, i get a random error of ") required" - i was wondering if anyone had this issue and if so, how did you solve this?


    Thank you
    Last edited by Dave Baik; 11 Nov 2021, 14:03.

  • #2
    Are you sure you are getting the error message from -marginsplot- and not -margins-? Your -at- option has unbalanced parentheses.

    Comment


    • #3
      Hi Clyde,
      Thank you for your reply!
      My apologies for the typo in the margins line above.

      I have run the following codes:

      margins, at(x = (0(0.1)1) z = ($effa, $eff $effb))
      marginsplot

      I have no issue getting the output from the margins command, but the ") required " error message pops up after the marginsplot command.
      Last edited by Dave Baik; 11 Nov 2021, 14:12.

      Comment


      • #4
        Sorry for the back to back posting - the above error message is followed by r(100) as well.

        Comment


        • #5
          I have never encountered this and I have not been able to concoct an example that produces this problem. Can you please post back with example data and code using that data which reproduces this problem and I'll try to troubleshoot.

          We all make typos, and they don't need apologies. But when you are posting code requesting troubleshooting, you shouldn't be typing that code in the first place. It should be copied to your clipboard from your do file, Results window, or log file and then pasted here into the Forum between code delimiters. (Please see Forum FAQ #12 if you are not familiar with code delmiters.) That's because there are no unimportant details in code. Any single character could make a major difference. So it is crucial that the code you show be exactly what was run--and the only way to assure that is by copy/paste. Otherwise you just waste your own time and that of those who try to help you.

          When posting back with example data, be sure to use the -dataex- command to do that. If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data. When asking for help with code, always show example data. When showing example data, always use -dataex-.

          Comment


          • #6
            Hi Clyde, thank you once again for your reply.
            I have tried to copy sample data using -dataex. I hope the following sample data is what you were expecting to see in terms of format

            X(Double) Z(Float) Y (Float)

            27 .15829344 .09439725
            25 .16189472 .0911274
            41 .15892962 .06356584
            57 .15099585 .08042134
            62 .1483468 .0648372
            60 .081534214 .06392438
            62 .091914371 .06483292
            50 .18314214 -.005676568
            48 .16058032 .04583593
            71 .17820784 .05132638
            61 .17563593 .05640454
            74 .16867305 .07296336
            12 .13158658 .05706029
            17 .13437301 .0473191
            25 .11873307 .013620125
            64 .12529568 -.004286718
            23 .090631969 .03601554
            33 .088861816 -.00111269

            I run the following codes:
            Code:
            regress Y  c.X##c.Z
            
            sum X
            return list
            global effa = round(r(mean) + r(sd),0.1)
            global eff = round(r(mean),0.1)
            global effb = round(r(mean) - r(sd),0.1)
            
            margins, at(X=(0(0.1)1) Z=($effa $eff $effb))
            marginsplot

            Thank you,
            Last edited by Dave Baik; 11 Nov 2021, 14:37.

            Comment


            • #7
              Thank you. The data listing you show is not quite what I was expecting. It was usable in other ways, but here's what it should have been:
              Code:
              * Example generated by -dataex-. For more info, type help dataex
              clear
              input double X float(Y Z)
              27 .15829344   .09439725
              25 .16189472    .0911274
              41  .1589296   .06356584
              57 .15099585   .08042134
              62  .1483468    .0648372
              60 .08153421   .06392438
              62 .09191437   .06483292
              50 .18314214 -.005676568
              48  .1605803   .04583593
              71 .17820784   .05132638
              61 .17563593   .05640454
              74 .16867305   .07296336
              12 .13158658   .05706029
              17 .13437301    .0473191
              25 .11873307  .013620125
              64 .12529568 -.004286718
              23 .09063197   .03601554
              33 .08886182  -.00111269
              end
              I ran this -dataex- and followed it with your code. It gives no error messages, and produces a reasonable looking plot after -marginsplot-. In short, I can't reproduce the problem.

              Here are some thoughts that sometimes resolve this kind of problem:

              1. Do a full update of your Stata installation. (-update all, force-). If your system does not give you permission to do this, ask your IT specialist to do it for you.
              2. Do a cold reboot of your computer.

              Try again and see if that does the trick.

              There is another unlikely and obscure possibility, but one that is very hard to track down--I mention it because it's one of my pet peeves and because I once got burned by this myself and it took me days to unravel the mystery. The use of global macros is an inherently unsafe programming practice, and they should only be used in the very rare circumstance where there is no alternative for doing what needs to be done. The reason is that if there is any other program running in the environment that also has a global macro with the same name as one of yours, that program could covertly be changing the value of some of those global macros without your knowing it, and perhaps changing one of them to something that introduces an unbalanced ( into the code after the macro substitutions are done. Now, your code does not look like it really provides an opportunity to do that: the global macros are used immediately after they are defined--there are no intervening commands that might invoke a program that does this. So I don't think this is what's wrong here. Nevertheless, it would improve your code to change those globals to local macros.

              Comment


              • #8
                Thank you Clyde - I will reinstall STATA and try again!
                I appreciate your time!

                Comment

                Working...
                X