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]

RE: Re: st: Generating days eligible when eligibility changes over time


From   "Brill, Robert" <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: Re: st: Generating days eligible when eligibility changes over time
Date   Mon, 10 Mar 2014 16:42:33 +0000

Thanks for the help with birthdays--I had used rough code(birthday+(365.25*`age')) to generate the 'turned`age'' variable and your snippet is very helpful to do it correctly. 

The survey date is the date that the individuals were contacted--the dataset is survey, rather than administrative. The goal is to see how much time an child had been eligible between his birth and the date that he was surveyed. 

Also, very embarrassing that I forgot about the branching if in Stata--I had gotten too caught up in the other moving parts of the puzzle. However, I realized that because the dates of eligibility are scalars, there was no need to call to the dataset to branch, but rather to loop over all of the months in each year and branch based on those to generate the indicator variables. 

I also went back and noticed that the program is paid monthly and individuals are paid the benefit in the month of their birthday, so it's only important to find the number of months as a dose (in fact the "actual" dose, rather than the intended dose, is also measured in months)

Here's the code I ended up using: 

forval y=1998/2010 {
forval m=1/12 {	
	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)"
	local date = mdy(`m',01,`y')
	
	if `date'<=`p1' { 
	
	g drop`m'`y'=(((`date'-birthday)/365.25)<7)
	}
	
	else if `date'>`p1' & `date'<=`p2' {
	g drop`m'`y'=(((`date'-birthday)/365.25)<9)
	}
	
	else if `date'>`p2' & `date'<=`p3' {
	g drop`m'`y'=(((`date'-birthday)/365.25)<11)
	}
	
	else if `date'>`p3' & `date'<=`p4' {
	g drop`m'`y'=(((`date'-birthday)/365.25)<14)
	} 
	
	else if `date'>`p4' & `date'<=`p5' {
	g drop`m'`y'=(((`date'-birthday)/365.25)<15)
	}
	
	else if `date'>`p5'  {
	g drop`m'`y'=(((`date'-birthday)/365.25)<18)
	}
	
	}
	}
	
	
egen intdose=rowtotal(drop*)
replace intdose=intdose/12

drop drop*



© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index