[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: using creat count id on var
This field centres on the use of -by:-.
One attempt at an introductory overview
emphasising the basics very strongly is
How to move step by: step.
Stata Journal 2(1): 86-102 (2002).
This explains the use of the -by:- construct to tackle
a variety of problems with group structure, ranging from
simple calculations for each of several groups to more
advanced manipulations that use the built-in _n and _N.
In addition, many data management and other FAQs
contain examples of -by:-.
In your case, you are over the last ridge and home
is nearly in sight. As Joseph Coveney suggested,
you also should tap into -egen- for handy functions.
Again, there is propaganda in an overview
On getting functions to do the work.
Stata Journal 2(4): 411--427 (2002).
egen max1 = max(var1), by(id visitno)
egen mean1 = mean(var1), by(id visitno)
bysort id visitno: egen max1 = max(var1)
by id visitno: egen mean1 = mean(var1)
> Thanks Nick for your reply
> Im obviously finding it difficult to develop in this area
> I cant find a useful guide,any pointers?
> My problem now is that having identified the visitno within
> id I wish to
> perform manipulations on a variable. For example
> using the illustrated structure.
> To obtain the maximum value of var1 within id at each level
> of visitno.
> To obtain the mean value of var1 within id at each level of visitno
> id date visitno var1
> > 1 16267 1 53
> > 1 16267 1 106
> > 1 16267 1 84
> > 1 16267 1 90
> > 1 16267 1 76
> > 1 16267 1 65
> > 1 16298 2 87
> > 1 16298 2 76
> > 2 15678 1 98
> > 2 15678 1 98
> > 2 16541 2 150
* For searches and help try: