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 on April 23, and its replacement, statalist.org is already up and running.


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

st: Counting Number of Program Days


From   Nicole Johnson <njohnson@researchforaction.org>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: Counting Number of Program Days
Date   Tue, 1 Nov 2011 02:45:57 +0000

Hi all,

I have a dataset that is basically set up like an attendance roll book. It has the person’s name and then each variable is a date that the program was held. The person has a 1 if they attended that day. It looks like this:

First                       Last                        A10_01_10          A10_05_10          A10_010_10       A10_11_10
Jane                       Doe                        1                             1                              .                               .
John                      Doe                        .                               1                              0                              1

The records go from October through June, but the program did not meet every day. As noted above, the variable names indicate the date. I was able to use a loop to extract the date of first attendance and last attendance, but I need to now calculate the total number of days the person ‘could’ have attended the program between their date of first attendance and date of last attendance.  SO in the above example I would be able to say that John Doe attended 2 out of 3 possible program days. Of course since the data in my dataset has many more dates, this is much harder! Any help is appreciated. 

I guess I should mention I used the following to calculate some additional variables that may be of use which include string values for date first attended that match the variable names and date values, also the total number of program days. 

Any help is much appreciated – thank you!
Nikki

***Macro to find first date of attendance and create string variable 'firstfound'
local first 1
gen firstfound = ""
foreach v of varlist A10_01_2008-A06_20_2009 {
                replace firstfound = "`v'" if `v' == `first' & missing(firstfound)
}

***Macro to find last date of attendance and create string variable 'lastfound'
local last 1
gen lastfound = ""
foreach v of varlist A10_01_2008-A06_20_2009 {
                replace lastfound = "`v'" if `v' == `last'
}

***Transforming string 'firstfound' into date value first_attend_0809
. gen firstfound1=substr(firstfound, 2, 10)
. generate first_attend_0809=date(firstfound1,"MDY")
. format first_attend_0809 %td

***Transforming string 'lastfound' into date value last_attend_0809
. gen lastfound1=substr(lastfound, 2, 10)
. generate last_attend_0809=date(lastfound1,"MDY")
. format last_attend_0809 %td

local start firstfound
gen days_possible = 0
foreach v of varlist A10_01_2008-A06_20_2009 {
                replace days_possible = days_possible+1
}
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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