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   "Andrew O'Connor DO" <[email protected]>
To   <[email protected]>
Subject   Re: st: RE: Using Stata to calculate proportion of observation
Date   Thu, 26 Apr 2007 11:34:49 -0400

Thanks!!!  Looks like it worked, now just have to modify for my (much)
larger dataset
AO

>>> [email protected] 04/26/07 10:57 AM >>>

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


The MetroHealth System: Saving lives in Northeast Ohio for 170 
years as the region's leader in critical care, community health 
and rehabilitation.  Visit us at http://www.MetroHealth.org for 
a complete list of services, health care providers, and 
locations.

This email and all attachments that may have been included are 
intended only for the use of the party to whom/which the email 
is addressed and may contain information that is privileged, 
confidential, or exempt from disclosure under applicable law. 
If you are not the addressee or the employee or agent of the 
intended recipient, you are hereby notified that you are 
strictly prohibited from printing, storing, disseminating, 
distributing, or copying this communication. If you have 
received this notification in error, please contact the 
Director of Risk/Privacy Management at (216)778-5728. For a copy 
of our Notice of Privacy Practices, please visit: 
http://www.metrohealth.org/general/privacy.asp 

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