| |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: Re: programming assist, too many unique values for levels
From |
"Michael Blasnik" <[email protected]> |
To |
<[email protected]> |
Subject |
st: Re: programming assist, too many unique values for levels |
Date |
Tue, 01 May 2007 16:19:24 -0400 |
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/