Statalist The Stata Listserver


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

Re: st: RE: Using Stata to calculate proportion of observation


From   [email protected]
To   [email protected]
Subject   Re: st: RE: Using Stata to calculate proportion of observation
Date   Thu, 26 Apr 2007 09:57:10 -0500

----- Original Message -----
From: Andrew O'Connor DO <[email protected]>
Date: Thursday, April 26, 2007 8:09 am
Subject: Re: st: RE: Using Stata to calculate proportion of observation
	time above	a threshold value i.e. "ti
To: [email protected]

> Thanks for your help Scott,
> This is sort of what I was looking for, but rather than 
> calculating the
> predicted values for missing data, I'm trying to use the available 
> datato measure the proportion of each individuals observation time 
> (eachperson has a variable number of observations and a variable 
> total period
> (calendar days) of observation) that their blood pressures were 
> above a
> set threshold.  
> Put another way, if time is on the X axis, Systolic BP on the Y 
> axis, I
> can easily draw a graph with connected BP's over time.  Now if I 
> draw a
> horizontal line at say 140 on the y axis, how do I calculate the
> proportion of the total period of observation that blood pressures 
are
> above the threshold value.  
> Thanks again
> AO 
> 

How about this:

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]

//Create a variable with the proportion above threshold
   local threshold = 140
   gen proportion=.
   levelsof pt, local(levels)
   foreach l of local levels {
   	count if pt == `l' & bp !=.
	local total =r(N)
	count if bp > `threshold' & bp !=. & pt == `l'
	replace proportion = r(N)/`total' if pt == `l'
} 
l, sepby(pt) ab(20)	

//Creating a results dataset
tempname memhold
tempfile results
postfile  `memhold' id proportion using `results'
foreach l of local levels {
   	count if pt == `l' & bp !=.
	local total =r(N)
	count if bp > `threshold' & bp !=. & pt == `l'
	local proportion = r(N)/`total'
	post  `memhold' (`l') (`proportion')
} 
postclose `memhold'
preserve
use `results',clear
l, ab(20)
restore



Scott

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