Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: Tracking attrition in a long-shaped dataset
From
Max <[email protected]>
To
statalist <[email protected]>
Subject
st: Tracking attrition in a long-shaped dataset
Date
Thu, 21 Mar 2013 10:19:26 -0400
Hi everyone,
I have a long dataset of ID's (people) and months. People enter and leave
the dataset at various points, and can skip months. I want to track
attrition by doing two things:
1. Create a dummy variable = 1 in time t if the person appears in time t+1,
0 otherwise (but missing for the last month). I think I've solved this one,
but am always curious to hear if anyone has any alternate methods that
might be better. Here is my solution:
bysort ID (month): gen returned = 1 if month == month[_n+1] - 1
2. And this is where I'm stuck. I want to create a dummy variable = 1 in
time t if the person appears in time t+2, regardless of whether they appear
in time t+1 or not. I tried:
bysort ID (month): gen returned_2month = 1 if (month == month[_n+2] - 2)
But that didn't work because someone who, say, appears in months 1 and 3
will not have an entry for month[_n+2]. But they should in fact be coded as
a 1.
Does anyone have a good solution?
Thanks,
Max
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/