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: Fw: Event within dates


From   David Kpento <dkpento@yahoo.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: Fw: Event within dates
Date   Sat, 3 Dec 2011 17:43:45 +0000 (GMT)

I have prescription data in panel format for analysis. I wish to generate an indicator rs to be 1 for any subject who took drug2 within 56 days of taking drug1 (either before or after) as shown in sample data. I have done a code below but it generates rs to be 0. I have look at some examples on the Stata list without success. Please user somebody should have a look at the code for me. This is for my PhD.

 
I use Stata/SE 9.0 for Windows.

Many thanks
 
David
clear
input id str9 date drug rs
1 08apr2009 1 0 
1 08may2009 1 0
1 08jun2009 2 1
2 02jan2009 1 0
2 28jan2009 2 1
2 05apr2009 1 0
3 07jan2009 2 1
3 22mar2009 1 0
3 02jul2009 1 0
end
 
I have a code like this after formatting the date into a Stata date but rs1 is all zeros.
 
g rs1=0

forval i = 1/`=_N' {
        forval j = 1/`=_N' {
            replace rs1=1 if drug[`i']==1 & id[`i']==id[`j'] & ///
       drug[`j'] ==2 & inrange(date[`i'] - date[`j'], -56,56) in `i'
        }
}

}


*
*   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