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:
The second version is:
Which code is correct. To me it seems like the second version of the code is giving slightly different results.
Thanks much!
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
Code:
xtset companyid fyear, year gen Book_Leverage=(total_debt)/(TA[_n-1])
Thanks much!
Comment