Announcement

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

  • How to get data from a Stata graph?

    In my analysis I've used a command that produces a graph at the end of it but it doesn't produce make the data used for the graph available.

    If I've got saved Stata graphs, is there anyway to get the data from these graphs so that I could recreate the graph in something like Excel for example?

  • #2
    May you share exactly what commands you've run to make that graph? There may be much easier ways than messing around with Stata's hidden graph datasets.

    Comment


    • #3
      see -help serset-
      Code:
      tw fun 1
      graph save fun1, replace
      graph drop _all
      
      graph use fun1
      graph describe
      
      serset dir
      serset set 0 
      serset use , clear
      
      list in 1/5
      list in -5/-1

      Comment


      • #4
        I agree with Leonardo Guizzetti

        There are two situations:

        1. The "data" shown by the graph are those you give. Standard example; scatter plot.

        2. Stata does some calculations with your data before producing a graph. Standard example: histogram.

        Even if you're in class 2, which is why you're asking, there is usually a way to get the results otherwise.

        Comment


        • #5
          Originally posted by Leonardo Guizzetti View Post
          May you share exactly what commands you've run to make that graph? There may be much easier ways than messing around with Stata's hidden graph datasets.
          The command used to create the charts is the user written command
          Code:
          synth_runner
          which is a variant on
          Code:
          synth
          by Abadie, Diamond, and Hainmueller(2010) which allows for multiple treated units. Once the command is run, you can use the command
          Code:
          effect_graphs
          to generate the canonical synthetic control chart, as well as the gap between the treated and synthetic counterfactual.

          Issue is, I really don't like the way Stata graphs look (I know you can edit them but still...) and neither does my thesis supervisor. So I was planning on running the models, getting the graphs and then trying to export the data from the graphs to excel, but I'm unsure how to.

          Comment


          • #6
            I'm not familiar with these commands, so cannot comment of there is a more direct approach on this problem. The other way forward is to follow Bjarte's advice and load the -serset- and define your own graph using that dataset.

            Comment


            • #7
              Hey so I'm pretty much one of the maybe 3 people on here who have intimate knowledge of synth. My recommendation to you is to NOT use synth_runner, for the love of God don't use it.

              It's syntax is clunky and it's just generally difficult to use. So, here's my advice to you. Use the allsynth command (ssc inst allsynth). It automates the construction of multiple SC units, and gives you a ridculous amount of control over graphics (it's a MONSTER of a command).

              So abandon synth_runner. allsynth is your friend. Or, if you're willing to be really fancy, use my scul command for this (ssc inst scul). Jenner Kerr

              note that mine still has some bugs I have to fix (I'm in Puerto Rico and not at my computer till Tuesday), but mine will (likely) work or allsynth​​​​​​​.

              Comment


              • #8
                I really don't like the way Stata graphs look
                Will simply using some alternative scheme solve your case?

                Comment


                • #9
                  Bjarte Aagnes made a great point. More generally, Stata graphs look the way the code you run makes them look. I have seen silly mockery of the default s2color scheme that ignores the basic point that you can choose a different scheme, or even write your own.

                  We have no details of what you don’t like but I am optimistic on your behalf that changing some options would be much easier than working out how to plot results in other software.

                  That said, I don’t know anything specific about commands mentioned in this thread.

                  Comment


                  • #10
                    Thank you all for your advice.


                    I managed to figure out a way to get the raw results data out of the command.

                    Regarding what I said about how Stata graphs look, it's more that I know you can format them to look nice but for this paper I don't have the time to learn and play around with it. So would rather get the raw data out and put it into R, which I can now do.

                    Comment


                    • #11
                      Code:
                      ssc install schemepack, replace
                      ref https://asjadnaqvi.github.io/Stata-schemes/

                      Comment


                      • #12
                        As someone who's pretty fluent in Stata, and who also uses Python sometimes, I do NOT recommend you use R just to make graphics from a raw dataset you've made it would be a little like me switching to R because, I don't know, I prefer their summarize command to Stata's, it isn't worth the trouble.

                        A little learning of Stata's graphics will take you a very very very long way, I assure you

                        Comment


                        • #13
                          It sounds as if Jenner is already quite familiar with R. That's what it is.

                          The more serious question remains what anyone doesn't like about Stata graphics -- that isn't fixable. I see lots of awful R graphs, but they aren't representative of the best that is possible in R, which is often excellent. The main issues in either case are using defaults and copying someone else's mediocre code, and that is common in Stata too.

                          Comment


                          • #14
                            I think I should clarify my first point- even if I knew Python as well as I do Stata, I would still never do my analysis in Stata and do graphics in Python (unless I just NEEDED a graph from Python that Stata simply couldn't provide). The reasoning for me is a little more practical, in my opinion. When I do a project, I want to have as little dependencies as possible. If I can do my data collection, cleaning and analysis in pure Stata code, then that's what I'll do. I'll only add another software if I need to do something that Stata simply couldn't accommodate, as is sometimes the case. The reason for this, is because ideally, my project can replicate by just one run of my master file. I won't need to run the master file first and then go to QGIS or something else, everything is done from one software, one location. People don't need to listen to ne on this of course, this is just my standpoint on things.

                            I also agree with the main point though. Barring wacky things like putting graphs in graphs or other trendy elements, there's very very very little that R can do that Stata is just wholly inferior at. I've yet to see any convincing evidence from this pretty R gallery that there's very much that R can do graphically that Stata can't. Of course, there are exceptions.

                            Same with statistics too. I'll be polite and say that certain people I've met... worship, before R, hailing it's statistical abilities, which should be praised in my opinion, especially since it's free. But, Stata has Mata. Barring very very SPECIFIC applications (like, different equation solvers and whatnot), the difference between R and Stata is that someone's not yet programmed it. It isn't a law of nature, someone's just not written a routine yet.

                            But either way, if you'd like to make graphs in R, I don't mean to stop you.

                            ADDED: I also agree about customization. There's no software that just takes data and makes a da Vinci out of it graphically, certain R users I've met seem to be of the impression that R just makes awesome graphs like alchemy and that no further effort is needed beyond its default/ggplot settings
                            Last edited by Jared Greathouse; 08 Aug 2022, 07:21.

                            Comment


                            • #15
                              Originally posted by Jared Greathouse View Post
                              I think I should clarify my first point- even if I knew Python as well as I do Stata, I would still never do my analysis in Stata and do graphics in Python (unless I just NEEDED a graph from Python that Stata simply couldn't provide). The reasoning for me is a little more practical, in my opinion. When I do a project, I want to have as little dependencies as possible. If I can do my data collection, cleaning and analysis in pure Stata code, then that's what I'll do. I'll only add another software if I need to do something that Stata simply couldn't accommodate, as is sometimes the case. The reason for this, is because ideally, my project can replicate by just one run of my master file. I won't need to run the master file first and then go to QGIS or something else, everything is done from one software, one location. People don't need to listen to ne on this of course, this is just my standpoint on things.

                              I also agree with the main point though. Barring wacky things like putting graphs in graphs or other trendy elements, there's very very very little that R can do that Stata is just wholly inferior at. I've yet to see any convincing evidence from this pretty R gallery that there's very much that R can do graphically that Stata can't. Of course, there are exceptions.

                              Same with statistics too. I'll be polite and say that certain people I've met... worship, before R, hailing it's statistical abilities, which should be praised in my opinion, especially since it's free. But, Stata has Mata. Barring very very SPECIFIC applications (like, different equation solvers and whatnot), the difference between R and Stata is that someone's not yet programmed it. It isn't a law of nature, someone's just not written a routine yet.

                              But either way, if you'd like to make graphs in R, I don't mean to stop you.

                              ADDED: I also agree about customization. There's no software that just takes data and makes a da Vinci out of it graphically, certain R users I've met seem to be of the impression that R just makes awesome graphs like alchemy and that no further effort is needed beyond its default/ggplot settings
                              It's as simple as this, I'd used synth_runner in Stata before but I'm not a massive Stata user (that's why I asked a question haha), so for me it was quicker to do the analysis in Stata and then output to R, than to figure out the equivalent R command or to get good with Stata visualisation.

                              I had about 20 days to finish my paper, so I was just looking for advice, not to spark a whole debate on visualisation on Stata Vs R or to insult Stata users by saying that I'm more used to working in R 😅

                              Comment

                              Working...
                              X