Announcement

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

  • Extracting x- and y-coordinates from binscatter

    I was wondering whether there is an immediate way to collapse one's dataset into the x- and y-coordinates of the scatter plot that results when running the community-supplied command -binscatter- by Michael Stepner.

    Many thanks.

  • #2
    Provide a reproducible example. You can use one of Stata's datasets to do so.

    Comment


    • #3
      Thanks, Andrew, for getting back to me so quickly. My choice of dataset (and variables for that matter) might not be ideal in order to illustrate the usefulness of -binscatter- (ssc) but conceptually speaking, when you run

      Code:
      sysuse auto, clear
      binscatter price mpg, controls(weight length)
      the output is a scatter plot with roughly 15 data-points. My goal would be to extract the coordinates of those resultant data-points, e.g. by collapsing my data set into the corresponding 15 observations on mpg and price.

      Comment


      • #4
        Thanks. See

        Code:
        help serset
        Code:
        *ssc install binscatter, clear
        sysuse auto, clear
        serset clear
        binscatter price mpg, controls(weight length) linetype(none) saving(gr1, replace)
        serset
        serset use, clear
        qui ds
        scatter `r(varlist)', saving(gr2, replace)
        gr combine gr1.gph gr2.gph
        list, sep(0)
        Res.:

        Code:
        . list, sep(0)
        
             +---------------------+
             | __000000   __000001 |
             |---------------------|
          1. | 7708.986   15.36638 |
          2. | 7296.664   17.29647 |
          3. | 9134.336   18.25014 |
          4. | 8178.358   18.65475 |
          5. | 5358.144   19.12579 |
          6. | 6402.154   19.72018 |
          7. | 6266.413   20.03812 |
          8. |  4112.68   20.35558 |
          9. | 5130.125   20.63411 |
         10. | 6067.938   20.82926 |
         11. | 4703.824   21.21599 |
         12. | 4683.766   21.49749 |
         13. |  5429.12   21.72291 |
         14. | 6571.992   21.96066 |
         15. | 5572.696   22.35784 |
         16. | 6478.716   22.81931 |
         17. | 4977.235   23.27673 |
         18. | 6179.023   24.47673 |
         19. | 6865.149   27.26818 |
         20. | 6607.218   31.09768 |
             +---------------------+
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	39.1 KB
ID:	1737710

        Last edited by Andrew Musau; 19 Dec 2023, 16:19.

        Comment


        • #5
          binscatter is from SSC.

          My reading of the help is that there is an explicit option savedata() to do precisely this. It worked for me:

          Code:
          sysuse auto, clear
          binscatter price mpg, controls(weight length) savedata(foo)

          Comment


          • #6
            Thanks so much to both of you, Nick and Andrew. Works perfectly!

            When I tried to call the help documentation for -binscatter- I received the error message: "request ignored because of batch mode". Should have investigated further...

            Comment

            Working...
            X