Hi, I have monthly data on participation in a program from 2017-2019, and I would like to construct spell measures. I am using tsspell, but I am having trouble correctly defining conditions that yield what I want. The example data contains 4 individuals. I have id 1 and 4 who enter the program and never exit over the sample period; id 2 who enters and exits; and id 3 who only exits. My goal is to specify a tsspell condition that only measures spells for people like id 2 who both enter and exit over the period.
First, I declare panel data and specify the condition that defines the beginning of a spell:
where a spell begins when the individual enters the program following inactivity in the previous month. However, this is not sufficient because some observations, such as id 1 and 4, enter the program and never come off over the sample period. I do not want to count these as spells! I only want to define a spell for observations that, like id 2, enter and exit the program over the sample. I believe I need to use the cond command to define the end condition (i.e., active==1 & active[_n+1] = 0) as well, but I cannot figure out how to specify both conditions with the tsspell function.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input long id int year byte month float modate double active 1 2019 1 708 0 1 2019 2 709 0 1 2019 3 710 0 1 2019 4 711 0 1 2019 5 712 0 1 2019 6 713 0 1 2019 7 714 0 1 2019 8 715 1 1 2019 9 716 1 1 2019 10 717 1 1 2019 11 718 1 1 2019 12 719 1 2 2018 1 696 0 2 2018 2 697 0 2 2018 3 698 0 2 2018 4 699 0 2 2018 5 700 0 2 2018 6 701 0 2 2018 7 702 0 2 2018 8 703 0 2 2018 9 704 0 2 2018 10 705 0 2 2018 11 706 0 2 2018 12 707 1 2 2019 1 708 1 2 2019 2 709 1 2 2019 3 710 1 2 2019 4 711 1 2 2019 5 712 1 2 2019 6 713 1 2 2019 7 714 0 2 2019 8 715 0 2 2019 9 716 0 2 2019 10 717 0 2 2019 11 718 0 2 2019 12 719 0 3 2017 1 684 1 3 2017 2 685 1 3 2017 3 686 1 3 2017 4 687 1 3 2017 5 688 1 3 2017 6 689 1 3 2017 7 690 1 3 2017 8 691 1 3 2017 9 692 1 3 2017 10 693 1 3 2017 11 694 1 3 2017 12 695 1 3 2018 1 696 1 3 2018 2 697 1 3 2018 3 698 1 3 2018 4 699 1 3 2018 5 700 1 3 2018 6 701 1 3 2018 7 702 1 3 2018 8 703 1 3 2018 9 704 1 3 2018 10 705 1 3 2018 11 706 1 3 2018 12 707 1 3 2019 1 708 1 3 2019 2 709 1 3 2019 3 710 0 3 2019 4 711 0 3 2019 5 712 0 3 2019 6 713 0 3 2019 7 714 0 3 2019 8 715 0 3 2019 9 716 0 3 2019 10 717 0 3 2019 11 718 0 3 2019 12 719 0 4 2018 1 696 0 4 2018 2 697 0 4 2018 3 698 0 4 2018 4 699 0 4 2018 5 700 0 4 2018 6 701 0 4 2018 7 702 1 4 2018 8 703 1 4 2018 9 704 1 4 2018 10 705 1 4 2018 11 706 1 4 2018 12 707 1 4 2019 1 708 1 4 2019 2 709 1 4 2019 3 710 1 4 2019 4 711 1 4 2019 5 712 1 4 2019 6 713 1 4 2019 7 714 1 4 2019 8 715 1 4 2019 9 716 1 4 2019 10 717 1 4 2019 11 718 1 4 2019 12 719 1 end format %tm modate
Code:
xtset id modate ssc install tsspell tsspell active, fcond((active==1 & active[_n-1]==0))
Comment