Announcement

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

  • Calculating Salience and Recency Variable using daily returns

    Hello Statalisters,

    I need to measure two variables, Salience and Recency.

    Firstly, I tried calculating the monthly ST value (STV) for stocks, computed as the covariance between salience weights and daily returns. However, I doubt I measured it correctly based on the Stata code below.

    The ST value is determined in several steps:

    1. We calculate the salience of each stock’s daily payoff within the measurement period. Consequently, investors assess a company in the context of all other firms. Therefore, the salience of a security’s return on day s (ri,s) depends on its distance from the average returns in the market on that day (rs).


    2. In the second step, to calculate the salience weight for each stock, we rank the daily returns in each month in descending order of salience ranging from 1 for the most salient to S for the least salient (S denotes the number of trading days within the analyzed month or ranking period). Where δ=0.7 captures the degree of salience distortion and π = 1/S as the scaling factor.


    3. Finally, the stock's ST value is computed as the covariance between salience weights and daily returns.


    Secondly, I also need to calculate another variable, RECENCY which captures the dynamic decay of attention following a Salient event. It is defined as the inverse of one plus the number of trading days between the Salient day and the last trading day in the portfolio formation month.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long date double(permno ret Mktrt) float(time_avail_m Salience)
    22950 92172   .0078124552965164185 -.004101261 754    .10645448
    22950 75649   -.030303021892905235 -.004101261 754    .19494736
    22950 91068   -.013755304738879204 -.004101261 754     .0819135
    22950 22628   .0004910766729153693 -.004101261 754    .04390702
    22950 82215   -.020527908578515053 -.004101261 754     .1318042
    22950 22813    .006789475213736296 -.004101261 754    .09821142
    22950 17345    .004352183546870947 -.004101261 754    .07794537
    22950 14201    .009724464267492294 -.004101261 754    .12146398
    22950 15862     .02401369996368885 -.004101261 754    .21945104
    22950 15657   -.001468503032810986 -.004101261 754    .02493856
    22950 80200     .00999374408274889 -.004101261 754    .12353744
    22950 16253  -.0043002585880458355 -.004101261 754  .0018357454
    22950 63715    .019456811249256134 -.004101261 754    .19066396
    22950 27909    .007968120276927948 -.004101261 754    .10769562
    22950 13407    .021897736936807632 -.004101261 754     .2063429
    22950 86128    .046734701842069626 -.004101261 754    .33702815
    22950 19100   -.005495326593518257 -.004101261 754   .012719973
    22950 16648    .004946070723235607 -.004101261 754    .08296701
    22950 75405    .007601364050060511 -.004101261 754     .1047659
    22950 83219    .008486082777380943 -.004101261 754     .1118007
    22950 20233  -.0020018278155475855 -.004101261 754    .01978673
    22950 12759    .008766458369791508 -.004101261 754    .11400709
    22950 92052   .0069712926633656025 -.004101261 754    .09968758
    22950 13612   -.000340035097906366 -.004101261 754   .036012825
    22950 19382   -.003441029926761985 -.004101261 754   .006139269
    22950 13840    .010309306904673576 -.004101261 754    .12595487
    22950 12662    .012658316642045975 -.004101261 754     .1435392
    22950 16066    -.03317532688379288 -.004101261 754    .21179187
    22950 91713     .02408185414969921 -.004101261 754    .21986605
    22950 75320    -.01251201145350933 -.004101261 754    .07212516
    22950 32062     .02315792255103588 -.004101261 754     .2142021
    22950 44134    -.06813926249742508 -.004101261 754    .37179404
    22950 21079                      0 -.004101261 754    .03939684
    22950 88264   -.018867995589971542 -.004101261 754    .12008477
    22950 81044    .031350865960121155 -.004101261 754    .26173177
    22950 19053  -.0021767597645521164 -.004101261 754   .018108178
    22950 14202    .004348707385361195 -.004101261 754    .07791582
    22950 21840   .0019890107214450836 -.004101261 754     .0574065
    22950 12633   -.005176003091037273 -.004101261 754   .009835002
    22950 22667   .0059524462558329105 -.004101261 754    .09135274
    22950 90077    -.02099047601222992 -.004101261 754    .13501464
    22950 14958    .006911044009029865 -.004101261 754    .09919896
    22950 12065    .000822325237095356 -.004101261 754    .04692545
    22950 14046   -.030303090810775757 -.004101261 754     .1949478
    22950 12367     .04219090938568115 -.004101261 754     .3164364
    22950 21911    .002532985992729664 -.004101261 754    .06221497
    22950 13878    .020270250737667084 -.004101261 754    .19595735
    22950 88937     .05330881476402283 -.004101261 754    .36471665
    22950 14225   -.000052484840125544 -.004101261 754    .03887307
    22950 20342   -.010944352485239506 -.004101261 754    .05948155
    22950 22186    -.00925925001502037 -.004101261 754    .04550076
    22950 13836    .007931678555905819 -.004101261 754    .10740537
    22950 22716    .014182922430336475 -.004101261 754    .15457843
    22950 15374    .013207602314651012 -.004101261 754     .1475495
    22950 13326     .01900816150009632 -.004101261 754     .1877145
    22950 13634    .013886390253901482 -.004101261 754    .15245368
    22950 13380     .00591713422909379 -.004101261 754     .0910611
    22950 44230    .015122858807444572 -.004101261 754    .16124354
    22950 78034     .04312671720981598 -.004101261 754     .3207813
    22950 16557   -.000992086250334978 -.004101261 754   .029584887
    22950 15685   .0035087100695818663 -.004101261 754    .07071809
    22950 14643    .019455265253782272 -.004101261 754    .19065385
    22950 90664   -.014406341128051281 -.004101261 754    .08695712
    22950 15195  -.0008080992847681046 -.004101261 754   .031390544
    22950 78975    -.07656142860651016 -.004101261 754     .4010799
    22950 12066    .015679363161325455 -.004101261 754    .16514044
    22950 22127 -.00001004371097224066 -.004101261 754    .03929657
    22950 28629     .03274555876851082 -.004101261 754    .26925594
    22950 92408    .005334809888154268 -.004101261 754     .0862245
    22950 20668   .0012602964416146278 -.004101261 754    .05088723
    22950 14348   .0019130040891468525 -.004101261 754    .05673071
    22950 77643    .002092031529173255 -.004101261 754    .05832094
    22950 77071   .0008466786239296198 -.004101261 754    .04714661
    22950 19838                      0 -.004101261 754    .03939684
    22950 85020   -.004119789227843285 -.004101261 754 .00017120724
    22950 90298   -.012793164700269699 -.004101261 754    .07435687
    22950 18388    .013078433461487293 -.004101261 754    .14660983
    22950 16108     .05063286051154137 -.004101261 754     .3537301
    22950 13116   -.005864735227078199 -.004101261 754    .01603654
    22950 84207   -.004981798119843006 -.004101261 754   .008072171
    22950 19601    .008501586504280567 -.004101261 754      .111923
    22950 18655                      . -.004101261 754            .
    22950 92919   -.009066860191524029 -.004101261 754    .04387807
    22950 18828     .04105691984295845 -.004101261 754     .3110963
    22950 23490    .008453860878944397 -.004101261 754    .11154643
    22950 23799    -.01115240529179573 -.004101261 754    .06117935
    22950 92471    .026177942752838135 -.004101261 754    .23241778
    22950 54244     .03784573823213577 -.004101261 754     .2955117
    22950 22931    .011675103567540646 -.004101261 754    .13626584
    22950 14786    .005639047361910343 -.004101261 754     .0887578
    22950 12566  -.0034723016433417797 -.004101261 754   .005846784
    22950 88216    -.01042875461280346 -.004101261 754    .05524747
    22950 16617   .0016891473205760121 -.004101261 754    .05473472
    22950 13797    -.03308681771159172 -.004101261 754    .21128336
    22950 14435    .015141365118324757 -.004101261 754     .1613737
    22950 90767    .013346881605684757 -.004101261 754    .14856039
    22950 15265    .006400458514690399 -.004101261 754     .0950367
    22950 17135    .006349199917167425 -.004101261 754    .09461673
    22950 93318    .016786573454737663 -.004101261 754     .1727869
    22950 79698     .07644404470920563 -.004101261 754     .4461224
    end
    format %td date
    format %tm time_avail_m


    Code:
    // Calculate Salience
    gen Salience = abs(ret - Mktrt) / (abs(ret) + abs(Mktrt) + 0.1)
    
    // Assign a rank to each trading date by Salience in each month
    egen Slncrk = rank(-Salience), by(permno time_avail_m)
    
    // Calculate the number of trading days in each month
    egen Dsct = count(Slncrk), by(permno time_avail_m)
    
    ** Calculate the number of trading days from high Salience Payoff day to the end of the month
    gen Recency = Dsct - Slncrk + 1
    
    // Calculate salience weight
    gen Wt_temp = 0.7 ^ Slncrk
    egen Wt_denominator = total(Wt_temp), by(Dsct)
    gen Wt = Wt_temp / Wt_denominator
    drop Wt_temp Wt_denominator
    
    ** Calculate the covariance manually
    bysort permno time_avail_m: egen Mean_ret = mean(ret)
    bysort permno time_avail_m: egen Mean_Wt = mean(Wt)
    bysort permno time_avail_m: egen CovProduct = sum((ret - Mean_ret) * (Wt - Mean_Wt)) if _N > 1
    bysort permno time_avail_m: egen N = total(_N) if _N > 1
    
    gen STV = CovProduct / (N - 1)
    
    drop Mean_ret Mean_Wt CovProduct N
    
    // Collapse to monthly data
    collapse (mean) STV Recency, by(permno time_avail_m)

  • #2
    Hi Peter,
    have you solved this problem?
    I am performing a very similar analysis and I am struggling to calculate ST values that yield return predictions similar to all the papers.

    Best, Florian

    Comment

    Working...
    X