Announcement

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

  • How to graph a yield curve in stata

    Hi,

    How to create an easy yield curve in stata for one observation. I have these variables: tre_mnd, seks_mnd, ni_mnd, tolv_mnd, tre_år fem_år, ti_år. Which show the interest rates for different maturities. I would like to graph the yield curve for one single observation. When qdate=="2008q1". I have tried different approaches but can't seem to get it right.


    . list qdate tre_mnd seks_mnd ni_mnd tolv_mnd tre_år fem_år ti_år

    +---------------------------------------------------------------------------+
    | qdate tre_mnd seks_mnd ni_mnd tolv_mnd tre_år fem_år ti_år |
    |---------------------------------------------------------------------------|
    1. | 1993q4 . . . . 5.28 5.39 5.78 |
    2. | 1994q1 . . . . 5.08 5.26 5.75 |
    3. | 1994q2 . . . . 6.13 6.75 7.34 |
    4. | 1994q3 . . . . 7.37 7.92 8.26 |
    5. | 1994q4 . . . . 7.69 8.17 8.46 |
    |---------------------------------------------------------------------------|
    6. | 1995q1 . . . . 7.03 7.63 8.05 |
    7. | 1995q2 . . . . 6.47 7.03 7.58 |
    8. | 1995q3 . . . . 6.24 6.78 7.36 |
    9. | 1995q4 . . . . 5.68 6.10 6.72 |
    10. | 1996q1 . . . . 5.43 5.89 6.67 |
    |---------------------------------------------------------------------------|
    11. | 1996q2 . . . . 5.35 5.98 6.89 |
    12. | 1996q3 . . . . 5.80 6.29 7.00 |
    13. | 1996q4 . . . . 5.23 5.76 6.54 |
    14. | 1997q1 . . . . 4.23 4.84 5.88 |
    15. | 1997q2 . . . . 4.46 5.08 6.06 |
    |---------------------------------------------------------------------------|
    16. | 1997q3 . . . . 4.88 5.32 5.97 |
    17. | 1997q4 . . . . 4.87 5.22 5.66 |
    18. | 1998q1 . . . . 4.68 4.97 5.30 |
    19. | 1998q2 . . . . 5.06 5.23 5.43 |
    20. | 1998q3 . . . . 5.74 5.59 5.44 |
    |---------------------------------------------------------------------------|
    21. | 1998q4 . . . . 5.78 5.56 5.43 |
    22. | 1999q1 . . . . 4.99 4.86 4.89 |
    23. | 1999q2 . . . . 4.99 4.98 5.06 |
    24. | 1999q3 . . . . 5.69 5.78 5.94 |
    25. | 1999q4 . . . . 5.85 5.90 6.12 |
    |---------------------------------------------------------------------------|
    26. | 2000q1 . . . . 6.21 6.20 6.27 |
    27. | 2000q2 . . . . 6.55 6.34 6.15 |
    28. | 2000q3 . . . . 6.96 6.57 6.24 |
    29. | 2000q4 . . . . 6.72 6.41 6.22 |
    30. | 2001q1 . . . . 6.46 6.18 5.98 |
    |---------------------------------------------------------------------------|
    31. | 2001q2 . . . . 6.80 6.61 6.44 |
    32. | 2001q3 . . . . 6.66 6.54 6.50 |
    33. | 2001q4 . . . . 5.87 5.92 6.04 |
    34. | 2002q1 . . . . 6.28 6.33 6.40 |
    35. | 2002q2 . . . . 6.85 6.79 6.75 |
    |---------------------------------------------------------------------------|
    36. | 2002q3 . . . . 6.53 6.39 6.32 |
    37. | 2002q4 . . . . 5.91 5.94 6.08 |
    38. | 2003q1 5.64 5.38 5.25 5.13 5.10 5.17 5.42 |
    39. | 2003q2 4.68 4.31 4.18 4.09 4.34 4.53 4.92 |
    40. | 2003q3 3.04 2.91 2.92 2.96 3.80 4.32 4.94 |
    |---------------------------------------------------------------------------|
    41. | 2003q4 2.61 2.66 2.75 2.85 3.75 4.30 4.90 |
    42. | 2004q1 1.95 1.84 1.88 1.94 2.89 3.49 4.31 |
    43. | 2004q2 1.77 1.88 2.01 2.14 3.28 4.02 4.76 |
    44. | 2004q3 1.83 1.86 1.93 2.01 2.96 3.64 4.33 |
    45. | 2004q4 1.81 1.81 1.87 1.94 2.71 3.32 4.05 |
    |---------------------------------------------------------------------------|
    46. | 2005q1 1.78 1.86 1.98 2.10 2.78 3.28 3.90 |
    47. | 2005q2 1.87 2.02 2.17 2.29 2.80 3.20 3.71 |
    48. | 2005q3 2.09 2.18 2.28 2.37 2.78 3.09 3.56 |
    49. | 2005q4 2.29 2.41 2.56 2.71 3.24 3.52 3.83 |
    50. | 2006q1 2.42 2.53 2.65 2.78 3.28 3.50 3.74 |
    |---------------------------------------------------------------------------|
    51. | 2006q2 2.80 2.92 3.06 3.20 3.70 3.95 4.18 |
    52. | 2006q3 3.12 3.25 3.39 3.53 3.89 4.01 4.21 |
    53. | 2006q4 3.50 3.65 3.82 3.97 4.09 4.14 4.19 |
    54. | 2007q1 4.00 4.16 4.33 4.46 4.53 4.50 4.45 |
    55. | 2007q2 4.44 4.62 4.77 4.85 4.97 4.96 4.94 |
    |---------------------------------------------------------------------------|
    56. | 2007q3 4.71 4.82 4.98 5.02 4.95 4.92 4.94 |
    57. | 2007q4 5.07 5.13 5.15 5.06 4.75 4.72 4.78 |
    58. | 2008q1 5.24 5.23 5.23 5.09 4.46 4.34 4.40 |
    59. | 2008q2 5.63 5.73 5.76 5.71 5.06 4.83 4.69 |
    60. | 2008q3 5.86 5.92 5.92 5.89 5.01 4.80 4.71 |
    |---------------------------------------------------------------------------|
    61. | 2008q4 4.22 4.15 4.06 4.12 3.56 3.75 4.05 |
    62. | 2009q1 2.37 2.24 2.05 2.04 2.54 3.07 3.75 |
    63. | 2009q2 1.66 1.66 1.63 1.67 2.47 3.25 4.08 |
    64. | 2009q3 1.47 1.68 1.81 1.90 2.82 3.47 4.13 |
    65. | 2009q4 1.79 2.04 2.19 2.28 2.98 3.51 4.03 |
    |---------------------------------------------------------------------------|
    66. | 2010q1 2.04 2.23 2.28 2.27 2.80 3.30 3.93 |
    67. | 2010q2 2.21 2.32 2.32 2.17 2.33 2.68 3.54 |
    68. | 2010q3 2.23 2.32 2.30 2.33 2.35 2.63 3.25 |
    69. | 2010q4 2.18 2.22 2.22 2.22 2.35 2.69 3.38 |
    70. | 2011q1 2.24 2.37 2.41 2.44 2.78 3.22 3.78 |
    |---------------------------------------------------------------------------|
    71. | 2011q2 2.33 2.46 2.43 2.46 2.66 2.98 3.54 |
    72. | 2011q3 2.17 2.07 2.01 2.04 1.96 2.18 2.73 |
    73. | 2011q4 1.80 1.70 1.59 1.56 1.58 1.89 2.49 |
    74. | 2012q1 1.60 1.62 1.59 1.56 1.52 1.79 2.36 |
    75. | 2012q2 1.53 1.55 1.52 1.51 1.44 1.61 2.10 |
    |---------------------------------------------------------------------------|
    76. | 2012q3 1.49 1.48 1.47 1.46 1.34 1.41 1.90 |
    77. | 2012q4 1.57 1.60 1.60 1.59 1.46 1.56 2.02 |
    78. | 2013q1 1.60 1.61 1.60 1.60 1.55 1.76 2.35 |
    79. | 2013q2 1.52 1.49 1.46 1.44 1.35 1.57 2.19 |
    80. | 2013q3 1.50 1.51 1.51 1.53 1.81 2.18 2.85 |
    |---------------------------------------------------------------------------|
    81. | 2013q4 1.47 1.47 1.47 1.50 1.80 2.21 2.92 |
    82. | 2014q1 1.35 1.34 1.33 1.35 1.69 2.13 2.91 |
    83. | 2014q2 1.26 1.29 1.32 1.36 1.64 1.98 2.74 |
    84. | 2014q3 1.17 1.22 1.25 1.27 1.48 1.74 2.40 |
    85. | 2014q4 1.20 1.17 1.17 1.17 1.27 1.46 2.03 |
    |---------------------------------------------------------------------------|
    86. | 2015q1 0.93 0.83 0.82 0.81 0.77 0.92 1.46 |
    87. | 2015q2 0.93 0.86 0.85 0.83 0.87 1.12 1.63 |
    88. | 2015q3 0.79 0.74 0.71 0.69 0.71 0.98 1.60 |
    89. | 2015q4 0.63 0.60 0.58 0.58 0.68 0.95 1.59 |
    90. | 2016q1 0.59 0.53 0.51 0.51 0.56 0.80 1.39 |
    |---------------------------------------------------------------------------|
    91. | 2016q2 0.53 0.50 0.49 0.50 0.53 0.78 1.29 |
    92. | 2016q3 0.50 0.48 0.48 0.47 0.55 0.69 1.09 |
    93. | 2016q4 0.52 0.51 0.50 0.52 0.81 1.09 1.56 |
    94. | 2017q1 0.48 0.48 0.48 0.49 0.77 1.09 1.73 |
    95. | 2017q2 0.42 0.41 0.41 0.43 0.75 1.03 1.58 |
    |---------------------------------------------------------------------------|
    96. | 2017q3 0.36 0.36 0.36 0.40 0.77 1.06 1.63 |
    97. | 2017q4 0.34 0.34 0.34 0.38 0.78 1.08 1.61 |
    98. | 2018q1 0.43 0.43 0.44 0.50 1.00 1.35 1.89 |
    99. | 2018q2 0.62 0.63 0.67 0.73 1.11 1.41 1.88 |
    100. | 2018q3 0.63 0.68 0.72 0.77 1.19 1.43 1.81 |
    |---------------------------------------------------------------------------|
    101. | 2018q4 0.75 0.79 0.84 0.89 1.29 1.56 1.94 |
    102. | 2019q1 0.97 1.01 1.04 1.06 1.20 1.34 1.72 |
    103. | 2019q2 1.12 1.16 1.19 1.21 1.30 1.35 1.60 |
    104. | 2019q3 1.25 1.26 1.25 1.24 1.20 1.19 1.27 |
    105. | 2019q4 1.24 1.20 1.21 1.22 1.25 1.25 1.39 |
    |---------------------------------------------------------------------------|
    106. | 2020q1 1.06 1.05 1.05 1.04 1.04 1.07 1.22 |
    107. | 2020q2 0.07 0.09 0.10 0.12 0.21 0.32 0.61 |
    108. | 2020q3 0.01 0.01 0.02 0.04 0.21 0.35 0.65 |
    109. | 2020q4 0.02 0.01 0.02 0.04 0.28 0.48 0.79 |
    110. | 2021q1 0.12 0.12 0.13 0.17 0.56 0.85 1.26 |
    |---------------------------------------------------------------------------|
    111. | 2021q2 0.08 0.12 0.19 0.27 0.76 1.07 1.45 |
    112. | 2021q3 . . . . . . . |
    113. | 2021q4 . . . . . . . |
    114. | 2022q1 . . . . . . . |
    115. | 2022q2 . . . . . . . |

  • #2
    Sorry, but what's a yield curve?

    Please use dataex to give a data example (FAQ Advice #12).

    Comment


    • #3
      A yield curve is a line that plots the yields or interest rates of bonds that have equal credit quality but different maturity dates. The slope of the yield curve predicts the direction of interest rates and the economic expansion or contraction that could result.
      https://www.investopedia.com/terms/y/yieldcurve.asp
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input str7 qdate double(tre_mnd seks_mnd ni_mnd tolv_mnd tre_år fem_år ti_år)
      "1993q4"    .    .    .    . 5.28 5.39 5.78
      "1994q1"    .    .    .    . 5.08 5.26 5.75
      "1994q2"    .    .    .    . 6.13 6.75 7.34
      "1994q3"    .    .    .    . 7.37 7.92 8.26
      "1994q4"    .    .    .    . 7.69 8.17 8.46
      "1995q1"    .    .    .    . 7.03 7.63 8.05
      "1995q2"    .    .    .    . 6.47 7.03 7.58
      "1995q3"    .    .    .    . 6.24 6.78 7.36
      "1995q4"    .    .    .    . 5.68  6.1 6.72
      "1996q1"    .    .    .    . 5.43 5.89 6.67
      "1996q2"    .    .    .    . 5.35 5.98 6.89
      "1996q3"    .    .    .    .  5.8 6.29    7
      "1996q4"    .    .    .    . 5.23 5.76 6.54
      "1997q1"    .    .    .    . 4.23 4.84 5.88
      "1997q2"    .    .    .    . 4.46 5.08 6.06
      "1997q3"    .    .    .    . 4.88 5.32 5.97
      "1997q4"    .    .    .    . 4.87 5.22 5.66
      "1998q1"    .    .    .    . 4.68 4.97  5.3
      "1998q2"    .    .    .    . 5.06 5.23 5.43
      "1998q3"    .    .    .    . 5.74 5.59 5.44
      "1998q4"    .    .    .    . 5.78 5.56 5.43
      "1999q1"    .    .    .    . 4.99 4.86 4.89
      "1999q2"    .    .    .    . 4.99 4.98 5.06
      "1999q3"    .    .    .    . 5.69 5.78 5.94
      "1999q4"    .    .    .    . 5.85  5.9 6.12
      "2000q1"    .    .    .    . 6.21  6.2 6.27
      "2000q2"    .    .    .    . 6.55 6.34 6.15
      "2000q3"    .    .    .    . 6.96 6.57 6.24
      "2000q4"    .    .    .    . 6.72 6.41 6.22
      "2001q1"    .    .    .    . 6.46 6.18 5.98
      "2001q2"    .    .    .    .  6.8 6.61 6.44
      "2001q3"    .    .    .    . 6.66 6.54  6.5
      "2001q4"    .    .    .    . 5.87 5.92 6.04
      "2002q1"    .    .    .    . 6.28 6.33  6.4
      "2002q2"    .    .    .    . 6.85 6.79 6.75
      "2002q3"    .    .    .    . 6.53 6.39 6.32
      "2002q4"    .    .    .    . 5.91 5.94 6.08
      "2003q1" 5.64 5.38 5.25 5.13  5.1 5.17 5.42
      "2003q2" 4.68 4.31 4.18 4.09 4.34 4.53 4.92
      "2003q3" 3.04 2.91 2.92 2.96  3.8 4.32 4.94
      "2003q4" 2.61 2.66 2.75 2.85 3.75  4.3  4.9
      "2004q1" 1.95 1.84 1.88 1.94 2.89 3.49 4.31
      "2004q2" 1.77 1.88 2.01 2.14 3.28 4.02 4.76
      "2004q3" 1.83 1.86 1.93 2.01 2.96 3.64 4.33
      "2004q4" 1.81 1.81 1.87 1.94 2.71 3.32 4.05
      "2005q1" 1.78 1.86 1.98  2.1 2.78 3.28  3.9
      "2005q2" 1.87 2.02 2.17 2.29  2.8  3.2 3.71
      "2005q3" 2.09 2.18 2.28 2.37 2.78 3.09 3.56
      "2005q4" 2.29 2.41 2.56 2.71 3.24 3.52 3.83
      "2006q1" 2.42 2.53 2.65 2.78 3.28  3.5 3.74
      "2006q2"  2.8 2.92 3.06  3.2  3.7 3.95 4.18
      "2006q3" 3.12 3.25 3.39 3.53 3.89 4.01 4.21
      "2006q4"  3.5 3.65 3.82 3.97 4.09 4.14 4.19
      "2007q1"    4 4.16 4.33 4.46 4.53  4.5 4.45
      "2007q2" 4.44 4.62 4.77 4.85 4.97 4.96 4.94
      "2007q3" 4.71 4.82 4.98 5.02 4.95 4.92 4.94
      "2007q4" 5.07 5.13 5.15 5.06 4.75 4.72 4.78
      "2008q1" 5.24 5.23 5.23 5.09 4.46 4.34  4.4
      "2008q2" 5.63 5.73 5.76 5.71 5.06 4.83 4.69
      "2008q3" 5.86 5.92 5.92 5.89 5.01  4.8 4.71
      "2008q4" 4.22 4.15 4.06 4.12 3.56 3.75 4.05
      "2009q1" 2.37 2.24 2.05 2.04 2.54 3.07 3.75
      "2009q2" 1.66 1.66 1.63 1.67 2.47 3.25 4.08
      "2009q3" 1.47 1.68 1.81  1.9 2.82 3.47 4.13
      "2009q4" 1.79 2.04 2.19 2.28 2.98 3.51 4.03
      "2010q1" 2.04 2.23 2.28 2.27  2.8  3.3 3.93
      "2010q2" 2.21 2.32 2.32 2.17 2.33 2.68 3.54
      "2010q3" 2.23 2.32  2.3 2.33 2.35 2.63 3.25
      "2010q4" 2.18 2.22 2.22 2.22 2.35 2.69 3.38
      "2011q1" 2.24 2.37 2.41 2.44 2.78 3.22 3.78
      "2011q2" 2.33 2.46 2.43 2.46 2.66 2.98 3.54
      "2011q3" 2.17 2.07 2.01 2.04 1.96 2.18 2.73
      "2011q4"  1.8  1.7 1.59 1.56 1.58 1.89 2.49
      "2012q1"  1.6 1.62 1.59 1.56 1.52 1.79 2.36
      "2012q2" 1.53 1.55 1.52 1.51 1.44 1.61  2.1
      "2012q3" 1.49 1.48 1.47 1.46 1.34 1.41  1.9
      "2012q4" 1.57  1.6  1.6 1.59 1.46 1.56 2.02
      "2013q1"  1.6 1.61  1.6  1.6 1.55 1.76 2.35
      "2013q2" 1.52 1.49 1.46 1.44 1.35 1.57 2.19
      "2013q3"  1.5 1.51 1.51 1.53 1.81 2.18 2.85
      "2013q4" 1.47 1.47 1.47  1.5  1.8 2.21 2.92
      "2014q1" 1.35 1.34 1.33 1.35 1.69 2.13 2.91
      "2014q2" 1.26 1.29 1.32 1.36 1.64 1.98 2.74
      "2014q3" 1.17 1.22 1.25 1.27 1.48 1.74  2.4
      "2014q4"  1.2 1.17 1.17 1.17 1.27 1.46 2.03
      "2015q1"  .93  .83  .82  .81  .77  .92 1.46
      "2015q2"  .93  .86  .85  .83  .87 1.12 1.63
      "2015q3"  .79  .74  .71  .69  .71  .98  1.6
      "2015q4"  .63   .6  .58  .58  .68  .95 1.59
      "2016q1"  .59  .53  .51  .51  .56   .8 1.39
      "2016q2"  .53   .5  .49   .5  .53  .78 1.29
      "2016q3"   .5  .48  .48  .47  .55  .69 1.09
      "2016q4"  .52  .51   .5  .52  .81 1.09 1.56
      "2017q1"  .48  .48  .48  .49  .77 1.09 1.73
      "2017q2"  .42  .41  .41  .43  .75 1.03 1.58
      "2017q3"  .36  .36  .36   .4  .77 1.06 1.63
      "2017q4"  .34  .34  .34  .38  .78 1.08 1.61
      "2018q1"  .43  .43  .44   .5    1 1.35 1.89
      "2018q2"  .62  .63  .67  .73 1.11 1.41 1.88
      "2018q3"  .63  .68  .72  .77 1.19 1.43 1.81
      "2018q4"  .75  .79  .84  .89 1.29 1.56 1.94
      "2019q1"  .97 1.01 1.04 1.06  1.2 1.34 1.72
      "2019q2" 1.12 1.16 1.19 1.21  1.3 1.35  1.6
      "2019q3" 1.25 1.26 1.25 1.24  1.2 1.19 1.27
      "2019q4" 1.24  1.2 1.21 1.22 1.25 1.25 1.39
      "2020q1" 1.06 1.05 1.05 1.04 1.04 1.07 1.22
      "2020q2"  .07  .09   .1  .12  .21  .32  .61
      "2020q3"  .01  .01  .02  .04  .21  .35  .65
      "2020q4"  .02  .01  .02  .04  .28  .48  .79
      "2021q1"  .12  .12  .13  .17  .56  .85 1.26
      "2021q2"  .08  .12  .19  .27  .76 1.07 1.45
      "2021q3"    .    .    .    .    .    .    .
      "2021q4"    .    .    .    .    .    .    .
      "2022q1"    .    .    .    .    .    .    .
      "2022q2"    .    .    .    .    .    .    .
      end
      However, we lack descriptions of your variables. So how to determine which variable to be plotted?
      Code:
      gen qdate2=quarterly(qdate,"YQ",1993)
      format qdate2 %tq
      twoway line tre_år qdate2

      Comment


      • #4
        Hi and thanks for responding.

        tre_mnd = is the yield from a 3 month T-bill
        seks_mnd= is the yield from a 6 month T- bill
        ni_mnd = is the yield from a 9 month T- bill
        tolv_mnd= is the yield from a 12 month T-bill
        tre_år = is the yield from a 3 year T-bond
        fem_år= is the yield from a 5 year T-bond
        ti_år= is the yield from a 10 year T- bond.

        I need a figure that shows the yield curve (of all of the above t-bills and t-bonds) for time period 2008q1.

        Code:
          list qdate tre_mnd seks_mnd ni_mnd tolv_mnd tre_år fem_år ti_år if _n==58
        
             +---------------------------------------------------------------------------+
             |  qdate   tre_mnd   seks_mnd   ni_mnd   tolv_mnd   tre_år   fem_år   ti_år |
             |---------------------------------------------------------------------------|
         58. | 2008q1      5.24       5.23     5.23       5.09     4.46     4.34    4.40 |
             +---------------------------------------------------------------------------+
        So it should be a fairly simple graph that puts one dot at 5.24% interest at 1 quarter time, another dot at 5.23 % for 2 quarters time, another dot at 5.23% for 3 quarters time and so on. And preferrably, a line connecting all the dots.
        Last edited by sunny paul; 12 Nov 2024, 09:20.

        Comment


        • #5
          Thanks to Chen Samulsion and OP for details.

          For that you need a different data layout. Here is some technique. Log scale is just a guess. There may well be strong conventions otherwise.

          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input str7 qdate double(tre_mnd seks_mnd ni_mnd tolv_mnd tre_år fem_år ti_år)
          "1993q4"    .    .    .    . 5.28 5.39 5.78
          "1994q1"    .    .    .    . 5.08 5.26 5.75
          "1994q2"    .    .    .    . 6.13 6.75 7.34
          "1994q3"    .    .    .    . 7.37 7.92 8.26
          "1994q4"    .    .    .    . 7.69 8.17 8.46
          "1995q1"    .    .    .    . 7.03 7.63 8.05
          "1995q2"    .    .    .    . 6.47 7.03 7.58
          "1995q3"    .    .    .    . 6.24 6.78 7.36
          "1995q4"    .    .    .    . 5.68  6.1 6.72
          "1996q1"    .    .    .    . 5.43 5.89 6.67
          "1996q2"    .    .    .    . 5.35 5.98 6.89
          "1996q3"    .    .    .    .  5.8 6.29    7
          "1996q4"    .    .    .    . 5.23 5.76 6.54
          "1997q1"    .    .    .    . 4.23 4.84 5.88
          "1997q2"    .    .    .    . 4.46 5.08 6.06
          "1997q3"    .    .    .    . 4.88 5.32 5.97
          "1997q4"    .    .    .    . 4.87 5.22 5.66
          "1998q1"    .    .    .    . 4.68 4.97  5.3
          "1998q2"    .    .    .    . 5.06 5.23 5.43
          "1998q3"    .    .    .    . 5.74 5.59 5.44
          "1998q4"    .    .    .    . 5.78 5.56 5.43
          "1999q1"    .    .    .    . 4.99 4.86 4.89
          "1999q2"    .    .    .    . 4.99 4.98 5.06
          "1999q3"    .    .    .    . 5.69 5.78 5.94
          "1999q4"    .    .    .    . 5.85  5.9 6.12
          "2000q1"    .    .    .    . 6.21  6.2 6.27
          "2000q2"    .    .    .    . 6.55 6.34 6.15
          "2000q3"    .    .    .    . 6.96 6.57 6.24
          "2000q4"    .    .    .    . 6.72 6.41 6.22
          "2001q1"    .    .    .    . 6.46 6.18 5.98
          "2001q2"    .    .    .    .  6.8 6.61 6.44
          "2001q3"    .    .    .    . 6.66 6.54  6.5
          "2001q4"    .    .    .    . 5.87 5.92 6.04
          "2002q1"    .    .    .    . 6.28 6.33  6.4
          "2002q2"    .    .    .    . 6.85 6.79 6.75
          "2002q3"    .    .    .    . 6.53 6.39 6.32
          "2002q4"    .    .    .    . 5.91 5.94 6.08
          "2003q1" 5.64 5.38 5.25 5.13  5.1 5.17 5.42
          "2003q2" 4.68 4.31 4.18 4.09 4.34 4.53 4.92
          "2003q3" 3.04 2.91 2.92 2.96  3.8 4.32 4.94
          "2003q4" 2.61 2.66 2.75 2.85 3.75  4.3  4.9
          "2004q1" 1.95 1.84 1.88 1.94 2.89 3.49 4.31
          "2004q2" 1.77 1.88 2.01 2.14 3.28 4.02 4.76
          "2004q3" 1.83 1.86 1.93 2.01 2.96 3.64 4.33
          "2004q4" 1.81 1.81 1.87 1.94 2.71 3.32 4.05
          "2005q1" 1.78 1.86 1.98  2.1 2.78 3.28  3.9
          "2005q2" 1.87 2.02 2.17 2.29  2.8  3.2 3.71
          "2005q3" 2.09 2.18 2.28 2.37 2.78 3.09 3.56
          "2005q4" 2.29 2.41 2.56 2.71 3.24 3.52 3.83
          "2006q1" 2.42 2.53 2.65 2.78 3.28  3.5 3.74
          "2006q2"  2.8 2.92 3.06  3.2  3.7 3.95 4.18
          "2006q3" 3.12 3.25 3.39 3.53 3.89 4.01 4.21
          "2006q4"  3.5 3.65 3.82 3.97 4.09 4.14 4.19
          "2007q1"    4 4.16 4.33 4.46 4.53  4.5 4.45
          "2007q2" 4.44 4.62 4.77 4.85 4.97 4.96 4.94
          "2007q3" 4.71 4.82 4.98 5.02 4.95 4.92 4.94
          "2007q4" 5.07 5.13 5.15 5.06 4.75 4.72 4.78
          "2008q1" 5.24 5.23 5.23 5.09 4.46 4.34  4.4
          "2008q2" 5.63 5.73 5.76 5.71 5.06 4.83 4.69
          "2008q3" 5.86 5.92 5.92 5.89 5.01  4.8 4.71
          "2008q4" 4.22 4.15 4.06 4.12 3.56 3.75 4.05
          "2009q1" 2.37 2.24 2.05 2.04 2.54 3.07 3.75
          "2009q2" 1.66 1.66 1.63 1.67 2.47 3.25 4.08
          "2009q3" 1.47 1.68 1.81  1.9 2.82 3.47 4.13
          "2009q4" 1.79 2.04 2.19 2.28 2.98 3.51 4.03
          "2010q1" 2.04 2.23 2.28 2.27  2.8  3.3 3.93
          "2010q2" 2.21 2.32 2.32 2.17 2.33 2.68 3.54
          "2010q3" 2.23 2.32  2.3 2.33 2.35 2.63 3.25
          "2010q4" 2.18 2.22 2.22 2.22 2.35 2.69 3.38
          "2011q1" 2.24 2.37 2.41 2.44 2.78 3.22 3.78
          "2011q2" 2.33 2.46 2.43 2.46 2.66 2.98 3.54
          "2011q3" 2.17 2.07 2.01 2.04 1.96 2.18 2.73
          "2011q4"  1.8  1.7 1.59 1.56 1.58 1.89 2.49
          "2012q1"  1.6 1.62 1.59 1.56 1.52 1.79 2.36
          "2012q2" 1.53 1.55 1.52 1.51 1.44 1.61  2.1
          "2012q3" 1.49 1.48 1.47 1.46 1.34 1.41  1.9
          "2012q4" 1.57  1.6  1.6 1.59 1.46 1.56 2.02
          "2013q1"  1.6 1.61  1.6  1.6 1.55 1.76 2.35
          "2013q2" 1.52 1.49 1.46 1.44 1.35 1.57 2.19
          "2013q3"  1.5 1.51 1.51 1.53 1.81 2.18 2.85
          "2013q4" 1.47 1.47 1.47  1.5  1.8 2.21 2.92
          "2014q1" 1.35 1.34 1.33 1.35 1.69 2.13 2.91
          "2014q2" 1.26 1.29 1.32 1.36 1.64 1.98 2.74
          "2014q3" 1.17 1.22 1.25 1.27 1.48 1.74  2.4
          "2014q4"  1.2 1.17 1.17 1.17 1.27 1.46 2.03
          "2015q1"  .93  .83  .82  .81  .77  .92 1.46
          "2015q2"  .93  .86  .85  .83  .87 1.12 1.63
          "2015q3"  .79  .74  .71  .69  .71  .98  1.6
          "2015q4"  .63   .6  .58  .58  .68  .95 1.59
          "2016q1"  .59  .53  .51  .51  .56   .8 1.39
          "2016q2"  .53   .5  .49   .5  .53  .78 1.29
          "2016q3"   .5  .48  .48  .47  .55  .69 1.09
          "2016q4"  .52  .51   .5  .52  .81 1.09 1.56
          "2017q1"  .48  .48  .48  .49  .77 1.09 1.73
          "2017q2"  .42  .41  .41  .43  .75 1.03 1.58
          "2017q3"  .36  .36  .36   .4  .77 1.06 1.63
          "2017q4"  .34  .34  .34  .38  .78 1.08 1.61
          "2018q1"  .43  .43  .44   .5    1 1.35 1.89
          "2018q2"  .62  .63  .67  .73 1.11 1.41 1.88
          "2018q3"  .63  .68  .72  .77 1.19 1.43 1.81
          "2018q4"  .75  .79  .84  .89 1.29 1.56 1.94
          "2019q1"  .97 1.01 1.04 1.06  1.2 1.34 1.72
          "2019q2" 1.12 1.16 1.19 1.21  1.3 1.35  1.6
          "2019q3" 1.25 1.26 1.25 1.24  1.2 1.19 1.27
          "2019q4" 1.24  1.2 1.21 1.22 1.25 1.25 1.39
          "2020q1" 1.06 1.05 1.05 1.04 1.04 1.07 1.22
          "2020q2"  .07  .09   .1  .12  .21  .32  .61
          "2020q3"  .01  .01  .02  .04  .21  .35  .65
          "2020q4"  .02  .01  .02  .04  .28  .48  .79
          "2021q1"  .12  .12  .13  .17  .56  .85 1.26
          "2021q2"  .08  .12  .19  .27  .76 1.07 1.45
          "2021q3"    .    .    .    .    .    .    .
          "2021q4"    .    .    .    .    .    .    .
          "2022q1"    .    .    .    .    .    .    .
          "2022q2"    .    .    .    .    .    .    .
          end
          
          rename (tre_mnd seks_mnd ni_mnd tolv_mnd tre_år fem_år ti_år) (T3 T6 T9 T12 T36 T60 T120)
          
          gen better_qdate = quarterly(qdate, "YQ")
          
          label var better_qdate "quarterly date"
          
          reshape long T , i(better_qdate) j(period)
          
          local show = strofreal(yq(2008, 1), "%tq")
          
          twoway connected T period if better_qdate == yq(2008, 1), xsc(log) xla(3(3)12 36 "3" 60 "5" 120 "10") xmla(7 "months" 72 "years", tlength(*7) tlc(none) labsize(medsmall)) subtitle("`show'") ytitle(Interest rate (%))
          Click image for larger version

Name:	yield.png
Views:	1
Size:	34.6 KB
ID:	1767486

          Comment


          • #6
            This is just what I needed. Thanks a lot

            Comment


            • #7
              Well, I think you should change your data structure. And if you don't want to destroy your data structure, here is a clumsy code which add two variable in your dataset. But I think someone else can provide some smart solution. And here is how to creat yield curve in Excel: https://www.investopedia.com/ask/ans...urve-excel.asp
              Code:
              mkmat tre_mnd seks_mnd ni_mnd tolv_mnd tre_år fem_år ti_år if qdate=="2008q1", matrix(A)
              matrix A=A'
              svmat A, names(yield)
              gen maturity=_n in 1/7
              label define maturity 1 "3 month T-bill" 2 "6 month T-bill" 3 "9 month T-bill" 4 "12 month T-bill" 5 "3 year T-bond" 6 "5 year T-bond" 7 "10 year T-bond"
              label values maturity maturity
              twoway line yield maturity, xlabel(1/7, valuelabel labsize(vsmall))
              Nick just provide a smart solution in #5. And as I can expected, he used reshape.
              Last edited by Chen Samulsion; 12 Nov 2024, 10:07. Reason: Nick have provide excellent answer

              Comment


              • #8
                Originally posted by Chen Samulsion View Post
                Well, I think you should change your data structure. And if you don't want to destroy your data structure, here is a clumsy code which add two variable in your dataset. But I think someone else can provide some smart solution. And here is how to creat yield curve in Excel: https://www.investopedia.com/ask/ans...urve-excel.asp
                Code:
                mkmat tre_mnd seks_mnd ni_mnd tolv_mnd tre_år fem_år ti_år if qdate=="2008q1", matrix(A)
                matrix A=A'
                svmat A, names(yield)
                gen maturity=_n in 1/7
                label define maturity 1 "3 month T-bill" 2 "6 month T-bill" 3 "9 month T-bill" 4 "12 month T-bill" 5 "3 year T-bond" 6 "5 year T-bond" 7 "10 year T-bond"
                label values maturity maturity
                twoway line yield maturity, xlabel(1/7, valuelabel labsize(vsmall))
                Nick just provide a smart solution in #5. And as I can expected, he used reshape.
                Thanks Chen! Yes this is fairly easy to do in excel. However all of my other figures in my thesis is from Stata, so I figured it would look better to graph the yield curve in stata as well!

                Comment


                • #9
                  Hi sunny paul the code I posted in #7 is a piece of Stata code. I used matrix command to generate yield variable, and you can run it in Stata.

                  Comment


                  • #10
                    Hi Nick Cox , How can I draw a twoway line diagram to show the price on the vertical axis and dd and ss on the horizontal axis like the conventional demand and supply curve? My data is as follows:

                    Code:
                    * Example generated by -dataex-. For more info, type help dataex
                    clear
                    input float(dd ss price)
                       105 21.026  0
                    70.586 22.308 .2
                    36.172  23.59 .4
                     1.758 24.872 .6
                    end
                    Thanks in advance for your support.

                    Comment


                    • #11
                      Code:
                      line price dd || line price ss
                      or so I guess if I remember my economics teaching from 1967 correctly. (Moral: Please don't assume that everyone on Statalist works in your field.) (Compare #2.)

                      Comment

                      Working...
                      X