Announcement

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

  • Calculate conditional holding period return

    Hi everyone,

    I want to calculate the holding period return for the buy strategies (buy50 ==1) and sell strategies (sell50 == 1) as follows:

    For buy strategies:
    • HPRB1 = return in 547 + return in 548 + return in 549
    • HPRB2 = return in 554 +...+ return in 559
    For sell strategies:
    • HPRS1 = return in 550 + return in 551+ return in 552
    • HPRS2 = return in 560 +...+ return in 566
    Is there anyone who can show me how to use Stata code to calculate these HPRs?

    Thanks in advance.

    Best

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(time return buy50 sell50)
    547   .0011799157 1 .
    548   -.002749759 1 .
    549  -.0005252221 1 .
    550   -.003809786 . 1
    551  -.0003956057 . 1
    552 .000065926826 . 1
    553   .0005276818 . 1
    554   .0008570432 1 .
    555    .003490968 1 .
    556   -.000787728 1 .
    557  .00013140822 1 .
    558   .0009851815 1 .
    559   -.001312316 1 .
    560  -.0015111414 . 1
    561   -.001974094 . 1
    562   .0003955796 . 1
    563   .0019113462 . 1
    564    .002696937 . 1
    565   -.005510702 . 1
    566    .002770619 . 1
    567   .0041444963 . 1
    end

    --------------------
    (Stata 15.1 MP)

  • #2
    Code:
    egen HPRB1 = total(return) if inrange(time,547,549)
    etc. or,
    Code:
    gen group = sum(buy50!=buy50[_n-1])
    collapse (sum) return, by(group)

    Comment


    • #3
      Originally posted by Øyvind Snilsberg View Post
      [CODE]
      Code:
      gen group = sum(buy50!=buy50[_n-1])
      collapse (sum) return, by(group)
      It is super. This is what I need.

      Thanks Snilsberg
      --------------------
      (Stata 15.1 MP)

      Comment

      Working...
      X