Announcement

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

  • Panel Data: Daily Returns Calculations

    Hello,

    Could you please explain difference between lagged functions and arithmetic calculating daily returns?

    Date Firm ID Close Price
    9/1/2012 1 404
    9/2/2012 1 403
    9/3/2012 1 407
    9/4/2012 1 410
    9/5/2012 1 414
    9/6/2012 1 418
    9/1/2012 2 40
    9/2/2012 2 40
    9/3/2012 2 40
    9/4/2012 2 41
    9/5/2012 2 41
    9/6/2012 2 41
    9/1/2012 3 20
    9/2/2012 3 10
    9/3/2012 3 20
    9/4/2012 3 41
    9/5/2012 3 31
    9/6/2012 3 21

    I did use codes;

    xtset FirmID Date

    and then do both 1 and 2 below

    1. bysort FirmID: generate DailyReturn = (Close[_n] - Close[_n-1]) / Close[_n-1]

    2. bysort FirmID: generate LaggedReturn = (Close - L.Close) / L.Close

    I thought 1 and 2 have same results, but when I use Lagged functions, there are too many omitted variable (missing a lot of observations)

    Could you explain difference between those two?

    PS) Sample given above is what I just did make up.

    Thank you so much!


    Sincerely,

    Patrick

  • #2
    I cannot reproduce your problem. Both commands, as I run them, produce only 3 missing values: the first value is missing, which is to be expected because the lag is undefined at that initial time point.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float date byte firm float close
    19237 1 404
    19238 1 403
    19239 1 407
    19240 1 410
    19241 1 414
    19242 1 418
    19237 2  40
    19238 2  40
    19239 2  40
    19240 2  41
    19241 2  41
    19242 2  41
    19237 3  20
    19238 3  10
    19239 3  20
    19240 3  41
    19241 3  31
    19242 3  21
    end
    format %td dat
    
    xtset firm date
    
    bysort firm (date): generate dailyreturn = (close[_n] - close[_n-1]) / close[_n-1]
    
    generate laggedreturn = (close - l.close) / l.close
    
    list, noobs clean sepby(firm)
    Now, if there are gaps in the date variable in your real data, then -generate laggedreturn = (close - l.close) / l.close- will correctly generate additional missing values in the observation immediately after a gap. So, if your real data has, for example, only trading dates, then there will be a missing value every Monday and the day after every holiday. To resolve that problem you need to set up a business calendar and use business dates instead of regular calendar dates. See -help business calendar- for details.


    In the future, when showing data examples, please use the -dataex- command to do so, as I have here. If you are running version 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Comment


    • #3
      Thank you so much Mr. Schechter for not only answering my questions, but also really valuable advice for future references. I will look over the function, business calendar. You are right: every values dropped come those specific days. Thank you so much again.

      Comment

      Working...
      X