Statalist The Stata Listserver


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

RE: st: data formatting question


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: data formatting question
Date   Tue, 14 Feb 2006 09:50:39 -0000

Or if you wish to keep all the observations in the data: 

bysort ID : gen ABC = sum(A) & sum(B) & sum(C) 
by ID : replace ABC = ABC[_N] 

Nick 
[email protected] 

Philip Ryan
 
> If you don't wish to -reshape-, then the following is a possibility:
> 
> bysort id: gen temp = (sum(A) & sum(B) & sum(C))
> 
> bysort id: egen ABC = max(temp)
> 
> drop temp
 
> At 07:21 PM 13/02/2006 -0800, you wrote:
> >To clarify my question, here is a new example:
> >I would like to know if a patient is taking all 3
> >medications, A, B & C.  The data is formatted so that
> >each medication forms a new row.
> >
> >ID#  A   B   C   D   E
> >1    0   1   0   0   0
> >1    1   0   0   0   0
> >1    0   0   1   0   0
> >2    0   1   0   0   0
> >2    0   1   0   0   0
> >
> >I would like to identify all patients who take all 3
> >medications A, B, and C such as patient 1.
> >
> >
> >--- Nick Cox <[email protected]> wrote:
> >
> > > It seems that "without success" is a new variant on
> > > that
> > > old Statalist standby "doesn't work"! You don't say
> > > what you mean by it.
> > >
> > > These are all legal commands if the data have
> > > been sorted previously by -countrynumber-.
> > >
> > > But the first says: within categories of
> > > -countrynumber-, -gen new_var- with
> > > values of 0. You might as well have said
> > >
> > > gen new_var == 0
> > >
> > > as the -by:- prefix makes no difference
> > > to the result.
> > >
> > > The same comment applies to the second.
> > >
> > > Please specify a numerical example showing
> > > what you want.
> > >
> > > Nick
> > > [email protected]
> > >
> > > Andy Choi
> > >
> > > > Using this same example from previous emails is
> > > there
> > > > a command that would sort by country number when
> > > > defining a new variable?
> > > >
> > > > For example, I have tried something like this
> > > without
> > > > success:
> > > > by countrynumber: gen new_var=0
> > > > by countrynumber: replace new_var=1 if
> > > year=="1930" &
> > > > ethnicity=="Hispanic"
> > > > I want the end result to be 0 or 1 for each unque
> > > > country number value.
> > > >
> > > >
> > > > > Country Number    year    ethnicity       ethnicpop
> > > > > 10                1930    Caucasion       1,000,000
> > > > > 10                1930    Hispanic        50,000
> > > > > 10                1931    Caucasion       1,000,100
> > > > > 10                1931    Hispanic        51,000
> > > > > 11                1931    Asia            10,000
> > > > >
> > > > > I want to set up the data so there is only one
> > > entry
> > > > > per country per year,
> > > > > as follows:
> > > > >
> > > > > Country Number    year    ethnic1    ethnic2   ethpop1
> > >
> > > > > ethpop2
> > > > > 10                1930    Caucasian  Hispanic  
> 1,000,000  50,000
> > > > >

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