Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Tracking attrition in a long-shaped dataset


From   Max <maxliving@gmail.com>
To   statalist <statalist@hsphsun2.harvard.edu>
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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index