|
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: Unbalanced panel, count number of incidents
Hi Andy,
I am no expert here, and there is likely to be a much
easier way to do this than what I am suggesting, but this is what I
would do:
I would -reshape- your data from long form to wide
form so that each row is an ID and the responses on each day of contact
become separate variables.
The new form would look like this:
ID Response37200 Var137200 Var237200 Response37210 Var137210 Var237210
1 1 1 1 0 2 1
Before
you do this I suggest dropping any variables you don't need for this
analysis and renaming variables so their names are shorter (e.g.
response to r). Also, if all you are interested in for the analysis are more recent
dates of contact, you can drop all the data for prior dates of contact.
the syntax for reshape is:
reshape wide [varlist], i(id) j(date)
once
you've done that, you can just generate a new variable that sums across
the responses (once counting non-missing responses, and once counting
positive responses).
after doing that, you can easily reshape the data back to long form:
reshape long [varlist], i(id) j(date)
hope that helps,
-Naomi
----- Original Message ----
From: Andrew Stocking <[email protected]>
To: [email protected]
Sent: Sunday, July 22, 2007 3:35:34 AM
Subject: st: Unbalanced panel, count number of incidents
Hello. I have an unbalanced panel of subjects who have been contacted very
irregularly over the past 5 years. Total contacts range from 40-250 during
the 5 year period depending on the person. I'd like to create two
variables: one that counts the total number of contacts in the last 30 or 60
days and a second that sums the number of positive responses over the same
30 or 60 days. For each contact there could be anywhere from 0-15 contacts
in the last 30 days.
My data looks like:
ID Date Response Var1 Var2
1 37200 1 1 1
1 37210 0 2 1
1 37215 1 3 2
1 37229 1 4 3
1 37231 0 4 2
2 37201 0 1 0
.....
I can't make egen count() work for me (or really anything else).
Thanks in advance,
Andy
-----------------------------------
Andrew Stocking
University of Maryland
Ag and Resource Economics
[email protected]
-----------------------------------
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/