Announcement

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

  • Help with panel data and lag

    Gidday! Hope someone can help me.

    I have created a lag in my panel data (strongly balanced) using the following command

    gen BVpshare_L1= BVpshare[_n-1]
    However, when I browse the data using

    br companyid BVpshare BVpshare_L1
    I get a lag of 1 year from the last panel (companyid ) in the first year of the next panel (companyid)

    How do I ensure that the last year of data is not lagged to the first year of the next panel?

  • #2
    Easier and more accurate if you use Stata's panel data features:

    Code:
    xtset companyid year
    gen BVpshare_L1= L.BVpshare

    Otherwise, group by company and sort by year when generating the variable:

    Code:
    bys companyid (year): gen BVpshare_L1= BVpshare[_n-1]

    Note that in the above, the previous year may not necessarily be the current year minus one if you have holes in the panels.
    Last edited by Andrew Musau; 13 May 2022, 03:47.

    Comment


    • #3
      Thank you Andrew! That has done the trick!

      Comment

      Working...
      X