Statalist


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

st: RE: Egen command


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Egen command
Date   Tue, 19 Aug 2008 18:33:23 +0100

You should keep away from -egen, count()-. 

What does the help say? 

count(exp) (allows by varlist:) creates a constant (within varlist)
containing the number of nonmissing observations of exp.  

Your exp (i.e. expression) is -pillcount-. So you are counting whether
-pillcount- is non-missing. 1 is non-missing. 0 is non-missing. Any
other non-missing value is non-missing. All observations with any of
these non-missing values will be counted. 

That is, I gather, not at all what you want. 

I am less able to work out precisely what you do want. I could make some
guesses but I think it is better if you explain. Do remember that many
of us are not biostatisticians or medics and so, like me, may be fuzzy
on what on earth compliance is. 

Your examples do not include any with data for the key variable
-pillcount-. 

Nick
[email protected] 

Ziad El-Khatib

I have cohort dataset monitoring patients' compliance to drugs over 11
time points (weeks 2, 4, 8, 12, 16, 20, 24, 36, 52, 78 and 104 after
starting on drugs).
I want to look at the persistence of their compliance over weeks 2-24
versus 36-104, i.e. OR of not missing any pill at all over all this
visits between weeks 2-24 versus 36-104.

At every visit I coded pillcount as 0/1: 1 if patient was not
compliant versus 0: if patient was compliant.

Now trying to create pc2_24 for weeks 2 to 24, and pc36_104 for week
36 to 104 to code them as 0/1 (compliant/not compliant).

I tried
egen pc2_24=count(pillcount),by(studyid), if visit>0&visit<25

So got

studyid	visit	pc2_24
1003	2	1
1003	4	1
1003	8	1
1003	12	1
1003	16	1
1003	20	1
1003	24	1
1005	2	1
1005	4	1
1005	8	1


But I want the result to look like:
studyid	visit	pc2_24
1003	2	
1003	4	
1003	8	
1003	12	
1003	16	
1003	20	
1003	24	1
1005	2	
1005	4	
1005	8	
1005	12	
1005	16	
1005	20	
1005	24	1


so only to show number 0 or 1 at the last visit, whether visit number
24, 20 , or else that is <24


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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