Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Selecting maximum values and generating sum variable


From   Maarten Buis <[email protected]>
To   [email protected]
Subject   Re: st: Selecting maximum values and generating sum variable
Date   Tue, 24 May 2011 09:12:21 +0200

On Tue, May 24, 2011 at 4:33 AM, Catherine Tisch wrote:
> 1.      We want to select the highest UVI value per ID per day from five
> hourly measurements.  It is possible for measurements to be zero and in
> some instances data is missing. <snip>
> 2.      We want to know the sum of count of days per ID if UVIPeak is
> not missing.

*------------------ begin example ---------------
clear
input ///
ID    Day    Hour         UVI
1     1      11           5
1     1      12           9
1     1      13           7
1     1      14           3
1     1      15           4
1     2      11           7
1     2      12           8
1     2      13           2
1     2      14           1
1     2      15           .
1     3      11           1
1     3      12           2
1     3      13           1
1     3      14           1
1     3      15           0
2     1      11           .
2     1      12           .
2     1      13           .
2     1      14           .
2     1      15           .
2     2      11           9
2     2      12           10
2     2      13           10
2     2      14           8
2     2      15           6
end

bys ID Day : egen UVIpeak = max(UVI)
list
bys ID Day : gen byte notmiss = !missing(UVIpeak) if _n == 1
bys ID : egen SumDays = total(notmis)
list
drop notmiss
list
*----------------------- end example -----------------------
(For more on examples I sent to the Statalist see:
http://www.maartenbuis.nl/example_faq )

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany


http://www.maartenbuis.nl
--------------------------

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index