Announcement

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

  • Add vertical dotted line to a graph

    Hi,

    I have the following plot and I would like to add a vertical dotted line between two countries (JP and CH) and the fitted line. Can someone help me with this? Thanks.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(t ym) str25 Country double(i nfa i_US diff_i) str2 ISO_Country double N
    605 605 "Australia"          4.89  -.6361932594509315 .52  4.369999999999999 "AU" 18
    605 605 "Denmark"           1.152  .11107218805995124 .52  .6319999999999999 "DK" 18
    605 605 "Hungary"          5.4332 -1.1034204326307862 .52             4.9132 "HU" 18
    605 605 "Canada"         .7240909 -.16083738497657551 .52 .20409089999999996 "CA" 18
    605 605 "Japan"               .38   .5653186874679698 .52               -.14 "JP" 18
    605 605 "Israel"         1.637273  .10693765443351133 .52           1.117273 "IL" 18
    605 605 "Mexico"             5.01  -.3889563338310338 .52               4.49 "MX" 18
    605 605 "Euro"              .7276 -.18366856359995462 .52              .2076 "EU" 18
    605 605 "United Kingdom"   .72839  -.2518700226667981 .52 .20838999999999996 "UK" 18
    605 605 "Estonia"            1.47  -.7378494186166594 .52                .95 "EE" 18
    605 605 "New Zealand"        3.07  -.7909065216543432 .52               2.55 "NZ" 18
    605 605 "Korea"              2.45 -.13567637377153552 .52 1.9300000000000002 "KR" 18
    605 605 "Sweden"              .27 -.08128179740209189 .52               -.25 "SE" 18
    605 605 "Chile"              1.44 -.13657433787788453 .52  .9199999999999999 "CL" 18
    605 605 "Switzerland"      .11167  1.4318877305360396 .52            -.40833 "CH" 18
    605 605 "Poland"             3.87  -.6739952242742245 .52               3.35 "PL" 18
    605 605 "Norway"             2.67   .9070247055305891 .52               2.15 "NO" 18
    605 605 "Czech Republic"     1.24  -.4935960080934906 .52                .72 "CZ" 18
    end
    format %tm ym
    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(ISO_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)))

  • #2
    From -help twoway-, lines may be added to the graph for emphasis by using the added_line_options yline() and xline(). See -help added line options-.

    Comment


    • #3
      How would you write the syntax? I have tried but I'm struggling with it. Thanks a lot in advance!

      Comment


      • #4
        Code:
        twoway scatter yvar xvar, xline(value) yline(value)

        Comment


        • #5
          How can that be integrated to the following:

          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(ISO_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)))
          Also, does that really achieve the purpose? I could not run it but it does not seem to tailor for 2 countries only. Thanks.

          Comment

          Working...
          X