I have a panel dataset in which dates [date] are nested within periods [prd] within IDs [id]. The periods should always span a 30 day window, and I need a row for each date within that 30-day window. But, as you can see, there are gaps in date, and it does not always include the period's start date and end date. I was going to use tsfill to fill in the gaps, but since there isn't always a row for the start date within a given period, it would only start at the earliest date within a given period that shows up in the dataset.
So, what I'm trying to do is figure out how to insert observations with the values of startdate and enddate for each unique combination of id and prd, if these dates don't already exist for that id-prd combo. Any ideas?
So, what I'm trying to do is figure out how to insert observations with the values of startdate and enddate for each unique combination of id and prd, if these dates don't already exist for that id-prd combo. Any ideas?
Code:
* Example generated by -dataex-. For more info, type help dataex clear input long id float(date prd startdate enddate) 201677 22642 1 22639 22669 201677 22643 1 22639 22669 201677 22644 1 22639 22669 201677 22645 1 22639 22669 201677 22646 1 22639 22669 201677 22647 1 22639 22669 201677 22649 1 22639 22669 201677 22651 1 22639 22669 201677 22652 1 22639 22669 201677 22653 1 22639 22669 201677 22656 1 22639 22669 201677 22657 1 22639 22669 201677 22658 1 22639 22669 201677 22659 1 22639 22669 201677 22665 1 22639 22669 201677 22666 1 22639 22669 201677 22668 1 22639 22669 201677 22669 1 22639 22669 201677 22670 2 22669 22699 201677 22671 2 22669 22699 201677 22673 2 22669 22699 201677 22677 2 22669 22699 201677 22678 2 22669 22699 201677 22680 2 22669 22699 201677 22685 2 22669 22699 201677 22686 2 22669 22699 201677 22688 2 22669 22699 201677 22690 2 22669 22699 201677 22691 2 22669 22699 201677 22698 2 22669 22699 201677 22699 2 22669 22699 201677 22732 3 22735 22765 201677 22733 3 22735 22765 201677 22734 3 22735 22765 201677 22740 3 22735 22765 201677 22741 3 22735 22765 201677 22747 3 22735 22765 201677 22748 3 22735 22765 201677 22754 3 22735 22765 201677 22755 3 22735 22765 201677 22756 3 22735 22765 201677 22757 3 22735 22765 end format %tdNN/DD/YY date format %tdNN/DD/YY startdate format %tdNN/DD/YY enddate
Comment