Announcement

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

  • Creating a returns per trading month variable

    Dear Forum-users,

    I have a question regarding the following data. The ncusip is the identifier, ret equals the returns, and t concerns the trading days relative to an event date. The event date is here t= 0, and the data goes on to t = 800. Furthermore, I use Stata 15.1 on windows 10.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str8 ncusip double ret float t
    "14327110" -.043478261679410934 0
    "14327110" -.13636364042758942 1
    "14327110" -.05263157933950424 2
    "14327110" 0 3
    "14327110" .1111111119389534 4
    "14327110" .05000000074505806 5
    "14327110" .0476190485060215 6
    "14327110" 0 7
    "14327110" .04545454680919647 8
    "14327110" 0 9
    "14327110" 0 10
    "14327110" -.043478261679410934 11
    "14327110" 0 12
    "14327110" .13636364042758942 13
    "14327110" 0 14
    "14327110" 0 15
    "14327110" 0 16
    "14327110" .14926364032752912 17
    "14327110" 0 18
    "14327110" 0 19
    "14327110" 0 20
    "14327110" 0 21
    "14327110" 0 22
    "14327110" .04545454680919647 23
    end
    I want to generate an additional variable that serves as a trading month. Here, a month is defined as 21 trading days. Thus, from t =1 until t = 21 is month 1, and month 22 till 43, etc. I'm looking for a total of 36 months. Normally, I would recode t by hand, but that seems rather inefficient for 36 months.

    Thank you very much for your help.
    Kind regards,
    Justin


  • #2
    Code:
    gen trading_month = ceil(t/21)
    Even if it were only a few months, why would you even consider doing this by hand? The reason to do things with code and not by hand is to assure that what you do is, a) correct, and b) well documented. The fact that something might be quick and easy to do by hand would not justify doing so, unless you are just playing around with the data for fun. If you are doing this for any serious purpose, doing anything by hand is inappropriate.

    Comment

    Working...
    X