Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Using Stata to calculate proportion of observation time above a threshold value i.e. "time in range"


From   "Scott Merryman" <[email protected]>
To   <[email protected]>
Subject   st: RE: Using Stata to calculate proportion of observation time above a threshold value i.e. "time in range"
Date   Wed, 25 Apr 2007 20:52:00 -0500

I don't completely follow this, but if you want the predicted values for
each pt_id you can use -levelsof- and -foreach- to loop through the groups.

Note:  you have repeated time values for pt_id =2, 01 Aug 06.

Perhaps this will help:

clear
input pt_id  str9 appt_date str9 appt_status      bp_systolic
   1         "21 Apr 05"    "No Show"     .
   1       "07 Jun 05"     "Completed"      140
   1     "11 Jan 06"     "Completed"        150
   1       "16 Feb 06"    "Completed"       150
   1       "30 Mar 06"    "Canceled"     .
   1       "02 May 06"   "Canceled"     .
   1       "09 May 06"   "Completed"       138
   1       "11 Jul 06"     "Completed"       142
   1       "19 Sep 06"   "Completed"       150
   2       "30 May 06"   "No Show"    	.
   2       "11 Jul 06"     "Completed"       176
   2       "25 Jul 06"     "Completed"       121
   2       "01 Aug 06"    "Canceled" 	.
   2       "01 Aug 06"    "Completed"      101
   2       "15 Aug 06"    "Completed"      118
   2       "22 Aug 06"    "Canceled"	.
   2       "12 Sep 06"    "Completed"      136
   2       "14 Nov 06"    "Completed"       137
   2       "16 Jan 07"     "Completed"      113
   2        "06 Feb 07"    "No Show"  .
   2        "03 May 06"    "Canceled" .   
   2        "25 Jul 06"      "Canceled" .
   2        "01 Aug 06"    "Canceled"   .
   2        "07 Feb 07"   "Canceled" . 
   end

   gen date = date(appt_d, "dm20y")
   format date %d
   sort pt date appt_s
   by pt (date): drop if date == date[_n+1]
   tsset pt date
   qui {
   gen expect_bp = .
   levelsof pt, local(levels)
   foreach l of local levels {
   	reg bp date if pt == `l'
   	predict foo if pt == `l', xb
   	replace expect = foo if pt == `l'
   	drop foo
   }
   }
   mark tag if expect>140
   l, sepby(pt) ab(20)


Scott


> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Andrew O'Connor DO
> Sent: Wednesday, April 25, 2007 7:32 AM
> To: [email protected]
> Subject: st: Using Stata to calculate proportion of observation time above
> a threshold value i.e. "time in range"
> 
> I'm hoping someone can help me with a data problem (Nik sorry I emailed
> you directly rather than putting on the list).
> 
> A person I work with was able to calculate this in SAS and I'm hopefully
> able to do the same in STATA.  I'm trying to use stata to calculate a
> time in range for blood pressure data
> here is what my data looks like
> ------------------------------
> -----------------------------------------------------------------
> Pt_ID    Appt_date appt_status      bp_systolic
>    1         21 Apr 05    No Show
>    1       07 Jun 05     Completed       140
>    1     11 Jan 06     Completed         150
>    1       16 Feb 06    Completed        150
>    1       30 Mar 06    Canceled
>    1       02 May 06   Canceled
>    1       09 May 06   Completed        138
>    1       11 Jul 06     Completed        142
>    1       19 Sep 06   Completed        150
>    2       30 May 06   No Show
>    2       11 Jul 06     Completed        176
>    2       25 Jul 06     Completed        121
>    2       01 Aug 06    Canceled
>    2       01 Aug 06    Completed       101
>    2       15 Aug 06    Completed       118
>    2       22 Aug 06    Canceled
>    2       12 Sep 06    Completed       136
>    2       14 Nov 06    Completed        137
>    2       16 Jan 07     Completed       113
>    2        06 Feb 07    No Show
>    2        03 May 06    Canceled
>    2        25 Jul 06      Canceled
>    2        01 Aug 06    Canceled
>    2        07 Feb 07    Canceled
> --------------------------------------------------------------------------
> -----------------------------
> Basically I assume a linear slope (interpolated) between successive
> dates, set a threshold, then ask STATA to calculate the proportion of
> total observation time that the curve was above my threshold.
> 
> I think this falls under the cross sectional time series definition.
> Basically what I'm trying to do is each individual (where iis Pt_ID) has
> a unique observation time (tis Appt_date) and a set of observed systolic
> blood pressures (bp_systolic).  There are no set observation times, this
> is observational data.  For each time, I assume a linear slope of blood
> pressure change to the next observation time.  I need to calculate the
> area that the slope measure predicts blood pressure over my threshold
> (say 140 for example).  Slopes can be positive or negative or flat.
> Each individual has a variable number of observations, they are not
> equally spaced, and missing data is a possibility.
> 


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



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index