Announcement

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

  • Graph from Stata to Excel

    hello! which command can I use to export a graph from stata to excel?
    someone could write this directly around the command:

    graph bar, over(hochschule_haw, label(angle(vertical)labsize(vsmall)))

    and do I have to pay attention to anything? Activate before or so?

    Greetings and thanks, Franzi

  • #2
    You can use putexcel to export a graph from Stata to Excel. See, "Example 5: Adding a graph to an Excel file" in the Stata Blog post below:

    https://blog.stata.com/2017/01/24/cr...a-expressions/

    Comment


    • #3
      Thanks a lot !!!
      And what do I write in the parenthesis of "sheet (...)"?

      sorry, sorry, I am a total beginner...

      Comment


      • #4
        No problem. You can just use that to name the sheet. For example sheet("hochschule_haw graph") if you have a spreadsheet with multiple sheets. Otherwise, you can ignore and by default sheet1 will be used.

        Code:
        clear all
        sysuse "auto.dta"
        
        putexcel set myexample.xlsx,  replace
        scatter price mpg 
        graph export my_scatter.png, replace
        putexcel A1 = picture(my_scatter.png)

        Comment


        • #5
          thanks a lot, it works!
          Can i also adjust the size of the image? In stata as command, so that it is smaller in ecxel?

          Comment


          • #6
            and how can I place the graph at a certain position in excel?

            Comment


            • #7
              You can place the graph in a certain position when you specify putexcel cellexplist. For example, putexcel D1 means write in Excel column D row 1. As for adjusting the size, you can use the width() and height() options in graph export.

              Code:
              clear all
              sysuse "auto.dta"
              
              putexcel set myexample.xlsx,  replace
              scatter price mpg 
              graph export my_scatter.png, width(100) height(100) replace 
              putexcel D1 = picture(my_scatter.png)
              Click image for larger version

Name:	Screen Shot 2020-10-09 at 8.11.53 AM.png
Views:	2
Size:	317.8 KB
ID:	1576349

              Note (from the help file)

              width(#) specifies the width of the graph in pixels. width() must contain an integer between 8 and 16,000.
              height(#) specifies the height of the graph in pixels. height() must contain an integer between 8 and 16,000.

              Hope this helps.
              Attached Files

              Comment


              • #8
                Thank you so much ! It's working (:

                Comment

                Working...
                X