Announcement

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

  • Scatter plot with Country name and R-square

    Hi,

    I would like to create a scatter plot with a fitted regression line, along with R^2 and display the name of the country corresponding to each point. I would also like to name the y-axis "Interest Rate Differential (%)", the y-axis "Net Foreign Asset (NFA)" and provide a title for the graph "Interest Rate VS NFA".

    Here is the data:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str52 Country double(nfa diff_i)
    "Australia"       -.4267577486506838   1.615668604651164
    "Canada"          -.2696254208220782 .011162790697674955
    "Chile"           -.3628558592742929  10.223658382651651
    "Czech Republic" -.23455379242580174   2.010113071740569
    "Hungary"         -.7495181138676478   9.596175101188097
    "Iceland"        -1.7826689000284937  10.434086163048555
    "Israel"           .1590222455724404   .6748448767712435
    "Italy"          -.10556646713862525   5.023209166666656
    "Japan"           .37988397756392067 -3.7284142512077305
    "Korea"          -.12107555882403813  1.5218750000000025
    "Mexico"          -.3443486180147916   8.274787071185017
    "New Zealand"     -.7649633061776219  1.8052225176122438
    "Sweden"         -.31080523852767533  .37955777777777666
    "Switzerland"     1.2745308938969182  -.6942708333333352
    "United Kingdom"  -.0366740451489023  -.5527753968253981
    end
    Here is what I have so far. I do not know how to display the country and R-square:
    Code:
    graph twoway (lfit diff_i nfa) (scatter diff_i nfa)
    graph twoway (lfit i nfa) (scatter i nfa)
    Can someone help? Thanks.

  • #2
    Code:
    reg diff_i nfa
    local r2: display %5.4f e(r2)
    graph twoway lfit diff_i nfa || scatter diff_i nfa,mlabel(Country)||,ytitle("Interest Rate Differential") xtitle("Net Foreign Asset (NFA)") title("Interest Rate vs. NFA") note("R{superscript:2} = `r2'") legend(off)

    Comment


    • #3
      That's great, thanks a lot. Would you be able to help me display the equation of the regression line? Also, is there any way to display the countries so that they do not overlap? Thanks.

      Comment


      • #4
        One way to solve the second issue is to use the -mlabvpos- (written by Ulrich Kohler) function of -egenmore-:

        Code:
        reg diff_i nfa
        local r2: display %5.4f e(r2)
        local cons: display %5.4f r(table)[1,2]
        local b: display %5.4f r(table)[1,1]
        egen pos = mlabvpos(diff_i nfa)
        graph twoway lfit diff_i nfa || scatter diff_i nfa,mlabel(Country) mlabvpos(pos)||,ytitle("Interest Rate Differential") xtitle("Net Foreign Asset (NFA)") title("Interest Rate vs. NFA") note("diff_i = `cons' + (`b'*nfa)",tstyle(size(medium)))  legend(off) caption("R{superscript:2} = `r2'",tstyle(size(medium)))

        Comment


        • #5
          aaplot from SSC gives some code for showing the equation.

          Comment


          • #6
            Thanks a lot Ali, it really helps!

            Nick: How would you use aaplot in order to get the regression equation as well as statistical significance? I have tried the following with no success:

            Code:
            aaplot diff_i nfa || scatter diff_i nfa,mlabel(Country) mlabvpos(pos)||,ytitle("Interest Rate Differential") xtitle("Net Foreign Asset (NFA)") title("Interest Rate Differential vs. NFA") note("diff_i = `cons' + (`b'*nfa)",tstyle(size(medium)))  legend(off) caption("R{superscript:2} = `r2'",tstyle(size(medium)))
            Thank you in advance

            Comment


            • #7
              Your first question is already addressed in the help for aaplot -- although you have it the wrong way round, as the command displays the equation but not significance results.


              aaplot is indicative, not definitive. Some tastes might run to showing (for example) standard errors, t statistics and P-values instead of,
              or in addition to, the results shown. Users so inclined should feel free to clone
              aaplot and should feel compelled to use their own
              different program name.
              aaplot is not a twoway type so does not support the || syntax. Something more like this may work, but is, among other details, dependent on the local macros it invokes.


              Code:
              aaplot diff_i nfa, mlabel(Country) mlabvpos(pos) ytitle("Interest Rate Differential") xtitle("Net Foreign Asset (NFA)") title("Interest Rate Differential vs. NFA") note("diff_i = `cons' + (`b'*nfa)",tstyle(size(medium)))  legend(off) caption("R{superscript:2} = `r2'",tstyle(size(medium))). 

              Comment


              • #8
                Hi Nick,

                I do not see the statistical significance in the code you provided. Would you be able to help me add it? Thanks.

                Comment

                Working...
                X