Announcement

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

  • Help with generating/calculating variable!

    I would appreciate help creating the variable new_Expected = implied_rate[_n-1] - implied rate[the final day of month - 1]. In other words, the final day of the previous month. For example, if the month is August (month==8), then the final day of month - 1 is the final day of month == 7 which is 31. However, the data for implied_rate is financial market data, so it is only for 5 days/week and not on holidays. This may create an issue if the final day of the month is on a weekend, as it will not show up in my data. For example, see rows 189 to 190. If the data does not go to the actual end of the month (ie. day != D), I would like the new_Expected to take the implied_rate from the last day of the month when markets were open (row 189 in the case of September 2000). Variable D indicates the number of days in the given month.

    Here is my current code:
    gen new_Expected = .
    replace new_Expected = implied_rate[_n-1] - implied_rate[_n-1-day] if Change != . & day != 1
    replace new_Expected = implied_rate[_n] - implied_rate[_n-1] if Change != . & day = 1

    I originally thought that I could do implied_rate[_n-1-day], but this doesn't work given that there are not 30 days worth of data/month (because of weekends and holidays). I'm trying to calculate new_Expected as the implied rate of the day before a Change (where Change != .) - implied_rate on the last day of the previous month.

    Thank you so much in advance for the help!!


    Click image for larger version

Name:	Screenshot 2024-02-22 at 9.06.43 PM.png
Views:	1
Size:	755.4 KB
ID:	1744304



    Click image for larger version

Name:	Screenshot 2024-02-22 at 8.58.07 PM.png
Views:	1
Size:	794.6 KB
ID:	1744303

  • #2
    Use dataex to give a data example, rather than a screenshot, and a good reply is then much more likely.. https://www.statalist.org/forums/help#stata explains.

    Comment

    Working...
    X