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: data manipulation prob.


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: data manipulation prob.
Date   Thu, 7 Jun 2012 00:40:16 +0100

On the last question first: the usual Stata way is to add observations
at the end and then -sort-, although you could also -append- to a
one-observation dataset.

If -hits- is always 1, then

sort date
gen obs = _n
su obs, meanonly
di date[ceil(r(mean))] - date[1]

I guess you will now tell us that the real data are more complicated.

Nick

On Wed, Jun 6, 2012 at 10:24 PM, tashi lama <[email protected]> wrote:

>              date           hits |
>     |---------------------------|
>  1. | 10mar2011 01:07:18      1 |
>  2. | 10mar2011 01:09:48      1 |
>  3. | 10mar2011 01:54:00      1 |
>  4. | 10mar2011 02:03:37      1 |
>  5. | 10mar2011 02:11:00      1 |
>     |---------------------------|
>  6. | 10mar2011 02:26:00      1 |
>  7. | 10mar2011 02:46:00      1 |
>  8. | 10mar2011 02:47:00      1 |
>  9. | 10mar2011 02:51:09      1 |
>  10. | 10mar2011 02:51:24      1 |
>
> I need to find the time taken to get half of the total hits
>
> summ hits
>
> gen runsum=sum(hits)
>
>           date              hits     x |
>     |---------------------------------|
>  1. | 10mar2011 01:07:18      1     1 |
>  2. | 10mar2011 01:09:48      1     2 |
>  3. | 10mar2011 01:54:00      1     3 |
>  4. | 10mar2011 02:03:37      1     4 |
>  5. | 10mar2011 02:11:00      1     5 |
>     |---------------------------------|
>  6. | 10mar2011 02:26:00      1     6 |
>  7. | 10mar2011 02:46:00      1     7 |
>  8. | 10mar2011 02:47:00      1     8 |
>  9. | 10mar2011 02:51:09      1     9 |
>  10. | 10mar2011 02:51:24      1    10 |
>
> Now, the prob I am having is I will be comparing r(sum) in var "x" but I need to compute in var "date". So, if r(sum)/2 is 5 then i know to subtract date[5]-date[1]. Any idea?
>
> Also, is it possible to add one date observation on top in date column programmatically. So, I need to add 07mar2011 03:00:00 in date column and because this date comes first than other obs  in the dataset, I need to make this as my first obs.
>

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