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: RE: RE: Cut function


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: Cut function
Date   Wed, 28 Jul 2010 19:58:00 +0100

The reference here to -ceiling()- was a typo. The ceiling function is implemented as -ceil()-, as another reference indicates. Sorry if that floored you. 

Nick 
[email protected] 

Nick Cox

You can have anything you like with zero observations: it just won't be visible in your dataset. 

More seriously: 

I don't understand your precise problem but I've never wanted to use -egen, cut()- (as compared with -egen, group()- which I use very frequently). 

If I want to coarsen, I always want to use constant intervals and to be totally clear which way things were rounded. I thus turn to -floor()- or -ceiling()-. Of course, other people often want otherwise. 

To give a non-time series example: 

. sysuse auto
(1978 Automobile Data)

. clonevar mpg2 = mpg

. replace mpg2 = 5 * floor(mpg/5)
(60 real changes made)

. tab mpg2

    Mileage |
      (mpg) |      Freq.     Percent        Cum.
------------+-----------------------------------
         10 |          8       10.81       10.81
         15 |         27       36.49       47.30
         20 |         20       27.03       74.32
         25 |         12       16.22       90.54
         30 |          4        5.41       95.95
         35 |          2        2.70       98.65
         40 |          1        1.35      100.00
------------+-----------------------------------
      Total |         74      100.00

Thus with -floor()- you can round down; your definition will be transparent once you know what -floor()- does; and the resulting values will be automatically self-explanatory. Rounding up just requires -ceil()- instead. 

There is more at 

SJ-3-4  dm0002  . . . . . . . . Stata tip 2: Building with floors and ceilings
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q4/03   SJ 3(4):446--447                                 (no commands)
        tips for using floor() and ceil()

Some years ago I suggested to StataCorp that -floor()- and -ceil()- be extended to allow two arguments so that -floor(mpg, 5)- would have the effect above, but while I am still waiting it's easy enough to apply rounding to any interval. 

Nick 
[email protected] 

Katia Bobulova

I used the command egen cut to divide the time in 5-min intervals.

My 5-min intervals start from 9:30, however, for some days the time
starts for example at 9:40 and so on.

Is there a way to have the time interval with zero observations?


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