| |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: Simple programming question?
You may want to consider to reshape your data, perhaps like this:
clear
input id day1 day2 day3 day4 day5 day6
1 0 0 0 1 0 0
2 0 0 0 0 1 1
3 1 1 1 1 1 1
4 0 0 0 0 0 0
end
reshape long day, i(id) j(time)
rename day failure
rename time day
In this format, it would be relatively easy to identify the first day of
failure for each person (id), for example by:
bys id: egen dayff = min(day) if failure==1
label var dayff "Day of first failure"
Depending on what data structure you desire, you could reshape back to
wide-format, or collapse by person, for example:
collapse dayff, by(id)
HTH,
Philipp
Anderson, Bradley J wrote:
Though I seem to be too simple to figure it out.
I have data like the following:
id day1 day2 day3 day4 day5 day6 ... day90
1 0 0 0 1 0 0 ... 0
2 0 0 0 0 1 1 ... .
3 1 1 1 1 1 1 ... 1
4 0 0 0 0 0 0 ... 0
Assume that a 1 on day`i' represents failure. I'm trying to generate a
variable that gives days to failure for survival analysis. E.g., subject 1
failed on day 4, subject 5 failed on day 5, subject 3 failed on day 1,
subject 4 did not fail and would be considered censored. 90 days worth of
data were collected but not all subjects were observed for the full 90-day
period. Also note that subjects may be recorded as failing (drinking at
hazardous levels) on any combination of days during the 90-day period. I'm
trying to calculate number of days to first failure. Seems like it should
be simple but I'm sufficiently naive that I've not solved it. Thanks.
Brad
-----Original Message-----
From: [email protected]
[mailto:[email protected]]On Behalf Of Nick Cox
Sent: Tuesday, October 17, 2006 1:16 PM
To: [email protected]
Subject: st: RE: Manipulating variables with repeated observations
You should find out about -by:-.
For example:
bysort MRN (VisitDate) : gen visit = _n
by MRN : gen change = BMI[_N] - BMI[1]
Nick
[email protected]
Karen R. Fl�rez
I have a dataset with kids BMIs that looks like this:
MRN VisitDate BMI
123 10/20/04 30
123 6/11/05 25
123 4/14/06 25
222
222
222
Where MRN is the unique identifier. Kids had different visits at
different times and BMI were take at each time. How can I generate
a variable that codes for Visit 1,2,3,etc? So that I can measure
the change between baseline and last follow-up?
*
* 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/
*
* 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/