Statalist


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

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


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: Re: Code to generate variable indicating date that CD4 drops below 250
Date   Tue, 31 Mar 2009 20:58:24 +0200

<>

Here is the full code:

*****
*generate data
clear*
set obs 100
forv i=1/19{
g aux`i'=1+int(50*runiform())
}
cap ssc inst rowsort
rowsort(aux*), gen(visit1-visit19)
drop aux1- aux19
forv i=1/19{
g cd4`i'=150+int(250*runiform())
}
g id=_n
compress
*reshape for analysis
reshape long visit cd4, i(id)
*analysis, first step: when is cd4 below 250?
gen byte below250=cd4<250
*second step as in http://www.stata.com/support/faqs/data/firstoccur.html
bys id (visit): gen noccur = sum(below250)
bys id: gen byte first = noccur == 1  & noccur[_n - 1] != noccur
*get rid of auxiliary vars
drop below250 noccur
*see result
list in 1/50, noo sepby(id)
*****


HTH
Martin
_______________________
----- Original Message ----- From: "Polis, Chelsea B." <[email protected]>
To: <[email protected]>
Sent: Tuesday, March 31, 2009 7:55 PM
Subject: st: Code to generate variable indicating date that CD4 drops below 250


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/


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