Announcement

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

  • Is it possible to combine twoway binscatter?

    Is it possible to superimpose binscatter plot?

    I would usually do this with scatter in the following way

    sysuse auto, clear gen rep78_2 = rep78 + cond(foreign, 0.1, -0.1) scatter mpg rep78_2 if foreign, ms(Oh) mcolor(red) /// || scatter mpg rep78_2 if !foreign, ms(X) mcolor(blue) /// || lfit mpg rep78 if foreign, lcolor(red) /// || lfit mpg rep78 if !foreign, lcolor(blue) /// ytitle("`: var label mpg'") legend(order(1 "Foreign" 2 "Domestic"))
    But the twoway command or || do not seem to work with the binscatter plot command

    Many thanks

  • #2
    If I try this,

    twoway binscatter2 ln_int_c ln_int_p16 || binscatter2 ln_int_c ln_int_p5
    binscatter2 is not a twoway plot type

    Comment


    • #3
      binscatter is from SSC. I've no idea what binscatter2 is. Please note our request to explain the provenance of community-contributed commands.

      binscatter can't be combined with anything else to my knowledge. It's not a twoway type, and doesn't have a direct twoway analogue.

      I don't know what you're missing, but stringing twoway commands together to do it is likely to work better than your rewriting binscatter.

      Comment


      • #4
        Thank you Nick, what do you mean by stringing twoway commands together to do it is likely to work better? Could you please provide an example?

        binscatter2 is an update of binscatter

        Comment


        • #5
          You need to tell us where you got binscatter2, and we need access to it in order to help you. If you have a program we don't have access to, then how can you expect us to tell you anything that would be helpful to you?
          ---------------------------------
          Maarten L. Buis
          University of Konstanz
          Department of history and sociology
          box 40
          78457 Konstanz
          Germany
          http://www.maartenbuis.nl
          ---------------------------------

          Comment


          • #6
            "stringing twoway commands together" is exactly what your code in #1 exemplifies. The || syntax is typical.

            Comment


            • #7
              Thanks for your help

              I have found binscatter2 here https://github.com/mdroste/stata-binscatter2

              Also the || syntax does not work:

              binscatter ln_int_c ln_int_p16 || binscatter ln_int_c ln_int_p5
              | invalid name
              r(198);

              Comment


              • #8
                I didn't recommend that. As said, the || syntax applies to twoway commands and binscatter2 like binscatter is not a twoway command.

                A twoway command is as documented at

                Code:
                help graph twoway
                and while many graph commands use graph twoway internally, that doesn't make them twoway commands in Stata's sense. The terminology may seem confusing but it is Stata's and documenred.

                Superimposing the results of two binscatter (or presumably binscatter2) commands can't be done directly to my knowledge, You need to bin each variable yourself, do the calculations and then draw your own graph.

                Comment


                • #9
                  I have found a solution to superimpose the results of two binscatter. I will post an example here for others who may encounter a similar problem

                  clear*

                  sysuse auto
                  binscatter mpg weight, n(10) savedata(binned) replace
                  clear
                  do binned
                  save binned,replace

                  sysuse auto
                  binscatter mpg price, n(10) savedata(binned2) replace
                  clear
                  do binned2
                  save binned2,replace

                  sysuse auto,clear
                  append using binned, gen(binned)
                  append using binned2, gen(binned2)



                  twoway lfit mpg weight if binned == 1 ,sort lp(dash) lc(black) ///
                  || scatter mpg weight if binned == 1 , mc(blue) || ///
                  lfit mpg price if binned2 == 1 ,sort lp(dash) lc(black) ///
                  || scatter mpg price if binned2 == 1 , mc(blue)

                  Comment


                  • #10
                    Thanks for the information on the origin of binscatter2 and for closing the thread.
                    ---------------------------------
                    Maarten L. Buis
                    University of Konstanz
                    Department of history and sociology
                    box 40
                    78457 Konstanz
                    Germany
                    http://www.maartenbuis.nl
                    ---------------------------------

                    Comment

                    Working...
                    X