Hi guys,
I guess this is a problem of general interest, that many Stata-beginners face.
Let's assume I have panel data.
1. At the beginning, I xtset the data (e.g. xtset company_id month_id)
2. Later on, I have to re-sort the data (e.g. sort month_id company_id)
3. Re-sort the data again, back to the initial sorting (e.g. sort company_id month_id)
The issue is, that at step 3, Stata does not get that data is panel data identified by company_id month_id, just as in step 1. Or am I wrong?
This would mean, that e.g. for lag operators (e.g. l1.month_id / lag1.month_id) Stata might ignore the panel data structure and refer to a previous month of a different company_id.
So essentially, do I have to use xtset before each lag command?
Maybe a better example:
Would my lag-operator now refer to a previous month of a different company,
or would it understand not to go beyond company borders?
Best regards,
Carlos
I guess this is a problem of general interest, that many Stata-beginners face.
Let's assume I have panel data.
1. At the beginning, I xtset the data (e.g. xtset company_id month_id)
2. Later on, I have to re-sort the data (e.g. sort month_id company_id)
3. Re-sort the data again, back to the initial sorting (e.g. sort company_id month_id)
The issue is, that at step 3, Stata does not get that data is panel data identified by company_id month_id, just as in step 1. Or am I wrong?
This would mean, that e.g. for lag operators (e.g. l1.month_id / lag1.month_id) Stata might ignore the panel data structure and refer to a previous month of a different company_id.
So essentially, do I have to use xtset before each lag command?
Maybe a better example:
Code:
xtset company_id month_id sort company_id month_id generate var2 = l1.var1
or would it understand not to go beyond company borders?
Best regards,
Carlos

Comment