Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: data manipulation prob.


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
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 <ltashi32@hotmail.com> 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index