Announcement

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

  • Panel Data using lagged variable

    I have a question regarding the correct code for creating a lagged variable. It seems that the two versions generate different results.
    I have a panel data- company id is my cross sectional variation and year is my time series variation.
    I am trying to compute book leverage using total assets from a previous year. This is just for illustration purposes. My variable names are different.
    Here are the two versions of the code. The first version is:
    Code:
    xtset companyid fyear, year
    gen lTA = l.TA
    gen Book_Leverage=total_debt/lTA
    The second version is:
    Code:
    xtset companyid fyear, year
    gen Book_Leverage=(total_debt)/(TA[_n-1])
    Which code is correct. To me it seems like the second version of the code is giving slightly different results.
    Thanks much!

  • #2
    The two codes will produce equivalent results if, and only if, there are no gaps in the data. The time series operator l. is programmed so that it returns only the value of TA in the immediately preceding year. If there is no observation for the immediately preceding year, then l.TA returns missing value. By contrast, TA[_n-1] returns the value of TA in whatever observation happens to precede the current observation in the data set. If there is a gap in the time series, that value represents the value of TA in some year earlier than the immediately preceding year and is, therefore, not the one-year lag.

    tl;dr Use l.TA as it is always correct; TA[_n-1] is only correct under strong conditions.

    Comment

    Working...
    X