Bookmark and Share

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: Generating days eligible when eligibility changes over time


From   "Brill, Robert" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: Generating days eligible when eligibility changes over time
Date   Fri, 7 Mar 2014 00:19:44 +0000

Hi Listers,

I¹m working on a project in which I am generating an ³intended dosage²
variable equal to the number of days that a person was
eligible for a cash grant program.  In short, I¹d like to know how many
days a child was eligible for the program between the program start and
the survey date. Eligibility is based on being under an age cutoff. The
government in question, however, changed the eligibility age 4 times over
the course of the period of interest (1998-2010).

The program began on 01jan1998, and was available to children under 7. On
01apr2003 the eligibility was increased to 9, on  01jan2004 to 11, on
01jan2005 to 14, on 01jan2008 to 15, and on 01jan2010 to 18.

Therefore, if an individual turned 7 after the first eligibility change
occurred, she was eligible from the beginning of the program in 1998 until
the date of the survey in 2010. However, if she turned 7 before the
change, she is only eligible for the number of days from the beginning of
the program until the date she turned 7. It¹s also possible  that a
different child with a different birthday would fluctuate back and forth
in eligibility as the changes occurred (depending on her birthday,
obviously).

To generalize to all cases, I¹ve considered generating a dose variable for
each of the periods (1998-2003, 2003-2004, 2004-2005, 2005-2008, and
2008-2010) which uses if and if else statements to take all of the types
of cases into account when subtracting birthdays and eligibility change
days etc., or, alternatively, generating a couple hundred month indicators
(or a few thousand days) that are 1 if an individual was eligible in that
month (or day), then calculating the row total to tell me the number of
months (or days) eligible.

However, I¹d much prefer to have a fully accurate measure to the day, and
it seems a bit too crazy to generate all of those indicators when there¹s
likely another way, but I haven¹t been able to think my way out of my
current funk.  

The variable ³birthday² is a %td formatted individual birthday. ³turned7²
is the date that the individual turned 7 (and exists for each age,
turned9, etc.).

Right now, the code looks like:


** Input some example data
input str9 birthday str9 turned7 str9 turned9 str9 turned11
06sep1995 05sep2002 05sep2004 05sep2006
06dec1994 05dec2001 06dec2003 05dec2005
23oct1995 22oct2002 22oct2004 22oct2006
01dec1994 30nov2001 01dec2003 30nov2005
08sep1994 07sep2001 08sep2003 07sep2005
26jun1995 25jun2002 25jun2004 25jun2006
10nov1995 09nov2002 09nov2004 09nov2006
12feb1994 11feb2001 12feb2003 11feb2005
16nov1995 15nov2002 15nov2004 15nov2006
10feb1994 09feb2001 10feb2003 09feb2005
01sep1994 31aug2001 01sep2003 31aug2005
26oct1994 25oct2001 26oct2003 25oct2005
21nov1994 20nov2001 21nov2003 20nov2005
03nov1994 02nov2001 03nov2003 02nov2005
10mar1994 09mar2001 10mar2003 09mar2005
31oct1994 30oct2001 31oct2003 30oct2005
08aug1994 07aug2001 08aug2003 07aug2005
21dec1994 20dec2001 21dec2003 20dec2005
10may1994 09may2001 10may2003 09may2005
19apr1994 18apr2001 19apr2003 18apr2005
05nov1994 04nov2001 05nov2003 04nov2005
18dec1995 17dec2002 17dec2004 17dec2006
24may1995 23may2002 23may2004 23may2006
15aug1994 14aug2001 15aug2003 14aug2005
05apr1995 04apr2002 04apr2004 04apr2006
end

** format inputted data
foreach v of varlist *{
g td`v'=date(`v', "DMY")
drop `v'
rename td`v' `v'
format `v' %td
}


**generate dose by period vars

forval i=1/5 {
    g p`i'dose=.
    }


** use a bunch of if/else statements to generate dosage by period to be
summed later
foreach e in 7  {
        local start "mdy(01,01,1998)"
        local p1 "mdy(04,01,2003)"
        local p2 "mdy(01,01,2004)"
        local p3 "mdy(01,01,2005)"
        local p4 "mdy(01,01,2008)"
        local p5 "mdy(01,01,2010)"
        
        if turned7>`p1' {
            replace p1dose=`p1'-birthday
        }
        
        else if turned7<`p1' & birthday>`start' {
            replace p1dose=turned7-birthday
        }
            
        else if turned7<`p1' & birthday<`start' {
            replace p1dose=turned7-`start'
        }

        if turned9>`p2¹ & turned7>`p1¹ {
            replace p2dose=`p2¹-`p1¹
        }
        
        else if turned9<`p2¹ & turned9>`p1¹ {
            replace p2dose=turned9-`p1¹
        }
** etc etc etc



Or alternatively, the code could look like


forval m=1/12 {

forval y=1998/2012 {

    if `y¹<2003 { //this has a problem because of the april thing but you
get the idea
        g drop`m¹`y¹=(((mdy(`m¹,01,`y¹)-birthday)/365.25)<7)
        }

    else if  `y¹ >2002 & `y¹<2005 {
** etc etc etc
}



While I¹m not entirely opposed to doing one of these ways, I¹m wondering
if there is some obvious or less-obvious way to go through this in a more
efficient way or that perhaps requires less opaque code.

Any hints, tips, or tricks are very welcome and will be received with
extreme gratitude, I¹ve been banging my head against a wall on this for a
while now and would love to hear new perspectives on the problem.


Thanks greatly for your time, and for all the great help that I¹ve gotten
in the past by searching the archive.

Best,

Rob

--
Rob Brill
Research Associate
Child and Family Research Partnership
Lyndon B Johnson School of Public Affairs | The University of Texas at
Austin
(512) 471-3125



*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index