Announcement

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

  • How to make a graph of mean and standard deviation?

    Greetings. How can I make this graph of mean and standard deviation in stata? What would the command look like? Variable is "m2" and group is "town".
    Attached Files

  • #2
    Here is an example.
    Code:
    webuse grunfeld,clear
    collapse invest (sd) investsd=invest,by(company)
    gen y1=invest-investsd
    gen y2=invest+investsd
    twoway rcap y1 y2 company ||scatter invest company,scheme(538w)
    Attached Files
    Best regards.

    Raymond Zhang
    Stata 17.0,MP

    Comment


    • #3
      Thank you. A question. No need to install a package in the stata? Your quantitative variable is "invest" and your qualitative variable is "company"?

      Comment


      • #4
        yes,you need not install package. I just give you an example.company is quantity variable, if your group variable is qualitative variable,you can use encode command to make it to be quantity variable and then label the variable by your group variable town.
        Best regards.

        Raymond Zhang
        Stata 17.0,MP

        Comment


        • #5
          If you have the mean and sd, if if you can use - serrbar - command for that matter.
          Best regards,

          Marcos

          Comment


          • #6
            I'm updating this post. Here's a quick way to make the graph. https://www.youtube.com/watch?v=bphfs8lc77g

            Comment


            • #7
              The video in that link in #6 gives examples of graphs using ciplot -- without even explaining that you need to install it from SSC.

              In passing the speaker seems to confuse a 95% confidence interval for the mean with an interval including 95% of the data.-- and says that confidence interval plots are rarely used! I wouldn't myself use an example of the confidence interval for the mean population of the states of the US. That is not a question of social scientific interest, I suggest. We often stretch plausibility by treating batches of data as if they were random samples, but in that instance the stretch is a great deal.

              Also, the suggestion to use ciplot ignores the advice of its author, myself, that there are better ways to do it. That comment -- in the help -- was dated 2011, so this advice is not up-to-date. Specifically, often using statsby and then devising your own plot is a good strategy that obviates any need to install a new command.

              As a Stata program author, i put high value on commands remaining accessible -- and on recommending the best ways to do things.

              In this instance, cisets from SSC is another way to a much more general altternative. https://www.statalist.org/forums/for...-interval-sets says more.

              To summarize: ciplot isn't needed for simple problems, and not flexible enough for more challenging problems. That doesn't make it useless!

              Comment


              • #8
                The video is essentially an advert for an outfit that supports student assignments. As a teacher my own goal is that students get guidance and materials so that they can do their assignments themselves!

                Oh, and the video also refers to a by() option as a by command, which is quite different.

                The explanation that ciplot must be installed from SSC was given in a comment on the video.

                Comment


                • #9
                  As of Stata 19, the following can be used instead of the twoway command in #2:
                  Code:
                  twoway rpcap y1 y2 invest company

                  Comment


                  • #10
                    Further, the original request in #1 was not for confidence intervals as such, but for plots of mean +/- SD. or at least that was the interpretation in #2.

                    ciplot does not support such plots. but the method in #2 is one of several that could be used. Another that applies when you want mean and SD for groups is to use egen for the calculations of mean and SD and then graph as desired. That wouldn't involve a collapse.

                    Comment


                    • #11
                      Hemanshu Kumar Thanks for the reminder. Note that twoway rpcap does not do any calculations for you. That's emphatically not a criticism of the official command, as my own comments in #7 and #10 also imply that it is often practical to separate calculation of what you want shown from graphing what you want shown.

                      Comment


                      • #12
                        Thank you
                        Last edited by carlos viviano; 26 Sep 2025, 15:20.

                        Comment

                        Working...
                        X