Statalist The Stata Listserver


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

Re: st: Re: programming assist, too many unique values forlevels


From   "Andrew O'Connor DO" <[email protected]>
To   <[email protected]>
Subject   Re: st: Re: programming assist, too many unique values forlevels
Date   Tue, 01 May 2007 16:25:36 -0400

thank you
Andrew O'Connor, DO, MPH
Division of Nephrology
Center for Healthcare Research and Policy
MetroHealth Medical Center/Case Western Reserve University
(216)778-8484
>>> [email protected] 05/01/07 4:19 PM >>>
You don't need the levels command or the loops at the end, just use
-egen- 
commands:

egen time=sum(obstime), by(pt)
egen time_out=sum(out_range), by(pt)
gen bphigh=bp_systolic >= `threshold' & bp_systolic !=.
egen proportion=mean(bphigh), by(pt)

I think the above code should replace about 25 lines of your code. 
Note, I used 
egen sum(), but egen total() is a newer synonym, as is moving the -by-
to a 
prefix, but it will work fine as shown.

Michael Blasnik


----- Original Message ----- 
From: "Andrew O'Connor DO" <[email protected]>
To: <[email protected]>
Sent: Tuesday, May 01, 2007 2:54 PM
Subject: st: programming assist, too many unique values for levels


<snip>
> I've run into a problem due to the size of my data set, specifically
> that I have too many levels.  Here is my code
<snip>
> gen time=.
>
> levels pt, local(levels)
> quietly foreach l of local levels {
> sum obstime if pt==`l'
> local total=r(sum)
> replace time=`total' if pt==`l'
> }
> gen time_out=.
> quietly foreach l of local levels {
> sum out_range if pt==`l'
> local total =r(sum)
> replace time_out=`total' if pt==`l'
> }
> gen time_o_r=(time_out/time)
> local threshold = 140
>  gen proportion=.
> levels pt, local(levels)
> quietly foreach l of local levels {
>   count if pt == `l' & bp_systolic !=.
>    local total =r(N)
>    count if bp_systolic >= `threshold' & bp_systolic !=. & pt == `l'
>    replace proportion = r(N)/`total' if pt == `l'
> }
> Any suggestions for using a different set of programming statements???
> Thanks,
> AO
>

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