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]

st: Cut function


From   albert Lee <ajlee20005@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Cut function
Date   Fri, 10 Dec 2010 13:26:32 -0500

Hi, just want to see if this has happened to anyone else, and if stata has
an explanation.  I was trying to bin a continuous variable into fixed
intervals.  According to stata documentation, this function

egen price_incrB=cut(price), at(`min'(`step')`max') icodes
(1 missing value generated)

For some reasons, one missing value is created.  It turns out that the max
is not covered by any increment from the egen cut function.  Is this due to
rounding?  Is this a bug?

I would appreciate anyone's insight.

Code fragments are included below.

Thanks, Albert Lee.

. sysuse auto, clear
(1978 Automobile Data)

.
. sum price, d

                        Price
-------------------------------------------------------------
  Percentiles      Smallest
1%         3291           3291
5%         3748           3299
10%         3895           3667       Obs                  74
25%         4195           3748       Sum of Wgt.          74

50%       5006.5                      Mean           6165.257
                    Largest       Std. Dev.      2949.496
75%         6342          13466
90%        11385          13594       Variance        8699526
95%        13466          14500       Skewness       1.653434
99%        15906          15906       Kurtosis       4.819188

.
. local max=r(max)

.
. local min=r(min)

.
. local step=(`max'-`min')/9

.
. disp `step'
1401.6667

.
. egen price_incrB=cut(price), at(`min'(`step')`max') icodes
(1 missing value generated)

.
. tab price_incrB, mi

price_incrB |      Freq.     Percent        Cum.
------------+-----------------------------------
      0 |         30       40.54       40.54
      1 |         21       28.38       68.92
      2 |          8       10.81       79.73
      3 |          3        4.05       83.78
      4 |          2        2.70       86.49
      5 |          4        5.41       91.89
      6 |          2        2.70       94.59
      7 |          3        4.05       98.65
      . |          1        1.35      100.00
------------+-----------------------------------
  Total |         74      100.00

.
. list price if price_incrB==.

 +--------+
 |  price |
 |--------|
13. | 15,906 |
 +--------+

--
Albert J. Lee, Ph.D.,
Economist

Summit Consulting LLC*
626 E Street NW, Suite 200
Washington DC 20004

Main (202) 407 8300
Direct (202) 407 8302
Fax (509) 984 8943

www.summitllc.us

*Summit Consulting is a SBA certified 8(a) company with GSA FABS and
MOBIS schedules

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