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]

st: Selecting maximum values and generating sum variable


From   Catherine Tisch <[email protected]>
To   [email protected]
Subject   st: Selecting maximum values and generating sum variable
Date   Tue, 24 May 2011 14:33:26 +1200

Hello

We have two issues that hopefully you can help us with:

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.  An example of our dataset looks like:

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

We would like to create a new variable called 'UVPeak', from the example
above, the output would look like:

ID    Day    Hour         UVI      UVIPeak
1     1      11           5        9
1     1      12           9        9
1     1      13           7        9
1     1      14           3        9
1     1      15           4        9
1     2      11           7        8
1     2      12           8        8
1     2      13           2        8
1     2      14           1        8
1     2      15           .        8
1     3      11           1        2
1     3      12           2        2
1     3      13           1        2
1     3      14           1        2
1     3      15           0        2
2     1      11           .        .
2     1      12           .        .
2     1      13           .        .
2     1      14           .        .
2     1      15           .        .
2     2      11           9        10
2     2      12           10       10
2     2      13           10       10
2     2      14           8        10
2     2      15           6        10


2.	We want to know the sum of count of days per ID if UVIPeak is
not missing.  We will call this new variable 'SumDays'.  From the
example above, the output would look like:

ID    Day    Hour         UVI      UVIPeak     SumDays
1     1      11           5        9           3
1     1      12           9        9           3
1     1      13           7        9           3
1     1      14           3        9           3
1     1      15           4        9           3
1     2      11           7        8           3
1     2      12           8        8           3
1     2      13           2        8           3
1     2      14           1        8           3
1     2      15           .        8           3
1     3      11           1        2           3
1     3      12           2        2           3
1     3      13           1        2           3
1     3      14           1        2           3
1     3      15           0        2           3
2     1      11           .        .           1
2     1      12           .        .           1
2     1      13           .        .           1
2     1      14           .        .           1
2     1      15           .        .           1
2     2      11           9        10          1
2     2      12           10       10          1
2     2      13           10       10          1
2     2      14           8        10          1
2     2      15           6        10          1

Can anyone help us create these new variables?

Thanks in advance
Catherine

This email may be confidential and subject to legal privilege, it may
not reflect the views of the University of Canterbury, and it is not
guaranteed to be virus free. If you are not an intended recipient,
please notify the sender immediately and erase all copies of the message
and any attachments.

Please refer to http://www.canterbury.ac.nz/emaildisclaimer for more
information.

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