Statalist


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

RE: st: Code to generate variable indicating date that CD4 drops below 250


From   "Polis, Chelsea B." <[email protected]>
To   "[email protected]" <[email protected]>
Subject   RE: st: Code to generate variable indicating date that CD4 drops below 250
Date   Tue, 31 Mar 2009 17:12:33 -0400

Many thanks to everybody for the suggestions!  I can't express how grateful I am that this group exists, and is so active.

My dates were originally in long format, and I sorted them by chronological order before reshaping them wide and describing them in my post.  I was able to use Michael Lichter's very elegant solution to create the variable I needed.

Thanks to all!

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Michael I. Lichter
Sent: Tuesday, March 31, 2009 2:25 PM
To: [email protected]
Subject: Re: st: Code to generate variable indicating date that CD4 drops below 250

Assuming that your visitdate variables are sorted from earliest to
latest, how's this?

gen firstdrop = .
forvalues i = 1/19 {
    replace firstdrop = visitdate`i' if cd4`i' < 250 & first250 == .
}

If they're not sorted you really should go to long format and sort them
(which would be a reasonable idea here too).

-ml

Polis, Chelsea B. wrote:
> Dear Statalisters,
>
> I would like to create a variable in my dataset to indicate the date at
> which a subjects CD4 counts dropped below 250.  My data is currently in
> wide format, and each subject had anywhere from 1 to 19 visits.  For each
> subject, I have up to 19 variables that indicate cd4 count (i.e., cd41 cd42
> cd43 cd44 and so on), and up to 19 variables that indicate visit  date
> (visitdate1 visitdate2 visitdate3 visitdate4 etc.).  I'd like to create a
> variable to indicate the first date at which CD4 count dropped below 250,
> if it ever dropped below 250.
>
> Any suggestions on how to write such a code?
>
> Many thanks,
> Chelsea
>
> *
> *   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/
>

--
Michael I. Lichter, Ph.D.
Research Assistant Professor & NRSA Fellow
UB Department of Family Medicine / Primary Care Research Institute
UB Clinical Center, 462 Grider Street, Buffalo, NY 14215
Office: CC 125 / Phone: 716-898-4751 / E-Mail: [email protected]

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

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index