Announcement

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

  • Include slope on binscatter plot

    Hello,

    I am new to Stata - I was wondering if there is a way to add the value of the slope to binscatter plot, as in the example below? Thank you for your help.

    Click image for larger version

Name:	example.JPG
Views:	1
Size:	26.8 KB
ID:	1618657

  • #2
    I am not familiar with this user-written program (the FAQ asks you to provide info on where this comes from - please read the FAQ), but the help file says that this program accepts standard twoway options including those for text; see
    Code:
    help added text options

    Comment


    • #3
      Code:
      // open example data
      clear
      sysuse nlsw88
      
      // estimate the regression equation
      reg wage grade
      
      // build the regression equation
      local eq = `"`e(depvar)' = "'                         // the dependent variable
      local eq = `"`eq' `: display %4.2f _b[_cons]'"'       // the constant
      local eq = `"`eq' (`: display %4.2f _se[_cons]') + "' // se of the constant
      local eq = `"`eq' `: display %4.2f _b[grade]'"'       // effect of grade
      local eq = `"`eq' (`: display %4.2f _se[grade]')"'    // se of grade
      local eq = `"`eq' grade + {&epsilon}"'                // error term
      
      // apply the equation to binscatter
      binscatter wage grade, text(-2 10 `"`eq'"')
      ---------------------------------
      Maarten L. Buis
      University of Konstanz
      Department of history and sociology
      box 40
      78457 Konstanz
      Germany
      http://www.maartenbuis.nl
      ---------------------------------

      Comment


      • #4
        Originally posted by Rich Goldstein View Post
        I am not familiar with this user-written program (the FAQ asks you to provide info on where this comes from - please read the FAQ), but the help file says that this program accepts standard twoway options including those for text; see
        Code:
        help added text options
        thank you - the example actually comes from this file on binscatter plots: https://michaelstepner.com/binscatte...erence2014.pdf (page 27)

        Comment


        • #5
          Originally posted by Maarten Buis View Post
          Code:
          // open example data
          clear
          sysuse nlsw88
          
          // estimate the regression equation
          reg wage grade
          
          // build the regression equation
          local eq = `"`e(depvar)' = "' // the dependent variable
          local eq = `"`eq' `: display %4.2f _b[_cons]'"' // the constant
          local eq = `"`eq' (`: display %4.2f _se[_cons]') + "' // se of the constant
          local eq = `"`eq' `: display %4.2f _b[grade]'"' // effect of grade
          local eq = `"`eq' (`: display %4.2f _se[grade]')"' // se of grade
          local eq = `"`eq' grade + {&epsilon}"' // error term
          
          // apply the equation to binscatter
          binscatter wage grade, text(-2 10 `"`eq'"')
          thank you very much for your help - for some reason, it still doesn't work with my data, whereas it works fine if I use nlsw88.

          Comment


          • #6
            Alternativley try aaplot written by Nick Cox and available from SSC.

            Code:
            sysuse "nlsw88", clear
            aaplot wage tenure

            Comment


            • #7
              Originally posted by Justin Niakamal View Post
              Alternativley try aaplot written by Nick Cox and available from SSC.

              Code:
              sysuse "nlsw88", clear
              aaplot wage tenure
              ok, thank you!

              Comment


              • #8
                Originally posted by Isabelle Davies View Post

                thank you very much for your help - for some reason, it still doesn't work with my data, whereas it works fine if I use nlsw88.
                Look at the y axis and x axis in your graph. Then substitute

                Code:
                 text(-2 10 `"`eq'"')
                with the an appropriate y-value and x-value in your graph

                Code:
                 text(y x "my text")
                The coordinate pair specifies the exact position where you want the text to appear in your graph.

                Comment


                • #9
                  Originally posted by Andrew Musau View Post

                  Look at the y axis and x axis in your graph. Then substitute

                  Code:
                   text(-2 10 `"`eq'"')
                  with the an appropriate y-value and x-value in your graph

                  Code:
                   text(y x "my text")
                  The coordinate pair specifies the exact position where you want the text to appear in your graph.
                  thanks a lot!

                  Comment


                  • #10
                    Andrew Musau Hi Andrew,

                    I actually tried an arbitrarily chosen coordinate pair and a pair with the actual values for the dependent variable and explanatory variable. Both did not work though the code run smoothly without error report.

                    My code is:

                    reg depvar expvar
                    local eq = `"`e(depvar)' = "' // the dependent variable
                    local eq = `"`eq' `: display %4.2f _b[expvar]'"' // effect of expvar
                    local eq = `"`eq' (`: display %4.2f _se[expvar]')"' // se of expvar
                    binscatter depvar expvar, text(y x `"`eq'"')

                    Many thanks!

                    Comment


                    • #11
                      You need to post a reproducible example using the dataex command (see FAQ Advice #12), otherwise I cannot offer any useful advice based on your post.

                      Comment

                      Working...
                      X